How kkdai/linebot-adk-stock works
Project Type and Purpose
• This is a backend microservice (no UI) implementing a LINE messaging bot.
• It uses FastAPI to receive webhooks, routes incoming messages to AI-powered agents, calls external AI and data‐fetching services, and replies via the LINE Messaging API.
• The multi-agent design currently includes one “stock_agent” (with a planned general agent), in-memory session management, and function‐calling tools.
Top-Level Components
• LINE Platform (Messaging API)
• FastAPI Service (main.py)
• Webhook Receiver
• Runner / Agent Orchestrator
• InMemorySessionService
• Agent Modules (multi_tool_agent/stock_agent.py)
• stock_agent with its tool functions: get_stock_price, get_price_change_percent, get_best_performing
• External Services
• Google ADK (Agent SDK) → Google Gemini API or VertexAI
• yfinance (Yahoo Finance)
• Deployment Artifacts
• Docker container
• Cloud Run (or local via uvicorn / ngrok)
Relationships and Data Flow
1. A user sends a text message in LINE → LINE Platform pushes a webhook to your FastAPI endpoint.
2. FastAPI Webhook Receiver authenticates & extracts user ID + message.
3. InMemorySessionService loads/creates session context for that user.
4. Runner inspects the message, selects the root_agent (currently stock_agent).
5. stock_agent invokes one or more tool functions:
– If user asks for a stock price → calls get_stock_price (yfinance)
– If user asks percentage change → calls get_price_change_percent
– If user asks best performer → calls get_best_performing
6. For non‐tool steps or fallback, the agent uses Google ADK → Google Gemini or VertexAI to generate text.
7. Assembled reply is sent back through LINE Messaging API to the user.
Architectural Patterns and Principles
• Microservice: independent FastAPI service receiving webhooks.
• Modular Agent Pattern: pluggable agents/tools.
• Function Calling: agents call pure‐function tools for external data.
• Dependency Injection via environment variables and Docker.
• Stateless container with in-memory sessions (can be swapped for Redis in future).