How to get reasoning content

Hi, when run a reason agent, How to get the reasoning content? is there a function or method to get it? I also want to save it.

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools

reasoning_agent = Agent(
    model=OpenAIChat(id="gpt-4o"),
    tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True, company_news=True)],
    instructions=["Use tables to show data"],
    show_tool_calls=True,
    markdown=True,
    reasoning=True,
)
reasoning_agent.print_response("Write a report comparing NVDA to TSLA", stream=True, show_full_reasoning=True)

Hey @huangsh,

You can access the reasoning data in the extra_data attribute like this:

response_stream: Iterator[RunResponse] = reasoning_agent.run(task, stream=True)

for response in response_stream:
    print(response.extra_data.reasoning_steps)

You can check all the available methods here: https://docs.agno.com/agents/run

However, we missed adding extra_data. Please print it to learn more about it. From there, you can access reasoning_steps and reasoning_messages.

Thanks!, priti. But when i try to the code, I can not get reasoning data in extra_data

from agno.models.openai.like import OpenAILike

reasoning_agent = Agent( 
    model= OpenAILike(
        id="deepseek-ai/DeepSeek-R1",
        api_key=getenv("SILICONFLOW_API_KEY"),
        base_url="https://api.siliconflow.cn/v1",
    ),
  )
reasoning_agent  = reasoning_agent.run("how many 'r' in word 'Strawberry'" )

response.extra_data
# None

when I run this code:

from agno.models.openai.like import OpenAILike

reasoning_agent = Agent( 
   model= OpenAILike(
       id="deepseek-ai/DeepSeek-V3",
       api_key=getenv("SILICONFLOW_API_KEY"),
       base_url="https://api.siliconflow.cn/v1",
   ),
   reasoning_model=OpenAILike(
       id="deepseek-ai/DeepSeek-R1",
       api_key=getenv("SILICONFLOW_API_KEY"),
       base_url="https://api.siliconflow.cn/v1",
   )

)
response  = reasoning_agent.run("how many 'r' in word 'Strawberry'" )

response.extra_data

it raise the error

ERROR    Reasoning error: Error code: 400 - {'code': 20024, 'message': 'Json mode is not supported for this        
         model.', 'data': None}    

I don’t think your agent configuration is correct @huangsh

Please try this out & change it based on your requirements:

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.run.response import RunResponse

task = "Give me steps to write a python script for fibonacci series"

reasoning_agent = Agent(
    model=OpenAIChat(id="gpt-4o"),
    markdown=True,
    structured_outputs=True,
    reasoning=True
)
response_stream: RunResponse  = reasoning_agent.run(task)

print(response_stream.extra_data)

thanks for your replies.

it did work using your code…

it still doest not work in my code… I first change you OpenAIChat to OpenAILike

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.run.response import RunResponse

task = "Give me steps to write a python script for fibonacci series"

reasoning_agent = Agent(
   model=OpenAILike(
       id="deepseek-v3",
       api_key=getenv("ALIYUN_API_KEY"),
       base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
   ),
   markdown=True,
   structured_outputs=True,
   reasoning=True 
)
response_stream: RunResponse  = reasoning_agent.run(task)

print(response_stream.extra_data)

it rase the error, it seem it will use openai model for reasoning

ERROR    Error from OpenAI API: Error code: 401 - {'error': {'message': 'Incorrect API key provided: not-provided. 
         You can find your API key at https://platform.openai.com/account/api-keys.', 'type':                      
         'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}                                       
ERROR    Reasoning error: You tried to pass a `BaseModel` class to `chat.completions.create()`; You must use       
         `beta.chat.completions.parse()` instead  

So I set reasoning_model, then

task = "Give me steps to write a python script for fibonacci series"

reasoning_agent = Agent(
    model=OpenAILike(
        id="deepseek-v3",
        api_key=getenv("ALIYUN_API_KEY"),
        base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    ),
    markdown=True,
    structured_outputs=True,
    reasoning=True,    
    reasoning_model=OpenAILike(
        id="deepseek-r1",
        api_key=getenv("ALIYUN_API_KEY"),
        base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    )
 
)
response_stream: RunResponse  = reasoning_agent.run(task)

print(response_stream.extra_data)

it rase the error

ERROR    Error from OpenAI API: Error code: 400 - {'error': {'code': 'invalid_parameter_error', 'param': None,     
         'message': "<400> InternalError.Algo.InvalidParameter: 'messages' must contain the word 'json' in some    
         form, to use 'response_format' of type 'json_object'.", 'type': 'invalid_request_error'}, 'id':           
         'chatcmpl-423716b8-a92d-9054-ac3d-43712fb2e18c', 'request_id': '423716b8-a92d-9054-ac3d-43712fb2e18c'}    
ERROR    Reasoning error: You tried to pass a `BaseModel` class to `chat.completions.create()`; You must use       
         `beta.chat.completions.parse()` instead  

But if I use openai, I can geti it using following code:

import os
from openai import OpenAI

client = OpenAI(
 
    api_key=os.getenv("ALIYUN_API_KEY"),  
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
    model="deepseek-r1",   
    messages=[
        {'role': 'user', 'content': "how many 'r' in word 'Strawberry'"}
        ]
)
 
print(completion.choices[0].message.reasoning_content)
 

@priti Hey , I find the problem. Only Deepseek or Groq keep the reasoning_content
OpenAILike or OpenAIChat did not keep the reasoning_content

Also like perplexity.ai API will return a attribute citations, agno does not keep it, and openai will keep it…

ChatCompletion(id=' 4a', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='  DMEPOS billing nationwide[1].', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None), delta={'role': 'assistant', 'content': ''})], created=1739351559, model='sonar-reasoning', object='chat.completion', service_tier=None, system_fingerprint=None, usage=CompletionUsage(completion_tokens=508, prompt_tokens=2, total_tokens=510, completion_tokens_details=None, prompt_tokens_details=None), citations=['https://www.dmepdac.com'])

Do you have any advice if I want to keep them?

Thanks for pointing out this reasoning issue, @huangsh – we’re fixing it!

Reasoning issue should be fixed here: reasoning-fix-ag-2692 by ysolanky · Pull Request #2096 · agno-agi/agno · GitHub

Thanks for the citations request- we’ve noted it down. If you’ve sometime & need it urgently feel free to open an issue & contribute :slight_smile:

Thank you very much for you help! @priti

1 Like