Overview
TheChainOfThoughtEngine forces the model to reason through problems explicitly before answering. It uses XML-style <thinking> tags to separate the model’s internal reasoning from its final response.
This engine is ideal for tasks requiring careful, methodical analysis.
When to Use
UseChainOfThoughtEngine when:
- Tasks require explicit step-by-step reasoning
- You want to observe the model’s thought process
- Accuracy is more important than speed
- You need transparent decision-making for debugging or auditing
Constructor
Configuration
Whether to use XML-style
<thinking> tags to separate reasoning from response. When true, the engine strips the thinking block before returning the final answer.Maximum tool-using steps after the initial chain-of-thought reasoning pass.
Custom instruction appended to the system prompt to elicit step-by-step reasoning. If not provided, uses a default prompt that requests thinking inside
<thinking> tags.Usage Example
How It Works
- Inject Instruction: Adds chain-of-thought prompt to system message
- Initial Reasoning: Model produces
<thinking>...</thinking>+ answer (or tool calls) - Extract Thinking: Thinking content is extracted and emitted as a
ThoughtStep - Tool Loop: If tools were called, execute them and continue (up to
maxToolSteps) - Return Clean Answer: Final response excludes thinking tags
Default Thinking Instruction
Step Emissions
- ThoughtStep: Contains the extracted
<thinking>content - ResponseStep: Contains the final answer (thinking tags removed)
Example Output Flow
Model generates:Error Handling
Throws if maximum tool steps are exceeded:String Alias
Implementation Reference
Source:packages/reasoning/src/engines/cot.ts:53