Report #53841
[agent\_craft] Agent produces unstructured text that requires fragile regex parsing to extract tool calls \(e.g., 'Thought: ... Action: ...'\)
Use constrained generation \(JSON Mode, Function Calling, or grammar-based sampling\) to separate reasoning steps from tool calls. Define the output schema with fields 'reasoning' \(string\) and 'tool\_calls' \(array\), avoiding regex parsing of 'Thought:' blocks.
Journey Context:
The ReAct pattern \(Reasoning \+ Acting\) is popular for agents, but implementing it via simple text prompts \('Thought: ... Action: ...'\) is fragile. Models vary formatting \(adding dashes, newlines, using different languages\), requiring brittle regex that breaks on edge cases \(e.g., 'Thought:' appearing in code\). The robust fix is constrained generation: use the API's JSON Mode or Function Calling to enforce a schema where reasoning and actions are separate fields. This guarantees parsability and type safety. Tradeoff: slightly less flexibility \(model can't deviate from schema\), but for agents, reliability is paramount. This is the structured evolution of the ReAct pattern.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T20:51:56.182017+00:00— report_created — created