A multi-agent stock analysis system built with PydanticAI and Streamlit. Five specialized AI agents collaborate to analyze a stock, form a strategy, assess risk, check regulatory compliance, and produce a final, type-safe trading decision — all from an interactive web dashboard.
Disclaimer: This is an educational project that demonstrates multi-agent AI orchestration. It is not financial advice and should not be used to make real investment decisions.
The system breaks stock analysis into a pipeline of focused AI agents. Each agent has a narrow responsibility, its own tools, and a strict output schema enforced by Pydantic — so every result is validated, structured data rather than free-form text. Agents run individually from the dashboard and declare dependencies on one another, making the decision flow explicit and auditable.
| Agent | Role | Depends on |
|---|---|---|
| Market Analyst | Analyzes price data and technical indicators (RSI, MACD, Bollinger Bands, Fibonacci levels) | — |
| Strategy Agent | Develops a trading strategy from the market analysis | Market Analyst |
| Risk Manager | Assesses position risk and sizing | Market Analyst |
| Regulatory Agent | Checks compliance (e.g. Regulation M) | Market Analyst, Strategy Agent |
| Supervisor Agent | Weighs all inputs and issues the final TradingDecision |
All of the above |
Each agent verifies that its prerequisites have run and returns a clear message if they haven't.
- Type-safe agent outputs — every response is a validated Pydantic model. The final decision is a
TradingDecisionobject with an enum signal (BUY/SELL/HOLD), a bounded confidence score, a risk level, and a rationale. - Explicit dependency system — agents check that upstream agents have run and report progress in the UI.
- Manual trade execution — analysis never writes to storage automatically. A separate "Execute Trade" action records the final decision, keeping you in control of what gets logged.
- Pluggable storage — works out of the box with CSV files; optionally upgrades to PostgreSQL via a single environment variable.
- Offline-friendly — runs on bundled demo data when live market data is unavailable; only the AI calls require an internet connection.
- Audit trail — decisions and signals are persisted with timestamps, confidence, and rationale.
multi-agent-trading/
├── app/
│ ├── main.py # Streamlit dashboard & agent orchestration
│ ├── config.py # Settings loaded from environment variables
│ ├── agents/
│ │ ├── pydantic_agents.py # The 5-agent PydanticAI system
│ │ └── smol_agents.py # Alternative agent implementation
│ ├── models/
│ │ └── trading_models.py # Pydantic schemas for all agent outputs
│ ├── tools/ # Market-data & storage tools used by agents
│ ├── data/ # Market data + demo data handlers
│ ├── storage/ # CSV storage backend
│ └── db/ # Optional PostgreSQL backend
├── data_storage/ # Runtime CSV output (gitignored)
├── requirements.txt
├── run_app.sh # Quick-start launcher
├── .env.example # Template for your API keys
└── LICENSE
Python · Streamlit · PydanticAI · Pydantic · OpenAI API · LangChain · yfinance · Plotly · PostgreSQL (optional)
- Python 3.11 or newer
- An OpenAI API key (a Vocareum-issued
voc-key also works and is routed automatically)
git clone https://github.com/SebAustin/multi-agent-trading.git
cd multi-agent-trading
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtCopy the template and add your key — the .env file is gitignored and never committed:
cp .env.example .envThen edit .env and set at least OPENAI_API_KEY. All other variables are optional.
./run_app.shOr directly:
streamlit run app/main.py --server.port 8501Open http://localhost:8501 in your browser.
- Load stock data — enter a symbol (e.g.
AAPL,MSFT) and click Load Stock Data. - Run agents in order — click the agent buttons in the sidebar. Each one shows its analysis and tells you if a prerequisite is missing.
- Review the decision — the Supervisor Agent produces the final validated
TradingDecision. - Execute — click Execute Trade to persist the decision to storage.
All settings are read from environment variables (see .env.example):
| Variable | Required | Purpose |
|---|---|---|
OPENAI_API_KEY |
Yes | OpenAI / Vocareum API key |
ANTHROPIC_API_KEY |
No | Use Anthropic Claude instead of OpenAI |
TAVILY_API_KEY |
No | News-based sentiment analysis |
ALPHA_VANTAGE_API_KEY / QUANDL_API_KEY |
No | Additional market-data sources |
DATABASE_URL |
No | PostgreSQL connection string; falls back to CSV storage if unset |
DEFAULT_SYMBOL, CACHE_TIMEOUT_HOURS, DEFAULT_AI_MODEL, USE_OPENAI |
No | App behavior tweaks |
- "Model initialization issue" — check that
OPENAI_API_KEYis set in your.envand that the key is valid with available credits. - "Please load stock data first" — click Load Stock Data before running any agent, and confirm the symbol is valid.
- Database connection errors — the app automatically falls back to CSV storage. To use PostgreSQL, ensure
DATABASE_URLis correct and the database is reachable.
Released under the MIT License.
Built as a hands-on project exploring agentic AI for financial services — multi-agent orchestration, tool use, and structured/type-safe LLM outputs with PydanticAI.