Skip to main content

Overview

The AI Finance Agent Team demonstrates how to build a collaborative team of AI agents that work together as financial analysts. This system combines web search capabilities with real-time financial data analysis tools to provide comprehensive financial insights in just 20 lines of Python code.

Architecture

Multi-Agent Team Structure

The Finance Agent Team uses a team coordination pattern where specialized agents collaborate under a team lead:

Agent Roles

Web Agent

Role: Search the web for informationTools:
  • DuckDuckGo search
Capabilities:
  • General internet research
  • News and articles
  • Market sentiment

Finance Agent

Role: Get financial dataTools:
  • Current stock prices
  • Analyst recommendations
  • Company information
  • Company news
Display: Always uses tables for data

Team Agent

Role: Coordinate between agentsResponsibilities:
  • Route queries to appropriate agents
  • Combine insights from both agents
  • Present unified analysis

Implementation

from agno.agent import Agent
from agno.team import Team
from agno.models.openai import OpenAIChat
from agno.db.sqlite import SqliteDb
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.yfinance import YFinanceTools
from agno.os import AgentOS

# Setup database for storage
db = SqliteDb(db_file="agents.db")

# Web Agent
web_agent = Agent(
    name="Web Agent",
    role="Search the web for information",
    model=OpenAIChat(id="gpt-4o"),
    tools=[DuckDuckGoTools()],
    db=db,
    add_history_to_context=True,
    markdown=True,
)

# Finance Agent
finance_agent = Agent(
    name="Finance Agent",
    role="Get financial data",
    model=OpenAIChat(id="gpt-4o"),
    tools=[YFinanceTools(include_tools=[
        "get_current_stock_price", 
        "get_analyst_recommendations", 
        "get_company_info", 
        "get_company_news"
    ])],
    instructions=["Always use tables to display data"],
    db=db,
    add_history_to_context=True,
    markdown=True,
)

# Team Agent
agent_team = Team(
    name="Agent Team (Web+Finance)",
    model=OpenAIChat(id="gpt-4o"),
    members=[web_agent, finance_agent],
    debug_mode=True,
    markdown=True,
)

# AgentOS
agent_os = AgentOS(teams=[agent_team])
app = agent_os.get_app()

if __name__ == "__main__":
    agent_os.serve(app="finance_agent_team:app", reload=True)

Key Features

YFinance Integration:
  • Current stock prices
  • Analyst recommendations
  • Company information and fundamentals
  • Latest company news
  • Historical data analysis
Data Presentation:
  • Always formatted in tables
  • Clear, readable format
  • Supports multiple tickers
DuckDuckGo Search:
  • General market research
  • News and sentiment analysis
  • Industry trends
  • Competitive intelligence
  • Economic indicators
Privacy-Focused:
  • No tracking
  • Anonymous searches
  • Reliable results
SQLite Database:
  • Stores agent interactions
  • Maintains conversation history
  • Context awareness across queries
  • Historical analysis
Benefits:
  • Faster follow-up queries
  • Consistent analysis
  • Learning from past interactions
Intelligent Routing:
  • Automatically selects appropriate agent
  • Combines insights from multiple agents
  • Unified response format
Collaboration:
  • Agents share context
  • Complementary analysis
  • Comprehensive insights

Agent Coordination Patterns

Query Routing

The Team Agent intelligently routes queries based on the type of information needed:
# Routed to Finance Agent
"What is the current stock price of AAPL?"
"Show me analyst recommendations for Tesla"
"Get company information for Microsoft"

Agent Handoff

# Example flow for combined query
User: "Analyze TSLA stock and recent news"

1. Team Agent receives query
2. Routes to Finance Agent first
   - Gets stock price
   - Gets analyst recommendations
   - Gets company financials
3. Routes to Web Agent
   - Searches for recent news
   - Finds market sentiment
4. Team Agent combines insights
5. Returns comprehensive analysis

YFinance Tools

Available Functions

# Get current stock price
def get_current_stock_price(ticker: str) -> dict:
    """
    Get the current stock price for a ticker symbol.
    
    Args:
        ticker: Stock ticker symbol (e.g., 'AAPL', 'TSLA')
        
    Returns:
        dict: Current price, day high/low, volume, etc.
    """
