Reasoning is an experimental feature that enables an Agent to think through a problem step-by-step before jumping into a response. The Agent works through different ideas, validating and correcting as needed. Once it reaches a final answer, it will validate and provide a response. Let’s give it a try. Create a file reasoning_agent.py

reasoning_agent.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat

task = (
    "Three missionaries and three cannibals need to cross a river. "
    "They have a boat that can carry up to two people at a time. "
    "If, at any time, the cannibals outnumber the missionaries on either side of the river, the cannibals will eat the missionaries. "
    "How can all six people get across the river safely? Provide a step-by-step solution and show the solutions as an ascii diagram"
)

reasoning_agent = Agent(model=OpenAIChat(id="gpt-4o"), reasoning=True, markdown=True, structured_outputs=True)
reasoning_agent.print_response(task, stream=True, show_full_reasoning=True)

Run the Reasoning Agent:

pip install -U agno openai

export OPENAI_API_KEY=***

python reasoning_agent.py

Agno Agents can leverage specialized reasoning models alongside the primary Agent model. These models are dedicated to reasoning rather than handling the main Agent tasks. Their responses are appended as messages to the Agent, integrating into the message history sent to the primary Agent model.

Currently, Groq and DeepSeek models are supported for external reasoning. Below is an example Agent that uses a Groq model for reasoning but uses the OpenAI model for the main Agent.

groq_reasoning.py
from agno.agent import Agent
from agno.models.groq import Groq
from agno.models.openai import OpenAIChat

reasoning_agent = Agent(model=OpenAIChat(id="gpt-4o"), reasoning_model=Groq(id="deepseek-r1-distill-llama-70b"))
reasoning_agent.print_response(task, stream=True)

Run the Reasoning Agent:

pip install -U agno openai groq

export OPENAI_API_KEY=***
export GROQ_API_KEY=***

python groq_reasoning.py

How to use reasoning

To add reasoning, set reasoning=True or set reasoning_model to a supported reasoning model. If you do not set reasoning_model, the primary Agent model will be used for reasoning.

deepseek_reasoning.py
from agno.models.openai import OpenAIChat
from agno.models.deepseek import DeepSeek

reasoning_agent = Agent(
    model=OpenAIChat(id="gpt-4o-2024-08-06"),
    reasoning_model=DeepSeek(id="deepseek-reasoner"),
)
reasoning_agent.print_response("How many 'r' are in the word 'supercalifragilisticexpialidocious'?", stream=True)
pip install -U agno openai deepseek

export OPENAI_API_KEY=***
export DEEPSEEK_API_KEY=***

python deepseek_reasoning.py

Reasoning with tools

You can also use tools with a reasoning agent. Lets create a finance agent that can reason.

finance_reasoning.py
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)

Run the script to see the output.

pip install -U agno openai yfinance

export OPENAI_API_KEY=***

python finance_reasoning.py

More reasoning examples

Logical puzzles

logical_puzzle.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat

task = (
    "Three missionaries and three cannibals need to cross a river. "
    "They have a boat that can carry up to two people at a time. "
    "If, at any time, the cannibals outnumber the missionaries on either side of the river, the cannibals will eat the missionaries. "
    "How can all six people get across the river safely? Provide a step-by-step solution and show the solutions as an ascii diagram"
)
reasoning_agent = Agent(
    model=OpenAIChat(id="gpt-4o-2024-08-06"), reasoning=True, markdown=True, structured_outputs=True
)
reasoning_agent.print_response(task, stream=True, show_full_reasoning=True)

Run the script to see the output.

pip install -U agno openai

export OPENAI_API_KEY=***

python logical_puzzle.py

Mathematical proofs

mathematical_proof.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat

task = "Prove that for any positive integer n, the sum of the first n odd numbers is equal to n squared. Provide a detailed proof."
reasoning_agent = Agent(
    model=OpenAIChat(id="gpt-4o-2024-08-06"), reasoning=True, markdown=True, structured_outputs=True
)
reasoning_agent.print_response(task, stream=True, show_full_reasoning=True)

Run the script to see the output.

pip install -U agno openai

export OPENAI_API_KEY=***

python mathematical_proof.py

Scientific research

scientific_research.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat

task = (
    "Read the following abstract of a scientific paper and provide a critical evaluation of its methodology,"
    "results, conclusions, and any potential biases or flaws:\n\n"
    "Abstract: This study examines the effect of a new teaching method on student performance in mathematics. "
    "A sample of 30 students was selected from a single school and taught using the new method over one semester. "
    "The results showed a 15% increase in test scores compared to the previous semester. "
    "The study concludes that the new teaching method is effective in improving mathematical performance among high school students."
)
reasoning_agent = Agent(
    model=OpenAIChat(id="gpt-4o-2024-08-06"), reasoning=True, markdown=True, structured_outputs=True
)
reasoning_agent.print_response(task, stream=True, show_full_reasoning=True)

Run the script to see the output.

pip install -U agno openai

export OPENAI_API_KEY=***

python scientific_research.py

Ethical dilemma

ethical_dilemma.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat

task = (
    "You are a train conductor faced with an emergency: the brakes have failed, and the train is heading towards "
    "five people tied on the track. You can divert the train onto another track, but there is one person tied there. "
    "Do you divert the train, sacrificing one to save five? Provide a well-reasoned answer considering utilitarian "
    "and deontological ethical frameworks. "
    "Provide your answer also as an ascii art diagram."
)
reasoning_agent = Agent(
    model=OpenAIChat(id="gpt-4o-2024-08-06"), reasoning=True, markdown=True, structured_outputs=True
)
reasoning_agent.print_response(task, stream=True, show_full_reasoning=True)

Run the script to see the output.

pip install -U agno openai

export OPENAI_API_KEY=***

python ethical_dilemma.py

Planning an itinerary

planning_itinerary.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat

task = "Plan an itinerary from Los Angeles to Las Vegas"
reasoning_agent = Agent(
    model=OpenAIChat(id="gpt-4o-2024-08-06"), reasoning=True, markdown=True, structured_outputs=True
)
reasoning_agent.print_response(task, stream=True, show_full_reasoning=True)

Run the script to see the output.

pip install -U agno openai

export OPENAI_API_KEY=***

python planning_itinerary.py

Creative writing

creative_writing.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat

task = "Write a short story about life in 5000000 years"
reasoning_agent = Agent(
    model=OpenAIChat(id="gpt-4o-2024-08-06"), reasoning=True, markdown=True, structured_outputs=True
)
reasoning_agent.print_response(task, stream=True, show_full_reasoning=True)

Run the script to see the output.

pip install -U agno openai

export OPENAI_API_KEY=***

python creative_writing.py

Developer Resources