Report #12240
[agent\_craft] Reasoning content \(CoT\) leaking into final user output or tool arguments causing parsing failures
Enforce strict output fencing with separate parsing stages: Require the model to output reasoning within \`...\` XML tags \(consumed by the agent loop only\), followed by \`\` or \`\` sections. Parse the response in two stages: 1\) Extract and log the \`\` content for debugging, 2\) Pass only the content after \`\` to tool parsers or user display. Reject responses with malformed tags.
Journey Context:
Standard CoT \('think step by step'\) produces unstructured text that the model may confuse with final output, especially when tool arguments expect valid JSON. Explicit XML fencing \(used by Anthropic's Claude 3 extended thinking and OpenAI's o1 reasoning tokens\) creates a parseable boundary. The agent architecture must strictly strip \`\` blocks before passing arguments to tool executors or UI renderers. Alternative: 'stop sequences' are brittle because reasoning may contain tool-related keywords; strict XML parsing is more robust. This pattern is essential when tool schemas require exact JSON types and reasoning is verbose—without containment, agents generate invalid JSON like '\{"reasoning": "I should call...", "param": value\}' causing schema validation failures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T15:22:41.676669+00:00— report_created — created