Example:
Query: "What is AAPL stock price?"
Response: 
| Metric | Value |
|--------|-------|
| Price  | $178.32 |
| High   | $179.50 |
| Low    | $177.20 |
| Volume | 45.2M |

Installation

1

Clone Repository

git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git
cd advanced_ai_agents/multi_agent_apps/agent_teams/ai_finance_agent_team
2

Install Dependencies

pip install -r requirements.txt
Required packages:
  • agno>=2.2.10
  • openai
  • yfinance
  • duckduckgo-search
  • sqlalchemy
3

Set OpenAI API Key

export OPENAI_API_KEY='your-api-key-here'
Get your API key from platform.openai.com
4

Run Application

python3 finance_agent_team.py
Open your browser to the URL shown in the console to access the playground interface.

Usage Examples

User: "Analyze Apple stock (AAPL)"

Finance Agent:
- Current Price: $178.32
- 52-Week Range: $124.17 - $198.23
- Market Cap: $2.8T
- P/E Ratio: 29.5
- Dividend Yield: 0.52%

Web Agent:
- Recent product launches
- Market sentiment: Positive
- Industry position: Market leader

Team Analysis:
AAPL shows strong fundamentals with consistent growth.
Recent iPhone launch driving positive sentiment.
Analyst consensus: Buy with $195 target price.
User: "Research the semiconductor industry and check NVDA"

Web Agent:
- Industry growing at 8.6% CAGR
- AI chip demand driving growth
- Supply chain improving
- Major players: NVIDIA, AMD, Intel

Finance Agent:
NVIDIA (NVDA):
- Price: $495.50
- Market Cap: $1.2T
- Forward P/E: 35.2
- Revenue Growth: 126% YoY

Team Analysis:
Semiconductor sector shows strong growth driven by AI.
NVDA is industry leader with commanding market share.
Stock trading at premium but justified by growth.
User: "Compare Tesla and traditional automakers"

Finance Agent:
| Company | Price | P/E | Market Cap |
|---------|-------|-----|------------|
| TSLA | $242.50 | 75.3 | $770B |
| F | $12.40 | 6.2 | $50B |
| GM | $32.10 | 5.8 | $42B |

Web Agent:
- EV market growing rapidly
- Tesla leads in innovation
- Traditional automakers catching up
- Battery technology key differentiator

Team Analysis:
Tesla commands premium valuation due to tech leadership.
Traditional automakers cheaper but slower EV transition.
Market favors growth and innovation in auto sector.

Technical Architecture

Database Storage

from agno.db.sqlite import SqliteDb

# Persistent storage for agent interactions
db = SqliteDb(db_file="agents.db")

# Benefits:
# - Conversation history
# - Context across sessions
# - Historical analysis
# - Performance optimization

Context Management

# Agents maintain conversation context
add_history_to_context=True

# Enables:
# - Follow-up questions
# - Reference to previous queries
# - Consistent analysis
# - Better understanding

Markdown Output

# All agents output in markdown
markdown=True

# Provides:
# - Formatted tables
# - Clear structure
# - Easy reading
# - Professional presentation

Best Practices

Query Formulation

  • Be specific about what you need
  • Mention ticker symbols explicitly
  • Combine requests for comprehensive analysis
  • Ask for comparisons when relevant

Data Interpretation

  • Review both quantitative and qualitative data
  • Consider market context
  • Look at historical trends
  • Verify with multiple sources

Cost Management

  • Use specific queries to reduce API calls
  • Leverage conversation history
  • Cache frequently accessed data
  • Monitor OpenAI usage

Error Handling

  • Verify ticker symbols
  • Check for market hours
  • Handle data unavailability
  • Validate financial data
Important Notes:
  • Financial data is for informational purposes only
  • Not investment advice
  • Always verify critical information
  • Market data may have slight delays
  • Past performance doesn’t guarantee future results

Investment Agent

Advanced investment analysis

Deep Research Agent

Comprehensive research capabilities

Legal Agent Team

Document analysis with teams