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.
research_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.duckduckgo import DuckDuckGoToolsclass NewsAnalysis(BaseModel): topic: str headline: str analysis: strclass TopicAnalysis(BaseModel): topic_name: str analysis: strclass ResearchReport(BaseModel): topic: str = Field(..., description="Research topic") summary: str = Field(..., description="Brief summary of the topic") latest_news: str = Field(..., description="Latest news about the topic") analysis: str = Field(..., description="Comprehensive analysis combining multiple perspectives") recommendation: str = Field(..., description="Key insights and recommendations")# Create specialized agentsnews_searcher = Agent( name="News Searcher", model=OpenAIChat("gpt-4o"), response_model=NewsAnalysis, role="Searches for current news and trending information.", tools=[ DuckDuckGoTools( search=True, news=True, ) ],)topic_info_agent = Agent( name="Topic Info Searcher", model=OpenAIChat("gpt-4o"), role="Researches topic background and provides detailed information.", response_model=TopicAnalysis, tools=[ DuckDuckGoTools( search=True, news=False, ) ],)# Create team with structured outputresearch_team = Team( name="Research Team", mode="coordinate", model=OpenAIChat("gpt-4o"), members=[news_searcher, topic_info_agent], response_model=ResearchReport, markdown=True, show_members_responses=True,)research_team.print_response("Give me a comprehensive research report on artificial intelligence developments")
The team will coordinate between its members and produce a structured ResearchReport object:
Copy
Ask AI
ResearchReport(│ topic='artificial intelligence developments',│ summary='AI technology advances across multiple domains',│ latest_news='Major breakthroughs in large language models, computer vision, and robotics',│ analysis='Artificial intelligence continues to evolve rapidly with significant advances in transformer architectures, multimodal models, and practical applications. Recent developments show increased focus on efficiency, safety, and real-world deployment. Major companies are investing heavily in AI infrastructure while addressing concerns about responsible development.',│ recommendation='Key areas to watch: multimodal AI, AI safety research, and practical enterprise applications')
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.
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.duckduckgo import DuckDuckGoToolsclass TechnologyAnalysis(BaseModel): sector: str = Field(..., description="Technology sector being analyzed") key_trends: List[str] = Field(..., description="Major trends affecting the sector") top_developments: List[str] = Field(..., description="Most significant developments in the sector") market_outlook: str = Field(..., description="Overall sector 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 technology trends and sector developments.", tools=[DuckDuckGoTools(search=True, news=True)])risk_assessor = Agent( name="Risk Assessor", model=OpenAIChat("gpt-4o"), role="Identifies and evaluates technology risks and opportunities.", tools=[DuckDuckGoTools(search=True, news=True)])# Create streaming teamtechnology_research_team = Team( name="Technology Research Team", mode="coordinate", model=OpenAIChat("gpt-4o"), members=[trend_analyst, risk_assessor], response_model=TechnologyAnalysis, markdown=True, show_members_responses=True,)# Stream the team responsetechnology_research_team.print_response( "Analyze the artificial intelligence sector developments for 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.