A complete financial analysis application built with Google Agent Development Kit (ADK), featuring a modern Streamlit web interface and a powerful finance agent backend with real-time market data integration.
2025-06-09.15-19-32.mp4
This project consists of two main components:
- Streamlit Web Interface: Modern, interactive chat UI
- Real-time Streaming: Live streaming of agent responses with visual indicators
- Tool Execution Visualization: Chronological display of tool calls with expandable results
- Session Management: Create and manage ADK agent sessions
- Error Handling: Robust error handling and user feedback
- ADK Agent: Powered by Google Agent Development Kit
- YFinance Integration: Real-time market data and financial analysis
- Comprehensive Tools: Stock prices, company info, historical data, fundamentals, news
- OpenRouter LLM: Advanced language model integration for financial analysis
- Python 3.8+ with pip
- OpenRouter API Key (for LLM access)
- Internet connection (for real-time market data)
-
Clone and setup the project:
git clone <repository-url> cd Google-ADK-Agents pip install -r requirements.txt
-
Configure environment variables: Create a
.env
file in thefinance_agent/
directory:OPENROUTER_API_KEY=your_openrouter_api_key_here OPENROUTER_BASE_URL=https://openrouter.ai/api/v1 TAVILY_API_KEY=your_tavily_api_key_here
-
Verify YFinance installation:
import yfinance as yf stock = yf.Ticker("AAPL") print(stock.info.get("regularMarketPrice"))
-
Start the ADK agent backend:
#parent directory adk api_server --host 0.0.0.0 --port 8000
-
In a new terminal, start the Streamlit frontend:
streamlit run app.py
-
Open your browser to
http://localhost:8501
and start chatting!
#parent directory
adk run finance_agent
#parent directory
adk web
- π Real-time Streaming: Live streaming of agent responses
- π οΈ Tool Execution Visualization: See tools execute in real-time
- π¬ Modern Chat Interface: Clean, responsive chat UI
- π Copy to Clipboard: Easily copy agent responses
- π§ Session Management: Easy session creation and management
- π° Finance-Optimized: Proper handling of financial symbols and data
- π― Error Handling: Comprehensive error handling and user feedback
- π± Responsive Design: Works on desktop and mobile devices
- π Real-time Stock Data: Current prices with currency information
- π Company Analysis: Comprehensive profiles and business information
- π Historical Data: Historical prices with customizable time periods
- π° Financial Fundamentals: P/E ratios, EPS, debt-to-equity, ROE/ROA
- π° Market News: Latest company news and press releases
- π Web Search: Real-time web search for general financial news and information
- π’ Technical Indicators: Advanced technical analysis
- π Income Statements: Detailed financial statements
- π― Analyst Recommendations: Professional analyst insights
The finance agent provides these powerful tools accessible through the Streamlit interface:
Tool | Description | Example Query |
---|---|---|
get_current_stock_price |
Real-time stock prices | "What's Tesla's current price?" |
get_company_info |
Company profiles and metrics | "Tell me about Microsoft" |
get_historical_stock_prices |
Historical price data | "Apple's performance last year" |
get_stock_fundamentals |
Financial ratios and analysis | "Google's financial fundamentals" |
get_company_news |
Recent news and developments | "Latest Amazon news" |
get_income_statements |
Financial statements | "Netflix income statement" |
get_key_financial_ratios |
Key financial metrics | "Microsoft's financial ratios" |
get_analyst_recommendations |
Professional recommendations | "Apple analyst recommendations" |
get_technical_indicators |
Technical analysis data | "Tesla technical indicators" |
tavily_search_results |
Comprehensive web search | "What are the latest financial news headlines for Google?" |
Try these queries in the Streamlit interface:
- "What is Apple's current stock price and recent performance?"
- "Compare the financial performance of Tesla vs Ford over the last year"
- "Analyze Microsoft's quarterly earnings and provide key insights"
- "What are the top 5 performing tech stocks this month?"
- "Explain the recent market trends in the renewable energy sector"
- "What is Amazon's P/E ratio and how does it compare to industry average?"
- "Create a detailed SWOT analysis for Netflix in the current streaming market"
- "What are the key financial ratios I should look at when evaluating Nvidia's stock?"
- "Analyze the impact of recent Fed interest rate changes on bank stocks"
- "Compare the debt-to-equity ratios of major airlines: Delta, United, and Southwest"
- "What are the latest economic indicators for the US market?"
- "Summarize recent news about inflation and its impact on the stock market."
- Be specific: Instead of "How is Apple doing?", try "What was Apple's revenue growth in Q3 2024?"
- Ask for comparisons: "Compare X vs Y" often provides valuable insights
- Request explanations: Add "explain why" to understand the reasoning behind trends
- Use timeframes: Specify periods like "last quarter", "past year", or "since 2020"
Streamlit App (app.py)
βββ Session Management
βββ ADK API Integration (/run_sse endpoint)
βββ Real-time Event Processing
β βββ Function Calls (Tool Execution)
β βββ Function Responses (Tool Results)
β βββ Text Streaming (LLM Response)
βββ UI Components
βββ Chat Interface
βββ Tool Status Displays
βββ Error Handling
Finance Agent (finance_agent/)
βββ agent.py (Main agent logic)
βββ tools.py (YFinance tool implementations)
βββ prompts.py (System prompts and instructions)
βββ ADK Integration
βββ OpenRouter LLM
βββ Tool Execution Engine
βββ Session Management
- User Input β Streamlit UI
- HTTP Request β ADK Agent API (
/run_sse
) - Tool Execution β YFinance APIs
- LLM Processing β OpenRouter
- Streaming Response β Server-Sent Events
- Real-time Display β Streamlit UI
# Process all parts within a single event
if "content" in event and event["content"].get("parts"):
for part in event["content"]["parts"]:
if "functionCall" in part:
# Handle tool start
elif "functionResponse" in part:
# Handle tool result
elif "text" in part:
# Handle streaming text
# Create assistant container FIRST
with st.chat_message("assistant"):
assistant_container = st.container()
# All tools created within this container
# Escape dollar signs for Streamlit
def escape_markdown_dollars(text: str) -> str:
return text.replace('$', '\\$')
- Layout Shifts: Creating tool calls outside assistant container
- Event Skipping: Using
elif
instead of processing all parts - Text Duplication: Ignoring
partial
flags in streaming - Tool Mismatching: Not tracking tool IDs properly
Google-ADK-Agents/
βββ app.py # Streamlit frontend application
βββ readme.md # This comprehensive guide
βββ requirements.txt # Python dependencies
βββ finance_agent/ # ADK agent backend
βββ agent.py # Main agent configuration
βββ tools.py # YFinance tool implementations
βββ prompts.py # System prompts
βββ README.md # Backend-specific documentation
βββ __init__.py # Python package initialization
- API Keys: Store OpenRouter API key securely in
.env
- Local Only: Default configuration runs locally only
- No Authentication: Current setup has no user authentication
- Yahoo Finance TOS: Subject to Yahoo Finance terms of service
- Real-time Delays: Market data may have slight delays
- Educational Use: For educational and research purposes only
- Not Financial Advice: This tool does not provide investment advice
- Frontend:
streamlit run app.py
- Backend:
adk api_server
- Streamlit Cloud: Deploy frontend to Streamlit Cloud
- Google Cloud Run: Deploy ADK agent to Cloud Run
- Docker: Containerize both components
- Test SSE event handling with real ADK agents
- Verify chronological order of tool calls
- Test error scenarios and edge cases
- Ensure financial data displays correctly
- Add new YFinance tools in
tools.py
- Update prompts in
prompts.py
for new capabilities - Test tool integration with ADK framework
- Validate financial data accuracy
- Follow ADK best practices for agent development
- Use proper error handling for both frontend and backend
- Test with real market data and various stock symbols
- Maintain backward compatibility with existing tools
This project is for educational purposes. Please respect:
- Yahoo Finance's terms of service
- OpenRouter's usage policies
- Google ADK licensing terms