AI-Powered Stock and Investment Advisor – Built Using Google ADK

What Inspired Me

The inspiration for this project came from the idea of democratizing access to investment advice and market insights using AI. Many retail investors seek quick answers about stocks, sectors, or how to invest lump-sum amounts—yet comprehensive financial planning tools are either too complex or inaccessible. I wanted to create a conversational AI agent that could act like a personal financial assistant: responsive, context-aware, and capable of both data lookup and planning.

What I Learned

Through this project, I gained hands-on experience in:

  • Designing and orchestrating modular agents using [Google's Agent Development Kit (ADK)].
  • Integrating external financial data using the yfinance API.
  • Using tool-based agents to encapsulate logic such as fetching stock prices, analyzing sectors, or building portfolios.
  • Managing shared session state using ToolContext for context retention across agents.
  • Structuring agent outputs using Pydantic models for JSON-formatted advice.
  • Building a routing engine that dynamically selects the best agent based on user intent.

How I Built It

I divided the project into modular agent components, each designed with a single responsibility:

Core Agent Types

  • Basic Agents: For Q&A and individual tools like get_stock_price().
  • Multi-Tool Agent: Combines tools to fetch both stock price and company information.
  • Structured Agent: Uses Pydantic schema to give "Buy" or "Sell" recommendations based on live target and current prices.
  • Callback Agent: Tracks tool usage and logs pre/post tool execution events.
  • Sequential Agent (investment_advisor): A 4-stage planner agent that runs:
    • TopPickerAgent: Selects high-return stocks in a sector.
    • MarketDataAgent: Fetches beta, price, and 1Y return.
    • RiskAgent: Assigns risk tiers (High/Medium/Low).
    • PortfolioAgent: Allocates funds and returns projected returns & stop losses.

Intelligent Routing with Contextual Inference

At the core of this project is a routing logic engine implemented via the dynamic_router() function. It analyzes the user prompt for investment amounts, advice-related keywords, or ticker/company names. Based on this context, it decides which sub-agent should be activated:

def dynamic_router(prompt: str, tool_context: ToolContext) -> str:
    prompt_lower = prompt.lower()
    amount = extract_investment_amount(prompt)

    if any(term in prompt_lower for term in ["should i", "buy", "sell", "recommendation", "invest", "advice"]) and amount:
        tool_context.state["investment"] = amount
        tool_context.actions.transfer_to_agent = "investment_advisor"
        return f"Routing to full investment planning with ${amount}."

    elif any(term in prompt_lower for term in ["should i", "buy", "sell", "recommendation", "invest", "advice"]):
        tool_context.state["ticker"] = extract_ticker_or_company(prompt)
        tool_context.actions.transfer_to_agent = "structured_agent"
        return f"Analyzing '{tool_context.state['ticker']}' for investment advice." 

    else:
        tool_context.state["ticker"] = prompt.strip().upper()
        tool_context.actions.transfer_to_agent = "multi_tool_agent"
        return f"Fetching stock info for '{prompt.strip().upper()}'..."

This allows the root agent to adaptively route queries to appropriate agents based on natural language input—whether it's asking for stock prices, advice, or investment planning.

Challenges I Faced

The most significant challenge was designing a flexible, robust agent-routing mechanism that could accurately interpret vague user prompts. This required:

  • Handling multiple intents in a single sentence.
  • Differentiating between informational vs. advisory queries.
  • Managing session state across asynchronous agent workflows.
  • Debugging nested agent failures due to missing or misrouted data (e.g., incorrect state keys).

Fixes included improving fallback mechanisms, wrapping tool outputs properly, and refining keyword-based logic for better routing accuracy.

Final Output and Behavior

The final system offers a complete conversational experience:

  • Ask: "What is the stock price of Google?"
    Response: "The stock price of GOOGL is $143.85."

  • Ask: "Should I invest in Microsoft?"
    Response (structured JSON):

    {
    "ticker": "MSFT",
    "recommendation": "Buy"
    }
    
  • Ask: "I want to invest $5000"
    Response:

    Allocation:
    - AVGO: $375.0
    - META: $375.0
    - MSFT: $375.0
    - GOOGL: $375.0
    - NVDA: $500.0
    - AMD: $500.0
    

Expected 1-Year Return: $309.16

Stop-Losses:

  • AVGO: $212.49
  • META: $580.00
  • MSFT: $405.79
  • GOOGL: $141.64
  • NVDA: $122.27
  • AMD: $109.00 ```

This project proves that with modular architecture and smart routing logic, conversational AI can deliver end-to-end investment support—scalable for real-world fintech applications.

Built With

Share this project:

Updates

Submission history