A sophisticated, self-learning CLI tool built with the Strands Agents SDK that uses a multi-agent (Orchestrator) system to answer complex financial queries. It features specialist agents for SQL, live financial data (yfinance), and real-time news (Tavily), including a self-correcting loop to find and save new stock tickers.
This project is a powerful, interactive Command-Line Interface (CLI) application that functions as a Multi-Agent Financial Analyst. Built using the Strands Agents SDK, it serves as a practical demonstration of a robust, modular, and intelligent agentic architecture.
Instead of relying on a single, monolithic AI model, this system employs a Hierarchical Delegation (or "Agent-as-a-Tool") pattern. A central Orchestrator Agent acts as the "manager," interpreting complex user queries and delegating specific sub-tasks to a team of specialized agents.
This system's intelligence is distributed among three specialist agents, each with a distinct and precise role:
- Data Analyst Agent: The "gatekeeper" for all company data. It's responsible for converting company names (like "Apple") into official stock tickers ("AAPL").
- Financial Metrics Agent: The "quant." A precision-focused agent that fetches live financial data (like P/E ratio and stock price) using the
yfinanceAPI. - News Research Agent: The "researcher." It uses the
TavilyAPI to scan the web for real-time news and generates concise, human-readable summaries.
This system is built on the Strands Agents SDK and utilizes a Hierarchical Delegation ("Agent-as-a-Tool") architecture. This modular pattern separates the main Orchestrator from its specialized agents, enabling complex, multi-step, and self-correcting task execution.
- The system features one main Orchestrator Agent (
main.py) that serves as the "Lead Financial Analyst." - The Orchestrator manages a team of Specialist Agents (
agent-tools.py) which are defined as callable tools. - Specialist agents are designed for single-responsibility tasks:
data_analyst_agent: Manages data lookup and self-correction.financial_metrics_agent: Fetches live financial data.news_research_agent: Fetches and summarizes web news.
- The
data_analyst_agentimplements a Python-based self-healing loop. - When a primary tool (e.g.,
sql_query_tool) fails to find a ticker (aTICKER_NOT_FOUNDstate), the agent automatically triggers a secondary protocol. - It calls the
news_research_agentto find the missing data from the web. - It then uses the
sql_update_toolto permanently save the new ticker to the SQLite database, allowing the agent to learn.
- Model:
gpt-3.5-turbo(Configurable viaagent-tools.py). - Provider: OpenAI API.
- Framework: Utilizes the Strands' native
OpenAIModelprovider. - Context Handling: Relies on strict, role-based system prompts for each specialist agent to ensure deterministic outputs (e.g., raw JSON, single tickers) and minimize hallucinations.
- Database: SQLite (via Python's built-in
sqlite3) for persistent storage of company ticker symbols. - Live Financials:
yfinanceAPI, wrapped in thefinancial_data_tool. - Web Research:
TavilyAPI, wrapped in thenews_search_toolfor agent-optimized search results. - Memory:
mem0_memorytool provides a FAISS-backed vector store for the Orchestrator to persist conversational memory.
- π§ Hierarchical Multi-Agent System: Built on the Strands Agents SDK, this project uses an "Agent-as-a-Tool" architecture. A central Orchestrator Agent (the "manager") intelligently delegates complex tasks to a team of specialized, single-purpose agents.
- π Autonomous Self-Correction Loop: Features a "smart" Data Analyst Agent that automatically detects when a stock ticker is missing. It then triggers a self-healing protocol: it uses the
news_research_agentto find the ticker on the web and then uses thesql_update_toolto permanently save the new information to its SQLite database. - βοΈ Specialized Multi-Source Integration: Combines data from distinct, real-world sources by dedicating an agent to each one:
- Database:
sqlite3for persistent, local ticker data. - Live Market Data:
yfinanceAPI for real-time stock prices and P/E ratios. - Web Research:
Tavily APIfor agent-optimized, live news summarization.
- Database:
- π» Professional CLI Interface: A clean, asynchronous
asynciocommand-line interface. It features a multi-threaded spinner (β£Ύ Orchestrator is thinking...) and a smart callback handler that neatly separates agent "thinking" (tool calls) from the final, streamed answer.
π¦ strands-openai-financial-agent
β
βββ configuration.py # Environment setup and configurations
βββ agent-tools.py # Core strands workflow and agent logic
βββ main.py # CLI frontend for user interaction
βββ db_setup.py # Sqltite DataBase creation script
βββ README.md
βββ License
- Complex Financial Analysis: Ask multi-step questions that require data from multiple sources. For example: "Compare the P/E ratio of Apple and Google, and get me the latest news for Apple."
- Autonomous Company Research: Perform research on new or unknown companies. The agent will autonomously find the official ticker, save it to the database for future use, and then proceed with the financial analysis.
- Real-time Data Retrieval: Get instant, up-to-the-minute information without leaving the terminal. Ask for "the latest news for Microsoft" or "the current price of Tesla" to get live data from web APIs.
- Financial Power-Tool: Use as a high-speed tool for financial analysts, traders, or hobbyists to quickly gather and synthesize market data directly from their CLI.
- Agent Architecture Demo: Serve as a working, production-ready example of a Hierarchical Multi-Agent System (Agent-as-a-Tool) and a Self-Correcting Loop for other developers to learn from and build upon.
CLI Interface
- Python 3.10+
- CUDA-compatible GPU (optional, for faster processing)
- 8GB+ RAM recommended
git clone https://github.com/Ginga1402/strands-openai-financial-agent.git
cd strands-openai-financial-agentpip install -r requirements.txtUpdate the paths in configuration.py to match your system:
TAVILY_API_KEY = "YOUR-TAVILY-KEY"
OPENAI_KEY = "YOUR-OPENAI-KEY"
DB_FILE = 'financial_data.db'- Start the CLI Application:
python main.py-
User Input β The user asks a complex, natural-language question (e.g., "Compare the P/E ratio of Nvidia and Apple, and get me the latest news for Nvidia.").
-
Deconstruct Query β The main Orchestrator Agent (the "Lead Analyst") receives the query and its LLM deconstructs it into a multi-step plan (e.g., [Find Ticker: "Nvidia"], [Find Ticker: "Apple"], [Get Finance Data: Ticker 1], [Get Finance Data: Ticker 2], [Get News: Ticker 1]).
-
Resolve Tickers (Self-Correction) β The Orchestrator calls the data_analyst_agent for each company name.
- This specialist agent queries the local SQLite database.
- If the ticker is missing, it automatically triggers its self-correction loop: it calls the news_research_agent (using Tavily) to find the ticker on the web, then saves it to the SQLite DB using the sql_update_tool.
-
Execute Data Calls β The Orchestrator, now holding the correct tickers (e.g., "NVDA", "AAPL"), executes the next steps of its plan by calling the other specialists:
- financial_metrics_agent (which calls the yfinance API).
- news_research_agent (which calls the Tavily API).
-
Synthesize Response β The Orchestrator's LLM receives all the structured data (raw JSON from financial_metrics_agent) and unstructured data (text summaries from news_research_agent).
-
Generate Final Answer β The Orchestrator synthesizes all the gathered information into a single, comprehensive, human-readable response, which is streamed to the user in the CLI.
Workflow Graph:
START β deconstruct_query β resolve_tickers β execute_data_calls β synthesize_response β generate_final_answer β END
| Technology | Description | Link |
|---|---|---|
| Strands Agents SDK | A lightweight, model-driven framework for building AI agents. | Strands SDK (GitHub) |
| OpenAI | Used for LLM inference, powering all agent reasoning. | OpenAI |
gpt-3.5-turbo |
The specific model used for its balance of speed, cost, and tool-calling. | OpenAI Models |
| Tavily API | AI-optimized search engine for real-time web research. | Tavily |
| yfinance | Python library for fetching live financial data from Yahoo! Finance. | yfinance (PyPI) |
| SQLite | Lightweight, built-in database used for persistent ticker storage. | SQLite |
| mem0 | The memory tool used by the Orchestrator for FAISS-backed vector memory. | mem0 (GitHub) |
| Colorama | Python library for producing colored terminal text and a professional CLI UI. | Colorama (PyPI) |
| Asyncio | Python's built-in library for managing the asynchronous CLI loop. | Asyncio (Python Docs) |
Contributions to this project are welcome! If you have ideas for improvements, bug fixes, or new features, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you find strands-openai-financial-agent useful, please consider giving it a star β on GitHub!