docs/user_guide/en/modules/thinking.md
The Thinking module provides reasoning enhancement capabilities for Agent nodes, enabling the model to perform additional inference before or after generating results. This document covers the Thinking module architecture, built-in modes, and configuration methods.
nodes[].config.thinking, containing type and config fields._before_gen_think and _after_gen_think.register_thinking_mode(), and Schema API automatically displays available options.nodes:
- id: Thoughtful Agent
type: agent
config:
provider: openai
name: gpt-4o
api_key: ${API_KEY}
thinking:
type: reflection
config:
reflection_prompt: |
Please carefully review your response, considering:
1. Is the logic sound?
2. Are there any factual errors?
3. Is the expression clear?
Then provide an improved response.
| Type | Description | Trigger Timing | Config Fields |
|---|---|---|---|
reflection | Model reflects on and refines its output after generation | After generation (after_gen) | reflection_prompt |
Self-Reflection mode allows the model to reflect on and improve its initial output. The execution flow:
reflection_prompt to generate reflection result| Field | Type | Required | Description |
|---|---|---|---|
reflection_prompt | string | Yes | Prompt guiding model reflection, specifying reflection dimensions and expected improvements |
ThinkingManager supports two execution timings:
| Timing | Property | Description |
|---|---|---|
Before generation (before_gen) | before_gen_think_enabled | Execute thinking before model call for input preprocessing |
After generation (after_gen) | after_gen_think_enabled | Execute thinking after model output for post-processing or refinement |
The built-in reflection mode only enables after-generation thinking. Extension developers can implement before-generation thinking as needed.
The Thinking module can access Memory context:
ThinkingPayload.text: Text content at current stageThinkingPayload.blocks: Multimodal content blocks (images, attachments, etc.)ThinkingPayload.metadata: Additional metadataMemory retrieval results are passed to thinking functions via the memory parameter, allowing reflection to reference historical memories.
BaseConfig, define required configuration fieldsThinkingManagerBase, implement _before_gen_think or _after_gen_thinkfrom runtime.node.agent.thinking.registry import register_thinking_mode
register_thinking_mode(
"my_thinking",
config_cls=MyThinkingConfig,
manager_cls=MyThinkingManager,
summary="Custom thinking mode description",
)
python -m tools.export_design_template to update frontend optionsreflection_prompt for multi-roundreflection_prompt increases token consumption; focus on key improvement points