这个示例展示了如何创建一个强大的 AI 代理团队,协同工作以提供全面的金融分析和新闻报道。该团队由以下成员组成:
尝试以下示例提示:
from textwrap import dedent
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.yfinance import YFinanceTools
web_agent = Agent(
name="Web Agent",
role="Search the web for information",
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGoTools()],
instructions=dedent("""\
You are an experienced web researcher and news analyst! 🔍
Follow these steps when searching for information:
1. Start with the most recent and relevant sources
2. Cross-reference information from multiple sources
3. Prioritize reputable news outlets and official sources
4. Always cite your sources with links
5. Focus on market-moving news and significant developments
Your style guide:
- Present information in a clear, journalistic style
- Use bullet points for key takeaways
- Include relevant quotes when available
- Specify the date and time for each piece of news
- Highlight market sentiment and industry trends
- End with a brief analysis of the overall narrative
- Pay special attention to regulatory news, earnings reports, and strategic announcements\
"""),
show_tool_calls=True,
markdown=True,
)
finance_agent = Agent(
name="Finance Agent",
role="Get financial data",
model=OpenAIChat(id="gpt-4o"),
tools=[
YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)
],
instructions=dedent("""\
You are a skilled financial analyst with expertise in market data! 📊
Follow these steps when analyzing financial data:
1. Start with the latest stock price, trading volume, and daily range
2. Present detailed analyst recommendations and consensus target prices
3. Include key metrics: P/E ratio, market cap, 52-week range
4. Analyze trading patterns and volume trends
5. Compare performance against relevant sector indices
Your style guide:
- Use tables for structured data presentation
- Include clear headers for each data section
- Add brief explanations for technical terms
- Highlight notable changes with emojis (📈 📉)
- Use bullet points for quick insights
- Compare current values with historical averages
- End with a data-driven financial outlook\
"""),
show_tool_calls=True,
markdown=True,
)
agent_team = Agent(
team=[web_agent, finance_agent],
model=OpenAIChat(id="gpt-4o"),
instructions=dedent("""\
You are the lead editor of a prestigious financial news desk! 📰
Your role:
1. Coordinate between the web researcher and financial analyst
2. Combine their findings into a compelling narrative
3. Ensure all information is properly sourced and verified
4. Present a balanced view of both news and data
5. Highlight key risks and opportunities
Your style guide:
- Start with an attention-grabbing headline
- Begin with a powerful executive summary
- Present financial data first, followed by news context
- Use clear section breaks between different types of information
- Include relevant charts or tables when available
- Add 'Market Sentiment' section with current mood
- Include a 'Key Takeaways' section at the end
- End with 'Risk Factors' when appropriate
- Sign off with 'Market Watch Team' and the current date\
"""),
add_datetime_to_instructions=True,
show_tool_calls=True,
markdown=True,
)
# Example usage with diverse queries
agent_team.print_response(
"Summarize analyst recommendations and share the latest news for NVDA", stream=True
)
agent_team.print_response(
"What's the market outlook and financial performance of AI semiconductor companies?",
stream=True,
)
agent_team.print_response(
"Analyze recent developments and financial performance of TSLA", stream=True
)
# More example prompts to try:
"""
Advanced queries to explore:
1. "Compare the financial performance and recent news of major cloud providers (AMZN, MSFT, GOOGL)"
2. "What's the impact of recent Fed decisions on banking stocks? Focus on JPM and BAC"
3. "Analyze the gaming industry outlook through ATVI, EA, and TTWO performance"
4. "How are social media companies performing? Compare META and SNAP"
5. "What's the latest on AI chip manufacturers and their market position?"
"""
创建虚拟环境
打开 Terminal
并创建一个 python 虚拟环境。
python3 -m venv .venv
source .venv/bin/activate
Install libraries
pip install openai duckduckgo-search yfinance agno
Run the agent
python agent_team.py