A multi-agent stock analysis system that synthesizes opposing investment perspectives into balanced recommendations. The system channels Charlie Munger's skeptical "inversion thinking" and Warren Buffett's value-focused optimism through separate AI agents, then merges their insights into actionable investment theses.
Given a stock ticker (e.g., AAPL, MSTR, TSLA), the system:
- Fetches real-time financial metrics and news via
yfinance - Generates a Bear Memo using Munger-style skepticism (focuses on risks, red flags, overvaluation)
- Generates a Bull Memo using Buffett-style value analysis (focuses on moats, pricing power, durability)
- Synthesizes both perspectives into a final recommendation with confidence scoring and caveats
Output: A structured report with:
- Final recommendation:
STRONG_BUY|BUY|HOLD|SELL|STRONG_SELL - Confidence score (0.0β1.0)
- Balanced synthesis summary
- Key caveats for independent verification
- Full bear and bull analyst memos
βββββββββββββββ
β User β
β (Ticker) β
ββββββββ¬βββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Streamlit UI (app.py) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Scout Agent (scout.py) β
β β’ Fetches financial metrics from yfinance β
β β’ Pulls recent news headlines β
β β Outputs: ScoutReport β
βββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β
βββββββββββββ΄ββββββββββββ
βΌ βΌ
ββββββββββββββββββββ ββββββββββββββββββββ
β Bear Analyst β β Bull Analyst β
β (Munger AI) β β (Buffett AI) β
β β β β
β Gemini LLM β β Gemini LLM β
β + System Prompt β β + System Prompt β
β β β β
β β AnalystMemo β β β AnalystMemo β
β (Bear) β β (Bull) β
ββββββββββ¬ββββββββββ ββββββββββ¬ββββββββββ
β β
βββββββββββββ¬ββββββββββββ
βΌ
ββββββββββββββββββββββββββ
β Synthesizer Agent β
β (synthesizer.py) β
β β
β Gemini LLM β
β Weighs both theses β
β β
β β FinalRecommendation β
ββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Rich UI Report β
β β’ Colored badge β
β β’ Confidence score β
β β’ Synthesis summary β
β β’ Caveats list β
β β’ Expandable memos β
ββββββββββββββββββββββββββ
- Python 3.11+
- Google Gemini API Key (Get one here)
-
Clone the repository
git clone https://github.com/iamkhalid2/kwealth.git cd kwealth -
Create and activate virtual environment
On Windows:
python -m venv venv venv\Scripts\activate
On macOS/Linux:
python3 -m venv venv source venv/bin/activate -
Install dependencies
pip install -r requirements.txt
-
Configure API key
Create a
.envfile (use.env.exampleas template):GEMINI_API_KEY=your_actual_api_key_here
streamlit run app.py
# or
python -m streamlit run app.pyThen open your browser to http://localhost:8501
Note: Make sure your virtual environment is activated before running the app.
- Enter a ticker:
AAPL - Click π Analyze
- Watch the multi-step progress:
- β Fetching data...
- β Generating Bear memo (Munger)...
- β Generating Bull memo (Buffett)...
- β Synthesizing recommendations...
- Review the final report with metrics, memos, and caveats
from agents.scout import fetch_scout_report
from agents.analyst import generate_bear_memo, generate_bull_memo
from agents.synthesizer import synthesize
# Fetch data
report = fetch_scout_report("AAPL")
# Generate opposing perspectives
bear = generate_bear_memo(report)
bull = generate_bull_memo(report)
# Synthesize final recommendation
final = synthesize(bull, bear, report.metrics)
print(f"Recommendation: {final.recommendation}")
print(f"Confidence: {final.confidence_score}")
print(f"Summary: {final.synthesis_summary}")Edit config.py to customize:
| Setting | Default | Description |
|---|---|---|
GEMINI_MODEL |
gemini-3-flash-preview |
Gemini model to use |
REQUEST_TIMEOUT |
30 |
API timeout in seconds |
MAX_HEADLINES |
5 |
Number of news headlines to fetch |
kwealth/
βββ SPEC.md # Full technical specification
βββ requirements.txt # Python dependencies
βββ .env.example # API key template
βββ config.py # Centralized configuration
βββ app.py # Streamlit UI (entry point)
βββ agents/
βββ __init__.py # Package exports
βββ schemas.py # Pydantic data models
βββ scout.py # Financial data fetcher
βββ analyst.py # Bear/Bull memo generators
βββ synthesizer.py # Final recommendation logic
- Calls
yfinanceto fetch:- Financial metrics (P/E, P/B, D/E, FCF, market cap, etc.)
- Recent news headlines
- Normalizes data (e.g., converts yfinance's D/E percentage to ratio)
- Returns structured
ScoutReport
Bear Agent (Munger) focuses on:
- Hidden risks and overvaluation
- Debt concerns and accounting red flags
- Competitive threats and market saturation
- Crypto/fad exposure warnings
Bull Agent (Buffett) focuses on:
- Durable competitive moats
- Brand power and pricing power
- Free cash flow generation
- Management quality and capital allocation
Both use Gemini's structured output to produce typed AnalystMemo objects with:
- Summary (3-4 sentences)
- Key points (3-5 bullets)
- Risk/reward assessment
- Confidence score
- Receives both bear and bull memos + current metrics
- Uses Gemini to weigh arguments intelligently (not simple averaging)
- Produces:
- Final recommendation enum
- Confidence score (0.0β1.0)
- Synthesis summary balancing both views
- 3-5 specific caveats for user to verify independently
Recommendation: SELL (Confidence: 70%)
Synthesis:
While Apple remains a premier cash-flow engine with an unrivaled ecosystem, the valuation has reached levels that ignore structural risks. A P/B ratio over 51 and 32x P/E for a maturing hardware business suggest the stock is priced for perfection. The bear argument regarding financial engineering is compelling; using debt to fund buybacks at these valuations suggests management is prioritizing EPS support over fundamental reinvestment...
Key Caveats:
β οΈ Verify net cash position to determine if 152% D/E is mitigated by offshore liquidityβ οΈ Monitor US/EU antitrust cases targeting App Store commission structuresβ οΈ Evaluate upcoming iPhone refresh cycle for genuine AI-driven super-cycleβ οΈ Analyze Services growth sustainability if third-party payments are mandatedβ οΈ Check for shifts in capital allocation strategy at current price levels
The system gracefully handles:
- Invalid tickers: Shows user-friendly error message
- API failures: Catches Gemini 503/timeout errors with clear messages
- Missing data: Displays "N/A" for unavailable metrics (e.g., no dividend yield for growth stocks)
- Never commit
.envwith real API keys - API key is loaded via
python-dotenvfrom.env - Use
.env.exampleas a template for sharing
Contributions welcome! Areas for improvement:
- Add support for portfolio-level analysis
- Integrate additional data sources (SEC filings, earnings transcripts)
- Implement caching for repeated ticker lookups
- Add charting/visualization for historical performance
- Support non-US stocks
MIT License - see LICENSE for details.
- yfinance for financial data
- Google Gemini for LLM-powered analysis
- Streamlit for rapid UI prototyping
- Inspired by the investment philosophies of Charlie Munger and Warren Buffett
This tool is for educational and research purposes only. It does not constitute financial advice. Always conduct your own due diligence and consult with a qualified financial advisor before making investment decisions. The system's recommendations are generated by AI and may contain errors or biases.