Teams can generate structured data using Pydantic models, just like individual agents. This feature is perfect for coordinated data extraction, analysis, and report generation where multiple agents work together to produce a structured result.
Let’s create a Stock Research Team that produces a structured StockReport.
stock_team.py
Copy
Ask AI
from typing import Listfrom pydantic import BaseModel, Fieldfrom agno.agent import Agentfrom agno.models.openai import OpenAIChatfrom agno.team.team import Teamfrom agno.tools.yfinance import YFinanceToolsclass StockAnalysis(BaseModel): symbol: str company_name: str analysis: strclass CompanyAnalysis(BaseModel): company_name: str analysis: strclass StockReport(BaseModel): symbol: str = Field(..., description="Stock ticker symbol") company_name: str = Field(..., description="Full company name") current_price: str = Field(..., description="Current stock price") analysis: str = Field(..., description="Comprehensive analysis combining multiple perspectives") recommendation: str = Field(..., description="Investment recommendation: Buy, Hold, or Sell")# Create specialized agentsstock_searcher = Agent( name="Stock Searcher", model=OpenAIChat("gpt-4o"), response_model=StockAnalysis, role="Searches for current stock information and price data.", tools=[ YFinanceTools( stock_price=True, analyst_recommendations=True, ) ],)company_info_agent = Agent( name="Company Info Searcher", model=OpenAIChat("gpt-4o"), role="Researches company fundamentals and recent news.", response_model=CompanyAnalysis, tools=[ YFinanceTools( stock_price=False, company_info=True, company_news=True, ) ],)# Create team with structured outputstock_research_team = Team( name="Stock Research Team", mode="coordinate", model=OpenAIChat("gpt-4o"), members=[stock_searcher, company_info_agent], response_model=StockReport, markdown=True, show_members_responses=True,)stock_research_team.print_response("Give me a comprehensive stock report for NVDA")
The team will coordinate between its members and produce a structured StockReport object:
Copy
Ask AI
StockReport(│ symbol='NVDA',│ company_name='NVIDIA Corporation',│ current_price='$875.42',│ analysis='NVIDIA continues to dominate the AI chip market with strong demand for its H100 and upcoming H200 GPUs. The company has shown exceptional growth in data center revenue, driven by enterprise AI adoption and cloud provider expansion. Recent partnerships with major tech companies strengthen its market position, though competition from AMD and Intel is intensifying.',│ recommendation='Buy')
You can use an additional model to parse and structure the output from your primary model. This approach is particularly effective when the primary model is optimized for reasoning tasks, as such models may not consistently produce detailed structured responses.
Copy
Ask AI
team = Team( name="Stock Research Team", mode="coordinate", model=Claude(id="claude-sonnet-4-20250514"), members=[stock_searcher, company_info_agent], response_model=StockReport, parser_model=OpenAIChat(id="gpt-4o"),)
You can also provide a custom parser_model_prompt to your Parser Model.
Teams support streaming with structured output, where the content event contains the complete structured result as a single event.
streaming_team.py
Copy
Ask AI
from typing import Listfrom pydantic import BaseModel, Fieldfrom agno.agent import Agentfrom agno.models.openai import OpenAIChatfrom agno.team.team import Teamfrom agno.tools.yfinance import YFinanceToolsclass MarketAnalysis(BaseModel): sector: str = Field(..., description="Market sector being analyzed") key_trends: List[str] = Field(..., description="Major trends affecting the sector") top_performers: List[str] = Field(..., description="Best performing stocks in the sector") market_outlook: str = Field(..., description="Overall market outlook and predictions") risk_factors: List[str] = Field(..., description="Key risks to consider")# Create research agentstrend_analyst = Agent( name="Trend Analyst", model=OpenAIChat("gpt-4o"), role="Analyzes market trends and sector performance.", tools=[YFinanceTools(stock_price=True, analyst_recommendations=True)])risk_assessor = Agent( name="Risk Assessor", model=OpenAIChat("gpt-4o"), role="Identifies and evaluates market risks and opportunities.", tools=[YFinanceTools(company_news=True, company_info=True)])# Create streaming teammarket_research_team = Team( name="Market Research Team", mode="coordinate", model=OpenAIChat("gpt-4o"), members=[trend_analyst, risk_assessor], response_model=MarketAnalysis, markdown=True, show_members_responses=True,)# Stream the team responsemarket_research_team.print_response( "Analyze the technology sector for Q1 2024", stream=True, stream_intermediate_steps=True)
When streaming with teams and structured output, you’ll see intermediate steps from individual team members, but the final structured result is delivered as a single complete chunk rather than being streamed progressively.