Enabling the reasoning option on the team leader helps optimize delegation and enhances multi-agent collaboration by selectively invoking deeper reasoning when required.
Code
cookbook/reasoning/teams/reasoning_finance_team.py
Copy
Ask AI
from textwrap import dedent
from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.models.openai import OpenAIChat
from agno.team.team import Team
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.reasoning import ReasoningTools
web_agent = Agent(
name="Web Search Agent",
role="Handle web search requests",
model=OpenAIChat(id="gpt-4o-mini"),
tools=[DuckDuckGoTools()],
instructions="Always include sources",
add_datetime_to_instructions=True,
)
research_agent = Agent(
name="Research Agent",
role="Handle research and news requests",
model=OpenAIChat(id="gpt-4o-mini"),
tools=[
DuckDuckGoTools(search=True, news=True)
],
instructions=[
"You are a research specialist. Provide comprehensive and accurate information.",
"Use tables to display research findings and data comparisons.",
"Clearly state sources and provide relevant context.",
"Summarize recent news and developments if available.",
"Focus on delivering the requested research data points clearly.",
],
add_datetime_to_instructions=True,
)
team_leader = Team(
name="Reasoning Research Team Leader",
mode="coordinate",
model=Claude(id="claude-3-7-sonnet-latest"),
members=[
web_agent,
research_agent,
],
tools=[ReasoningTools(add_instructions=True)],
instructions=[
"Only output the final answer, no other text.",
"Use tables to display data",
],
markdown=True,
show_members_responses=True,
enable_agentic_context=True,
add_datetime_to_instructions=True,
success_criteria="The team has successfully completed the task.",
)
def run_team(task: str):
team_leader.print_response(
task,
stream=True,
stream_intermediate_steps=True,
show_full_reasoning=True,
)
if __name__ == "__main__":
run_team(
dedent("""\
Analyze the impact of recent global technology policy changes on development across these key sectors:
- Artificial Intelligence & Machine Learning
- Semiconductor Industry
- Renewable Energy Technology
- Electric Vehicle Technology
- Telecommunications Infrastructure
For each sector:
1. Compare development trends before and after policy changes
2. Identify innovation disruptions and investment impact
3. Analyze companies' strategic responses (R&D investments, partnerships, market positioning)
4. Assess expert outlook changes directly attributed to policy shifts
""")
)
Usage
1
Create a virtual environment
Open the
Terminal
and create a python virtual environment.Copy
Ask AI
python3 -m venv .venv
source .venv/bin/activate
2
Set your API key
Copy
Ask AI
export OPENAI_API_KEY=xxx
export ANTHROPIC_API_KEY=xxx
3
Install libraries
Copy
Ask AI
pip install -U openai anthropic agno
4
Run Example
Copy
Ask AI
python cookbook/reasoning/teams/reasoning_research_team.py