[FEATURE] Capture and surface reasoning traces (reasoning_content / thinking blocks) for reasoning models (DeepSeek-R1, Claude 3.7, o-series)
Feature Area
Core functionality
Is your feature request related to a an existing bug? Please link it here.
NA
Describe the solution you'd like
With the rapid adoption of reasoning models (DeepSeek-R1, Anthropic Claude 3.7 Sonnet with extended thinking, OpenAI o1/o3, and Gemini Flash Thinking), models generate rich chains of thought before executing tools or returning a final answer.
While CrewAI's UsageMetrics correctly tracks reasoning_tokens, the actual reasoning text is silently discarded:
- In OpenAI-compatible providers (
OpenAICompletion),message.reasoning_content(used by DeepSeek-R1, vLLM, Ollama, Together, Groq) is ignored. - In Anthropic (
AnthropicCompletion),ThinkingBlocks inresponse.contentare captured only for internal continuation state, but omitted fromLLMCallCompletedEventand task results. - In
crew_agent_executor.py,thoughtdefaults to an empty string""on native tool calls because it only expected legacy ReAct regex parsing ("Thought: ... \nAction:"). TaskOutputandLiteAgentOutputcurrently have no field to access the agent's chain-of-thought.
Proposed Architecture
-
Provider-Level Reasoning Extraction:
OpenAICompletion: Extractreasoning_content = getattr(message, "reasoning_content", None) or (message.model_extra or {}).get("reasoning_content")from chat completion choices and pass it inLLMCallCompletedEvent.AnthropicCompletion: Extract text fromThinkingBlockinstances inresponse.contentand include it inLLMCallCompletedEvent.GeminiCompletion: Extract thought parts wherepart.thought is True.
-
Surface in Agent Execution & Output Classes:
- In
AgentAction&AgentFinish: Populatethoughtwith the extracted reasoning text rather than defaulting to"". - In
TaskOutput&LiteAgentOutput: Add an optional field:thought: str | None = Field( default=None, description="The reasoning trace or chain-of-thought produced by reasoning models.", )
- In
-
Console UX (
verbose=True): Render the agent's reasoning inside a distinct[Thinking Process]block before tool execution or the final answer so developers can inspect the agent's chain of thought live.
Describe alternatives you've considered
- Relying solely on ReAct regex parsing (
"Thought: ..."in prompt): Fails completely on modern reasoning models using native function/tool calling, where reasoning is emitted via dedicated API fields (reasoning_contentorThinkingBlock) outside of the text body. - Third-party external tracing (Langfuse/OpenTelemetry only): Leaving reasoning inspection to external APM dashboards leaves local developers and terminal users in the dark when running crews with
verbose=True, and prevents downstream tasks or guardrails from validating the agent's reasoning.
Additional context
- Backward Compatibility: Fully backward compatible. For standard non-reasoning models (GPT-4o, Claude 3.5 without thinking, etc.),
thoughtremains empty/None as it is today. - Enterprise Safety: Allows enterprises to audit the agent's internal rationale prior to high-stakes tool execution (e.g. database mutations, financial operations, code edits).
Willingness to Contribute
Yes, I'd be happy to submit a pull request
Hi Maintainers,
I'd love to work on this feature
I have already mapped out the implementation across the native providers (OpenAICompletion for reasoning_content, AnthropicCompletion for ThinkingBlock), event bus propagation, and surfacing it cleanly in TaskOutput/LiteAgentOutput with comprehensive unit tests.
Could you please assign this issue to me, I'll submit a PR for this.
Thanks
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.