Skip to content
Back to skills

Model Reasoning Handling

ASecurity

How Nyxs separates a model's chain-of-thought (<think>…</think>) from its final answer across MANY different model families, using a defensive stream parser plus model-agnostic system-prompt reinforcement. Covers why both layers are needed and how to tune them.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 6, 2026
ai-agentsdebugging

Security analysis

A100/100

Scanned December 6, 2026

npx -y skills add nyxs-code/nyxs-code --skill model-reasoning-handling --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Model Reasoning Handling?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Model Reasoning Handling
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nyxs-code-model-reasoning-handling/badge)](https://www.skillsdirectory.com/skills/nyxs-code-model-reasoning-handling)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: model-reasoning-handling
description: How Nyxs separates a model's chain-of-thought (<think>…</think>) from its final answer across MANY different model families, using a defensive stream parser plus model-agnostic system-prompt reinforcement. Covers why both layers are needed and how to tune them.
when_to_use: Use when changing how Nyxs streams responses or separates reasoning/thinking from the answer, when handling <think> / </think> tags, when reasoning leaks into the visible chat, or when adding/debugging support for a new model family's reasoning behavior.
---

# Model reasoning handling (cross-model)

Nyxs serves **thousands of models** with different reasoning behaviors. NEVER over-fit the logic to one model — what works for kimi/DeepSeek-R1/QwQ must not break Anthropic, OpenAI, or non-reasoning models. Reasoning handling has **two layers, both required**.

## Layer 1 — Defensive stream parser
Location: `src/lib/ai.ts`, inside `processStream` → `routeText` / `flushPending`.

It splits inline `<think>…</think>` out of the text stream and routes that content to `onReasoning` (the collapsible reasoning block); only the real answer reaches `emit`. It MUST tolerate the dirty output weak/open models actually produce:

- **Orphan `</think>`** (a close with no matching open) → text before it is reclassified as reasoning.
- **Reasoning interleaved between tool calls**, in any language.
- **Tags split across stream deltas** (`<thi` + `nk>`).
- **Tags are never shown** to the user.
- `ANSWER_HOLD_CAP` (default 1200 chars) is the tuning dial: in "answer" mode the text is held so it can be reclassified to reasoning if a `</think>` arrives later. A reasoning block longer than the cap before its close will leak partially — an honest streaming limit (you cannot un-emit painted text). Reasoning streams live; only answer text is held. Raise the cap if long reasoning leaks; lower it if long answers feel laggy.

## Layer 2 — System-prompt reinforcement
Location: `src/lib/systemPrompt.ts`, `COMMUNICATING` section.

A model-agnostic instruction telling models: always close every `<think>`, never emit a bare `</think>`, and — crucially — if the model already streams reasoning through a native channel, do NOT also wrap text in these tags. This fixes the *cause* (inconsistent tagging) without harming native-reasoning models or non-reasoning ones.

## Why both
The prompt nudges well-behaved models to tag consistently; the parser is the safety net for the ones that ignore the prompt. Either layer alone is insufficient.

## When adding a new model family
1. Check whether it emits reasoning inline (in text) or via a separate reasoning channel (`reasoning-delta`).
2. If inline with non-standard delimiters (not `<think>`/`</think>`), extend the parser's tag set rather than hard-coding model names.
3. Verify the parser with: orphan close, interleaved reasoning, split tags, and a long untagged answer (must still stream).
4. Keep everything model-agnostic — no `if (model === "x")` branches in the reasoning path.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.