Demos (#42)
* Rimossi old docs & demos * Aggiornata la documentazione dell'architettura dell'app * Aggiunti nuovi script demo per i provider di mercato * Fix problems with socials * Fix Dockerfile per dipendenze di X
This commit was merged in pull request #42.
This commit is contained in:
committed by
GitHub
parent
551b6a049f
commit
08774bee1b
@@ -1,255 +1,160 @@
|
||||
# 📊 Architettura e Flussi dell'App upo-appAI
|
||||
# 📊 Architettura upo-appAI
|
||||
|
||||
## 🏗️ Diagramma Architettura Generale
|
||||
## 🏗️ Architettura Generale
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ 🌐 GRADIO UI │
|
||||
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
|
||||
│ │ User Input │ │ Provider │ │ Style │ │
|
||||
│ │ (Query) │ │ (Model) │ │ (Conservative/ │ │
|
||||
│ │ │ │ │ │ Aggressive) │ │
|
||||
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
|
||||
└─────────────────────────┬───────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ 🔧 TOOL AGENT │
|
||||
│ (Central Orchestrator) │
|
||||
│ │
|
||||
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
|
||||
│ │ 1. Collect Data │ │ 2. Analyze │ │ 3. Predict & │ │
|
||||
│ │ │ │ Sentiment │ │ Recommend │ │
|
||||
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
|
||||
└─────────────────────────┬───────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ 📊 AGENT ECOSYSTEM │
|
||||
│ │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌───────────┐│
|
||||
│ │ MARKET │ │ NEWS │ │ SOCIAL │ │ PREDICTOR ││
|
||||
│ │ AGENT │ │ AGENT │ │ AGENT │ │ AGENT ││
|
||||
│ │ │ │ │ │ │ │ ││
|
||||
│ │ 📈 Coinbase │ │ 📰 News API │ │ 🐦 Social │ │ 🤖 LLM ││
|
||||
│ │ 📊 CryptoCmp│ │ │ │ Media │ │ Analysis ││
|
||||
│ │ 🟡 Binance │ │ │ │ │ │ ││
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ └───────────┘│
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
INTERFACCE UTENTE
|
||||
├── 💬 Gradio Web (Chat + Dropdown modelli/strategie)
|
||||
└── 📱 Telegram Bot (Mini App)
|
||||
│
|
||||
▼
|
||||
CHAT MANAGER
|
||||
├── Storico messaggi
|
||||
├── Gestione PipelineInputs
|
||||
└── Salva/Carica chat
|
||||
│
|
||||
▼
|
||||
AGNO WORKFLOW PIPELINE (4 Steps)
|
||||
├── 1. Query Check → Verifica crypto
|
||||
├── 2. Condition → Valida procedere
|
||||
├── 3. Info Recovery → Team raccolta dati
|
||||
└── 4. Report Generation → Report finale
|
||||
│
|
||||
▼
|
||||
AGNO AGENT ECOSYSTEM
|
||||
├── 👔 TEAM LEADER (coordina Market, News, Social)
|
||||
│ Tools: ReasoningTools, PlanMemoryTool, CryptoSymbolsTools
|
||||
├── 📈 MARKET AGENT → MarketAPIsTool
|
||||
├── 📰 NEWS AGENT → NewsAPIsTool
|
||||
├── 🐦 SOCIAL AGENT → SocialAPIsTool
|
||||
├── 🔍 QUERY CHECK AGENT → QueryOutputs (is_crypto: bool)
|
||||
└── 📋 REPORT GENERATOR AGENT → Strategia applicata
|
||||
```
|
||||
|
||||
## 🔄 Flusso di Esecuzione Dettagliato
|
||||
## 🔄 Flusso Esecuzione
|
||||
|
||||
```
|
||||
👤 USER REQUEST
|
||||
│
|
||||
│ "Analizza Bitcoin con strategia aggressiva"
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ 🔧 TOOL AGENT │
|
||||
│ │
|
||||
│ def interact(query, provider, style): │
|
||||
│ │ │
|
||||
│ ├── 📊 market_data = market_agent.analyze(query) │
|
||||
│ ├── 📰 news_sentiment = news_agent.analyze(query) │
|
||||
│ ├── 🐦 social_sentiment = social_agent.analyze(query) │
|
||||
│ │ │
|
||||
│ └── 🤖 prediction = predictor_agent.predict(...) │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
📊 MARKET AGENT - Parallel Data Collection
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ │
|
||||
│ 🔍 Auto-detect Available Providers: │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
||||
│ │ Coinbase │ │ CryptoComp │ │ Binance │ │
|
||||
│ │ REST │ │ API │ │ Mock │ │
|
||||
│ │ │ │ │ │ │ │
|
||||
│ │ ✅ Active │ │ ✅ Active │ │ ✅ Active │ │
|
||||
│ │ $63,500 BTC │ │ $63,450 BTC │ │ $63,600 BTC │ │
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
||||
│ │
|
||||
│ 📈 Aggregated Result: │
|
||||
│ { │
|
||||
│ "aggregated_data": { │
|
||||
│ "BTC_USD": { │
|
||||
│ "price": 63516.67, │
|
||||
│ "confidence": 0.94, │
|
||||
│ "sources_count": 3 │
|
||||
│ } │
|
||||
│ }, │
|
||||
│ "individual_sources": {...}, │
|
||||
│ "market_signals": {...} │
|
||||
│ } │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
📰 NEWS AGENT + 🐦 SOCIAL AGENT
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ │
|
||||
│ 📰 News Sentiment: "Positive momentum, institutional │
|
||||
│ adoption increasing..." │
|
||||
│ │
|
||||
│ 🐦 Social Sentiment: "Bullish sentiment on Reddit, │
|
||||
│ Twitter mentions up 15%..." │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
🤖 PREDICTOR AGENT
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ │
|
||||
│ Input: │
|
||||
│ ├── 📊 Market Data (aggregated + confidence) │
|
||||
│ ├── 📰🐦 Combined Sentiment │
|
||||
│ ├── 🎯 Style: "aggressive" │
|
||||
│ └── 🤖 Provider: "openai/anthropic/google..." │
|
||||
│ │
|
||||
│ 🧠 LLM Processing: │
|
||||
│ "Based on high confidence market data (0.94) showing │
|
||||
│ $63,516 BTC with positive sentiment across news and │
|
||||
│ social channels, aggressive strategy recommendation..." │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
📋 FINAL OUTPUT
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ 📊 Market Data Summary │
|
||||
│ 📰🐦 Sentiment Analysis │
|
||||
│ 📈 Final Recommendation: │
|
||||
│ "Strong BUY signal with 85% confidence..." │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
**Input:** "Analizza Bitcoin con strategia aggressiva"
|
||||
|
||||
1. CHAT MANAGER riceve e prepara PipelineInputs
|
||||
2. WORKFLOW PIPELINE esegue 4 step:
|
||||
- Query Check: valida `is_crypto: true`
|
||||
- Condition: se false, termina
|
||||
- Info Recovery: Team raccoglie dati
|
||||
- Report Generation: genera report
|
||||
3. OUTPUT: Report con analisi + raccomandazioni
|
||||
|
||||
## 🏛️ Architettura API
|
||||
|
||||
**Tools (Agno Toolkit):**
|
||||
- MarketAPIsTool: Binance, YFinance, CoinBase, CryptoCompare
|
||||
- NewsAPIsTool: NewsAPI, GoogleNews, DuckDuckGo, CryptoPanic
|
||||
- SocialAPIsTool: Reddit, X, 4chan
|
||||
- CryptoSymbolsTools: `resources/cryptos.csv`
|
||||
|
||||
**WrapperHandler:** Failover automatico (3 tentativi/wrapper, 2s delay)
|
||||
|
||||
## 📊 Data Aggregation
|
||||
|
||||
**ProductInfo:**
|
||||
- Volume: media tra sources
|
||||
- Price: weighted average (price × volume)
|
||||
- Confidence: spread + numero sources
|
||||
|
||||
**Historical Price:**
|
||||
- Align per timestamp
|
||||
- Media: high, low, open, close, volume
|
||||
|
||||
## 🎯 Configuration
|
||||
|
||||
**configs.yaml:**
|
||||
```yaml
|
||||
port: 8000
|
||||
models: [Ollama, OpenAI, Anthropic, Google]
|
||||
strategies: [Conservative, Aggressive]
|
||||
agents: {team_model, team_leader_model, ...}
|
||||
api: {retry_attempts: 3, retry_delay_seconds: 2}
|
||||
```
|
||||
|
||||
## 🏛️ Architettura dei Provider (Market Agent)
|
||||
**.env (API Keys):**
|
||||
- Market: CDP_API_KEY, CRYPTOCOMPARE_API_KEY, ...
|
||||
- News: NEWS_API_KEY, CRYPTOPANIC_API_KEY, ...
|
||||
- Social: REDDIT_CLIENT_ID, X_API_KEY, ...
|
||||
- LLM: OPENAI_API_KEY, ANTHROPIC_API_KEY, ...
|
||||
- Bot: TELEGRAM_BOT_TOKEN
|
||||
|
||||
## 🗂️ Struttura Progetto
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ 📊 MARKET AGENT │
|
||||
│ │
|
||||
│ 🔍 Provider Detection Logic: │
|
||||
│ ┌─────────────────────────────────────────────────────────────┐│
|
||||
│ │ def _setup_providers(): ││
|
||||
│ │ ├── 🔑 Check CDP_API_KEY_NAME + CDP_API_PRIVATE_KEY ││
|
||||
│ │ │ └── ✅ Setup Coinbase Advanced Trade ││
|
||||
│ │ ├── 🔑 Check CRYPTOCOMPARE_API_KEY ││
|
||||
│ │ │ └── ✅ Setup CryptoCompare ││
|
||||
│ │ └── 🔑 Check BINANCE_API_KEY (future) ││
|
||||
│ │ └── ✅ Setup Binance API ││
|
||||
│ └─────────────────────────────────────────────────────────────┘│
|
||||
│ │
|
||||
│ 📡 Data Flow: │
|
||||
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
||||
│ │ Provider 1 │───▶│ │◀───│ Provider 2 │ │
|
||||
│ │ Coinbase │ │ AGGREGATOR │ │ CryptoComp │ │
|
||||
│ │ │ │ │ │ │ │
|
||||
│ │ Real-time │ │ ┌─────────┐ │ │ Real-time │ │
|
||||
│ │ Market Data │ │ │Confidence│ │ │ Market Data │ │
|
||||
│ └─────────────┘ │ │Scoring │ │ └─────────────┘ │
|
||||
│ │ │ │ │ │
|
||||
│ ┌─────────────┐ │ │ Spread │ │ ┌─────────────┐ │
|
||||
│ │ Provider 3 │───▶│ │Analysis │ │◀───│ Provider N │ │
|
||||
│ │ Binance │ │ │ │ │ │ Future │ │
|
||||
│ │ │ │ └─────────┘ │ │ │ │
|
||||
│ │ Mock Data │ │ │ │ │ │
|
||||
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
src/app/
|
||||
├── __main__.py
|
||||
├── configs.py
|
||||
├── agents/
|
||||
│ ├── core.py
|
||||
│ ├── pipeline.py
|
||||
│ ├── plan_memory_tool.py
|
||||
│ └── prompts/
|
||||
├── api/
|
||||
│ ├── wrapper_handler.py
|
||||
│ ├── core/ (markets, news, social)
|
||||
│ ├── markets/ (Binance, CoinBase, CryptoCompare, YFinance)
|
||||
│ ├── news/ (NewsAPI, GoogleNews, DuckDuckGo, CryptoPanic)
|
||||
│ ├── social/ (Reddit, X, 4chan)
|
||||
│ └── tools/ (Agno Toolkits)
|
||||
└── interface/ (chat.py, telegram_app.py)
|
||||
|
||||
tests/
|
||||
demos/
|
||||
resources/cryptos.csv
|
||||
docs/
|
||||
configs.yaml
|
||||
.env
|
||||
```
|
||||
|
||||
## 🔧 Signers Architecture
|
||||
## 🔑 Componenti Chiave
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ 🔐 SIGNERS ECOSYSTEM │
|
||||
│ │
|
||||
│ 📁 src/app/signers/market_signers/ │
|
||||
│ │ │
|
||||
│ ├── 🏦 coinbase_rest_signer.py │
|
||||
│ │ ├── 🔑 Uses: CDP_API_KEY_NAME + CDP_API_PRIVATE_KEY │
|
||||
│ │ ├── 📡 RESTClient from coinbase.rest │
|
||||
│ │ ├── 📊 get_asset_info() → Real Coinbase data │
|
||||
│ │ └── 📈 get_multiple_assets() → Bulk data │
|
||||
│ │ │
|
||||
│ ├── 📊 cryptocompare_signer.py │
|
||||
│ │ ├── 🔑 Uses: CRYPTOCOMPARE_API_KEY │
|
||||
│ │ ├── 📡 Direct HTTP requests │
|
||||
│ │ ├── 💰 get_crypto_prices() → Multi-currency │
|
||||
│ │ └── 🏆 get_top_cryptocurrencies() → Market cap │
|
||||
│ │ │
|
||||
│ └── 🟡 binance_signer.py │
|
||||
│ ├── 🔑 Uses: BINANCE_API_KEY (future) │
|
||||
│ ├── 📡 Mock implementation │
|
||||
│ ├── 🎭 Simulated market data │
|
||||
│ └── 📈 Compatible interface │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
1. **Agno Framework**: Agent, Team, Workflow, Toolkit, RunEvent
|
||||
2. **WrapperHandler**: Failover, Retry logic, Type safety
|
||||
3. **Data Aggregation**: Multiple sources, Confidence score
|
||||
4. **Multi-Interface**: Gradio + Telegram
|
||||
5. **Configuration**: configs.yaml + .env
|
||||
|
||||
## 🚀 Deployment
|
||||
|
||||
**Docker:**
|
||||
```bash
|
||||
docker-compose up --build -d
|
||||
```
|
||||
|
||||
## 🚀 Future Enhancement: Async Flow
|
||||
|
||||
```
|
||||
📱 USER REQUEST
|
||||
│
|
||||
▼
|
||||
🔧 TOOL AGENT (async)
|
||||
│
|
||||
┌────────────────┼────────────────┐
|
||||
│ │ │
|
||||
▼ ▼ ▼
|
||||
📊 Market 📰 News 🐦 Social
|
||||
Agent (async) Agent (async) Agent (async)
|
||||
│ │ │
|
||||
┌────┼────┐ │ │
|
||||
▼ ▼ ▼ │ │
|
||||
Coinbase │ Binance │ │
|
||||
CC │ │ │
|
||||
▼▼▼ ▼ ▼
|
||||
🔄 Parallel 📰 Sentiment 🐦 Sentiment
|
||||
Aggregation Analysis Analysis
|
||||
│ │ │
|
||||
└────────────────┼────────────────┘
|
||||
▼
|
||||
🤖 PREDICTOR AGENT
|
||||
(LLM Analysis)
|
||||
│
|
||||
▼
|
||||
📋 FINAL RESULT
|
||||
(JSON + Confidence)
|
||||
**Local (UV):**
|
||||
```bash
|
||||
uv venv
|
||||
uv pip install -e .
|
||||
uv run src/app
|
||||
```
|
||||
|
||||
## 📊 Data Flow Example
|
||||
## 🎯 Workflow Asincrono
|
||||
|
||||
```
|
||||
Input: "Analyze Bitcoin aggressive strategy"
|
||||
│
|
||||
├── 📊 Market Agent Output:
|
||||
│ {
|
||||
│ "aggregated_data": {
|
||||
│ "BTC_USD": {"price": 63516.67, "confidence": 0.94}
|
||||
│ },
|
||||
│ "individual_sources": {
|
||||
│ "coinbase": {"price": 63500, "volume": "1.2M"},
|
||||
│ "cryptocompare": {"price": 63450, "volume": "N/A"},
|
||||
│ "binance": {"price": 63600, "volume": "2.1M"}
|
||||
│ },
|
||||
│ "market_signals": {
|
||||
│ "spread_analysis": "Low spread (0.24%) - healthy liquidity",
|
||||
│ "price_divergence": "Max deviation: 0.24% - Normal range"
|
||||
│ }
|
||||
│ }
|
||||
│
|
||||
├── 📰 News Sentiment: "Positive institutional adoption news..."
|
||||
├── 🐦 Social Sentiment: "Bullish Reddit sentiment, +15% mentions"
|
||||
│
|
||||
└── 🤖 Predictor Output:
|
||||
"📈 Strong BUY recommendation based on:
|
||||
- High confidence market data (94%)
|
||||
- Positive news sentiment
|
||||
- Bullish social indicators
|
||||
- Low spread indicates healthy liquidity
|
||||
|
||||
Aggressive Strategy: Consider 15-20% portfolio allocation"
|
||||
```python
|
||||
workflow = Workflow(steps=[
|
||||
query_check, condition,
|
||||
info_recovery, report_generation
|
||||
])
|
||||
|
||||
iterator = await workflow.arun(query, stream=True)
|
||||
|
||||
async for event in iterator:
|
||||
if event.event == PipelineEvent.TOOL_USED:
|
||||
log(f"Tool: {event.tool.tool_name}")
|
||||
```
|
||||
|
||||
---
|
||||
*Diagrammi creati: 2025-09-23*
|
||||
*Sistema: upo-appAI Market Analysis Platform*
|
||||
**Vantaggi:** Asincrono, Streaming, Condizionale, Retry
|
||||
|
||||
## 📈 Future Enhancements
|
||||
|
||||
- Parallel Tool Execution
|
||||
- Caching (Redis)
|
||||
- Database (PostgreSQL)
|
||||
- Real-time WebSocket
|
||||
- ML Models
|
||||
- User Profiles
|
||||
- Backtesting
|
||||
|
||||
Reference in New Issue
Block a user