"""� Finance Agent - Your Personal Market Analyst!
This example shows how to create a sophisticated financial analyst that provides
comprehensive market insights using real-time news and research data. The agent combines financial news,
market analysis, company information, and expert insights to deliver professional-grade
financial research and market commentary.
Example prompts to try:
- "What's the latest news and market sentiment around Apple?"
- "Give me a detailed analysis of Tesla's recent market developments"
- "How is Microsoft performing in the current market? Include recent news"
- "Analyze NVIDIA's recent news and market position"
- "What's the latest financial news about Amazon's business performance?"
Run: `pip install openai ddgs agno` to install the dependencies
"""
from textwrap import dedent
from agno.agent import Agent
from agno.models.xai import xAI
from agno.tools.duckduckgo import DuckDuckGoTools
finance_agent = Agent(
model=xAI(id="grok-3-mini-beta"),
tools=[
DuckDuckGoTools(
search=True,
news=True,
)
],
instructions=dedent("""\
You are a seasoned financial analyst with deep expertise in market analysis and financial research! 📊
Follow these steps for comprehensive financial analysis:
1. Market Overview
- Search for latest company news and developments
- Current market sentiment and trends
2. Financial Deep Dive
- Key financial developments and announcements
- Recent earnings or business updates
3. Professional Analysis
- Expert opinions and market commentary
- Recent news impact assessment
4. Context and Impact
- Industry trends and competitive positioning
- Comparative market analysis
- Current investor sentiment and market indicators
Your reporting style:
- Begin with an executive summary
- Use tables for data presentation when available
- Include clear section headers
- Add emoji indicators for trends (📈 📉)
- Highlight key insights with bullet points
- Compare findings to industry benchmarks when possible
- Include technical term explanations
- End with a forward-looking market analysis
Financial Disclosure:
- Always highlight news sources and dates
- Note data limitations and availability
- Mention this is based on publicly available information
- This analysis is for educational purposes only
"""),
add_datetime_to_instructions=True,
markdown=True,
)
# Example usage with detailed financial analysis request
finance_agent.print_response(
"Provide a comprehensive financial analysis of Apple's recent market performance and news",
stream=True,
stream_intermediate_steps=True,
)
Create a virtual environment
Terminal
and create a python virtual environment.python3 -m venv .venv
source .venv/bin/activate
Set your API key
export XAI_API_KEY=xxx
Install libraries
pip install -U openai ddgs agno
Run Agent
python cookbook/models/xai/finance_agent.py
Was this page helpful?