Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
This commit is contained in:
TIANHE
2025-12-30 21:14:30 +08:00
parent 50939212be
commit c451e16caa
5 changed files with 351 additions and 127 deletions
+71 -16
View File
@@ -124,25 +124,80 @@ QuantDingers agents dont start from scratch every time. The backend includ
- **Where it lives**: Local SQLite files under `backend_api_python/data/memory/` (privacy-first).
```mermaid
flowchart TD
A[POST /api/analysis/multi] --> B[AnalysisService]
B --> C[AgentCoordinator]
C --> D[Build context: price/kline/news/indicators]
flowchart TB
%% ===== 🌐 Entry Layer =====
subgraph Entry["🌐 API Entry"]
A["📡 POST /api/analysis/multi"]
A2["🔄 POST /api/analysis/reflect"]
end
subgraph Agents[Agents]
E[Analysts + Researchers + Trader]
end
%% ===== ⚙️ Service Layer =====
subgraph Service["⚙️ Service Orchestration"]
B[AnalysisService]
C[AgentCoordinator]
D["📊 Build Context<br/>price · kline · news · indicators"]
end
C --> E
E -->|get_memories()| M[(SQLite: role_memory.db)]
M -->|Top-K memories| E
E -->|memory_prompt injected into system prompt| LLM[LLMService (OpenRouter)]
%% ===== 🤖 Multi-Agent Workflow =====
subgraph Agents["🤖 Multi-Agent Workflow"]
C --> R[ReflectionService.record_analysis]
R --> RR[(SQLite: reflection_records.db)]
W[ReflectionWorker (optional)] --> RR
W -->|auto-verify + learn| M
A2[POST /api/analysis/reflect] -->|manual learn| M
subgraph P1["📈 Phase 1 · Analysis (Parallel)"]
E1["🔍 MarketAnalyst<br/><i>Technical</i>"]
E2["📑 FundamentalAnalyst<br/><i>Fundamentals</i>"]
E3["📰 NewsAnalyst<br/><i>News & Events</i>"]
E4["💭 SentimentAnalyst<br/><i>Market Mood</i>"]
E5["⚠️ RiskAnalyst<br/><i>Risk Assessment</i>"]
end
subgraph P2["🎯 Phase 2 · Debate (Parallel)"]
F1["🐂 BullResearcher<br/><i>Bullish Case</i>"]
F2["🐻 BearResearcher<br/><i>Bearish Case</i>"]
end
subgraph P3["💹 Phase 3 · Decision"]
G["🎰 TraderAgent<br/><i>Final Verdict → BUY / SELL / HOLD</i>"]
end
end
%% ===== 🧠 Memory Layer =====
subgraph Memory["🧠 Local SQLite Memory (data/memory/)"]
M1[("market_analyst")]
M2[("fundamental")]
M3[("news_analyst")]
M4[("sentiment")]
M5[("risk_analyst")]
M6[("bull_researcher")]
M7[("bear_researcher")]
M8[("trader_agent")]
end
%% ===== 🔄 Reflection Loop =====
subgraph Reflect["🔄 Reflection Loop (Optional)"]
R[ReflectionService]
RR[("reflection_records.db")]
W["⏰ ReflectionWorker"]
end
%% ===== Main Flow =====
A --> B --> C --> D
D --> P1 --> P2 --> P3
%% ===== Memory Read/Write =====
E1 <-.-> M1
E2 <-.-> M2
E3 <-.-> M3
E4 <-.-> M4
E5 <-.-> M5
F1 <-.-> M6
F2 <-.-> M7
G <-.-> M8
%% ===== Reflection Flow =====
C --> R --> RR
W --> RR
W -.->|"verify + learn"| M8
A2 -.->|"manual review"| M8
```
**Retrieval ranking (simplified)**:
+68 -45
View File
@@ -126,57 +126,80 @@ QuantDinger 的多智能体不是“每次从零开始”。它内置了一个**
#### 逻辑图(从请求到记忆闭环)
```mermaid
flowchart TD
A[POST /api/analysis/multi] --> B[AnalysisService]
B --> C[AgentCoordinator]
flowchart TB
%% ===== 🌐 入口层 =====
subgraph Entry["🌐 API 入口"]
A["📡 POST /api/analysis/multi"]
A2["🔄 POST /api/analysis/reflect"]
end
C --> D[构建上下文: price/kline/news/indicators]
%% ===== ⚙️ 服务编排层 =====
subgraph Service["⚙️ 服务编排"]
B[AnalysisService]
C[AgentCoordinator]
D["📊 构建上下文<br/>price · kline · news · indicators"]
end
subgraph Agents[多智能体并行/串行工作流]
E1[MarketAnalyst]
E2[FundamentalAnalyst]
E3[NewsAnalyst]
E4[SentimentAnalyst]
E5[RiskAnalyst]
F1[BullResearcher]
F2[BearResearcher]
G[TraderAgent]
end
%% ===== 🤖 多智能体工作流 =====
subgraph Agents["🤖 多智能体工作流"]
C -->|Phase 1 并行| E1
C -->|Phase 1 并行| E2
C -->|Phase 1 并行| E3
C -->|Phase 1 并行| E4
C -->|Phase 1 并行| E5
C -->|Phase 2 并行| F1
C -->|Phase 2 并行| F2
C -->|Phase 3| G
subgraph P1["📈 Phase 1 · 多维分析(并行)"]
E1["🔍 MarketAnalyst<br/><i>技术面分析</i>"]
E2["📑 FundamentalAnalyst<br/><i>基本面分析</i>"]
E3["📰 NewsAnalyst<br/><i>新闻舆情</i>"]
E4["💭 SentimentAnalyst<br/><i>市场情绪</i>"]
E5["⚠️ RiskAnalyst<br/><i>风险评估</i>"]
end
subgraph MemDB[本地 SQLite 记忆库(按角色拆分)]
M1[(data/memory/market_analyst_memory.db)]
M2[(data/memory/fundamental_analyst_memory.db)]
M3[(data/memory/news_analyst_memory.db)]
M4[(data/memory/sentiment_analyst_memory.db)]
M5[(data/memory/risk_analyst_memory.db)]
M6[(data/memory/bull_researcher_memory.db)]
M7[(data/memory/bear_researcher_memory.db)]
M8[(data/memory/trader_agent_memory.db)]
end
subgraph P2["🎯 Phase 2 · 多空博弈(并行)"]
F1["🐂 BullResearcher<br/><i>看多论据</i>"]
F2["🐻 BearResearcher<br/><i>看空论据</i>"]
end
E1 <-->|get_memories / add_memory| M1
E2 <-->|get_memories / add_memory| M2
E3 <-->|get_memories / add_memory| M3
E4 <-->|get_memories / add_memory| M4
E5 <-->|get_memories / add_memory| M5
F1 <-->|get_memories / add_memory| M6
F2 <-->|get_memories / add_memory| M7
G <-->|get_memories / add_memory| M8
subgraph P3["💹 Phase 3 · 交易决策"]
G["🎰 TraderAgent<br/><i>综合研判 → BUY / SELL / HOLD</i>"]
end
C --> R[ReflectionService.record_analysis]
R --> RR[(data/memory/reflection_records.db)]
W[ReflectionWorker(可选,定时)] --> RR
W -->|到期验证 + 写回经验| M8
A2[POST /api/analysis/reflect(手动复盘)] -->|reflect_and_learn| M8
end
%% ===== 🧠 记忆层 =====
subgraph Memory["🧠 本地记忆库 SQLitedata/memory/"]
M1[("market_analyst")]
M2[("fundamental")]
M3[("news_analyst")]
M4[("sentiment")]
M5[("risk_analyst")]
M6[("bull_researcher")]
M7[("bear_researcher")]
M8[("trader_agent")]
end
%% ===== 🔄 反思闭环 =====
subgraph Reflect["🔄 反思闭环(可选)"]
R[ReflectionService]
RR[("reflection_records.db")]
W["⏰ ReflectionWorker"]
end
%% ===== 主流程 =====
A --> B --> C --> D
D --> P1 --> P2 --> P3
%% ===== 记忆读写 =====
E1 <-.-> M1
E2 <-.-> M2
E3 <-.-> M3
E4 <-.-> M4
E5 <-.-> M5
F1 <-.-> M6
F2 <-.-> M7
G <-.-> M8
%% ===== 反思流程 =====
C --> R --> RR
W --> RR
W -.->|"验证 + 学习"| M8
A2 -.->|"手动复盘"| M8
```
#### 1) 记忆是如何“注入提示词”的?
+72 -14
View File
@@ -126,22 +126,80 @@ QuantDinger のエージェントは毎回「ゼロから」ではありませ
#### フロー図(リクエスト → 記憶閉ループ)
```mermaid
flowchart TD
A[POST /api/analysis/multi] --> B[AnalysisService]
B --> C[AgentCoordinator]
C --> D[コンテキスト構築: price/kline/news/indicators]
flowchart TB
%% ===== 🌐 入口層 =====
subgraph Entry["🌐 API エントリー"]
A["📡 POST /api/analysis/multi"]
A2["🔄 POST /api/analysis/reflect"]
end
subgraph Agents[Agents]
E[Analysts + Researchers + Trader]
end
%% ===== ⚙️ サービス層 =====
subgraph Service["⚙️ サービス編成"]
B[AnalysisService]
C[AgentCoordinator]
D["📊 コンテキスト構築<br/>price · kline · news · indicators"]
end
C --> E
E -->|get_memories / add_memory| M[(SQLite: data/memory/*_memory.db)]
C --> R[ReflectionService.record_analysis]
R --> RR[(SQLite: data/memory/reflection_records.db)]
W[ReflectionWorker(任意)] --> RR
W -->|期限到来を検証し学習| M
A2[POST /api/analysis/reflect] -->|手動で学習| M
%% ===== 🤖 マルチエージェントワークフロー =====
subgraph Agents["🤖 マルチエージェントワークフロー"]
subgraph P1["📈 Phase 1 · 多次元分析(並列)"]
E1["🔍 MarketAnalyst<br/><i>テクニカル</i>"]
E2["📑 FundamentalAnalyst<br/><i>ファンダメンタル</i>"]
E3["📰 NewsAnalyst<br/><i>ニュース</i>"]
E4["💭 SentimentAnalyst<br/><i>センチメント</i>"]
E5["⚠️ RiskAnalyst<br/><i>リスク評価</i>"]
end
subgraph P2["🎯 Phase 2 · 強気弱気論争(並列)"]
F1["🐂 BullResearcher<br/><i>強気の論点</i>"]
F2["🐻 BearResearcher<br/><i>弱気の論点</i>"]
end
subgraph P3["💹 Phase 3 · 取引判断"]
G["🎰 TraderAgent<br/><i>総合判定 → BUY / SELL / HOLD</i>"]
end
end
%% ===== 🧠 記憶層 =====
subgraph Memory["🧠 ローカル SQLite 記憶庫(data/memory/"]
M1[("market_analyst")]
M2[("fundamental")]
M3[("news_analyst")]
M4[("sentiment")]
M5[("risk_analyst")]
M6[("bull_researcher")]
M7[("bear_researcher")]
M8[("trader_agent")]
end
%% ===== 🔄 反省ループ =====
subgraph Reflect["🔄 反省ループ(オプション)"]
R[ReflectionService]
RR[("reflection_records.db")]
W["⏰ ReflectionWorker"]
end
%% ===== メインフロー =====
A --> B --> C --> D
D --> P1 --> P2 --> P3
%% ===== 記憶読み書き =====
E1 <-.-> M1
E2 <-.-> M2
E3 <-.-> M3
E4 <-.-> M4
E5 <-.-> M5
F1 <-.-> M6
F2 <-.-> M7
G <-.-> M8
%% ===== 反省フロー =====
C --> R --> RR
W --> RR
W -.->|"検証 + 学習"| M8
A2 -.->|"手動復習"| M8
```
#### 検索ランキング(簡略)
+72 -14
View File
@@ -126,22 +126,80 @@ QuantDinger의 에이전트는 매번 “처음부터” 시작하지 않습니
#### 흐름도(요청 → 메모리 폐루프)
```mermaid
flowchart TD
A[POST /api/analysis/multi] --> B[AnalysisService]
B --> C[AgentCoordinator]
C --> D[컨텍스트 구성: price/kline/news/indicators]
flowchart TB
%% ===== 🌐 진입 레이어 =====
subgraph Entry["🌐 API 진입점"]
A["📡 POST /api/analysis/multi"]
A2["🔄 POST /api/analysis/reflect"]
end
subgraph Agents[Agents]
E[Analysts + Researchers + Trader]
end
%% ===== ⚙️ 서비스 레이어 =====
subgraph Service["⚙️ 서비스 오케스트레이션"]
B[AnalysisService]
C[AgentCoordinator]
D["📊 컨텍스트 구성<br/>price · kline · news · indicators"]
end
C --> E
E -->|get_memories / add_memory| M[(SQLite: data/memory/*_memory.db)]
C --> R[ReflectionService.record_analysis]
R --> RR[(SQLite: data/memory/reflection_records.db)]
W[ReflectionWorker(옵션)] --> RR
W -->|만기 검증 + 학습 반영| M
A2[POST /api/analysis/reflect] -->|수동 학습| M
%% ===== 🤖 멀티에이전트 워크플로우 =====
subgraph Agents["🤖 멀티에이전트 워크플로우"]
subgraph P1["📈 Phase 1 · 다차원 분석(병렬)"]
E1["🔍 MarketAnalyst<br/><i>기술적 분석</i>"]
E2["📑 FundamentalAnalyst<br/><i>펀더멘털</i>"]
E3["📰 NewsAnalyst<br/><i>뉴스</i>"]
E4["💭 SentimentAnalyst<br/><i>심리</i>"]
E5["⚠️ RiskAnalyst<br/><i>리스크 평가</i>"]
end
subgraph P2["🎯 Phase 2 · 강세/약세 논쟁(병렬)"]
F1["🐂 BullResearcher<br/><i>강세 논거</i>"]
F2["🐻 BearResearcher<br/><i>약세 논거</i>"]
end
subgraph P3["💹 Phase 3 · 거래 결정"]
G["🎰 TraderAgent<br/><i>종합 판단 → BUY / SELL / HOLD</i>"]
end
end
%% ===== 🧠 메모리 레이어 =====
subgraph Memory["🧠 로컬 SQLite 메모리(data/memory/"]
M1[("market_analyst")]
M2[("fundamental")]
M3[("news_analyst")]
M4[("sentiment")]
M5[("risk_analyst")]
M6[("bull_researcher")]
M7[("bear_researcher")]
M8[("trader_agent")]
end
%% ===== 🔄 리플렉션 루프 =====
subgraph Reflect["🔄 리플렉션 루프(옵션)"]
R[ReflectionService]
RR[("reflection_records.db")]
W["⏰ ReflectionWorker"]
end
%% ===== 메인 흐름 =====
A --> B --> C --> D
D --> P1 --> P2 --> P3
%% ===== 메모리 읽기/쓰기 =====
E1 <-.-> M1
E2 <-.-> M2
E3 <-.-> M3
E4 <-.-> M4
E5 <-.-> M5
F1 <-.-> M6
F2 <-.-> M7
G <-.-> M8
%% ===== 리플렉션 흐름 =====
C --> R --> RR
W --> RR
W -.->|"검증 + 학습"| M8
A2 -.->|"수동 회고"| M8
```
#### 검색 랭킹(간략)
+68 -38
View File
@@ -126,50 +126,80 @@ QuantDinger 的多智能體不是「每次從零開始」。後端內建**本地
#### 邏輯圖(從請求到記憶閉環)
```mermaid
flowchart TD
A[POST /api/analysis/multi] --> B[AnalysisService]
B --> C[AgentCoordinator]
flowchart TB
%% ===== 🌐 入口層 =====
subgraph Entry["🌐 API 入口"]
A["📡 POST /api/analysis/multi"]
A2["🔄 POST /api/analysis/reflect"]
end
C --> D[建構上下文: price/kline/news/indicators]
%% ===== ⚙️ 服務編排層 =====
subgraph Service["⚙️ 服務編排"]
B[AnalysisService]
C[AgentCoordinator]
D["📊 建構上下文<br/>price · kline · news · indicators"]
end
subgraph Agents[多智能體並行/串行工作流]
E1[MarketAnalyst]
E2[FundamentalAnalyst]
E3[NewsAnalyst]
E4[SentimentAnalyst]
E5[RiskAnalyst]
F1[BullResearcher]
F2[BearResearcher]
G[TraderAgent]
end
%% ===== 🤖 多智能體工作流 =====
subgraph Agents["🤖 多智能體工作流"]
C -->|Phase 1 並行| E1
C -->|Phase 1 並行| E2
C -->|Phase 1 並行| E3
C -->|Phase 1 並行| E4
C -->|Phase 1 並行| E5
C -->|Phase 2 並行| F1
C -->|Phase 2 並行| F2
C -->|Phase 3| G
subgraph P1["📈 Phase 1 · 多維分析(並行)"]
E1["🔍 MarketAnalyst<br/><i>技術面分析</i>"]
E2["📑 FundamentalAnalyst<br/><i>基本面分析</i>"]
E3["📰 NewsAnalyst<br/><i>新聞輿情</i>"]
E4["💭 SentimentAnalyst<br/><i>市場情緒</i>"]
E5["⚠️ RiskAnalyst<br/><i>風險評估</i>"]
end
subgraph MemDB[本地 SQLite 記憶庫(按角色拆分)]
M1[(data/memory/*_memory.db)]
end
subgraph P2["🎯 Phase 2 · 多空博弈(並行)"]
F1["🐂 BullResearcher<br/><i>看多論據</i>"]
F2["🐻 BearResearcher<br/><i>看空論據</i>"]
end
E1 <-->|get_memories / add_memory| M1
E2 <-->|get_memories / add_memory| M1
E3 <-->|get_memories / add_memory| M1
E4 <-->|get_memories / add_memory| M1
E5 <-->|get_memories / add_memory| M1
F1 <-->|get_memories / add_memory| M1
F2 <-->|get_memories / add_memory| M1
G <-->|get_memories / add_memory| M1
subgraph P3["💹 Phase 3 · 交易決策"]
G["🎰 TraderAgent<br/><i>綜合研判 → BUY / SELL / HOLD</i>"]
end
C --> R[ReflectionService.record_analysis]
R --> RR[(data/memory/reflection_records.db)]
W[ReflectionWorker(可選,定時)] --> RR
W -->|到期驗證 + 寫回經驗| M1
A2[POST /api/analysis/reflect(手動復盤)] -->|reflect_and_learn| M1
end
%% ===== 🧠 記憶層 =====
subgraph Memory["🧠 本地記憶庫 SQLitedata/memory/"]
M1[("market_analyst")]
M2[("fundamental")]
M3[("news_analyst")]
M4[("sentiment")]
M5[("risk_analyst")]
M6[("bull_researcher")]
M7[("bear_researcher")]
M8[("trader_agent")]
end
%% ===== 🔄 反思閉環 =====
subgraph Reflect["🔄 反思閉環(可選)"]
R[ReflectionService]
RR[("reflection_records.db")]
W["⏰ ReflectionWorker"]
end
%% ===== 主流程 =====
A --> B --> C --> D
D --> P1 --> P2 --> P3
%% ===== 記憶讀寫 =====
E1 <-.-> M1
E2 <-.-> M2
E3 <-.-> M3
E4 <-.-> M4
E5 <-.-> M5
F1 <-.-> M6
F2 <-.-> M7
G <-.-> M8
%% ===== 反思流程 =====
C --> R --> RR
W --> RR
W -.->|"驗證 + 學習"| M8
A2 -.->|"手動復盤"| M8
```
#### 檢索排序(簡化)