refactor(llm): unify agent tool loop + built-in provider presets - #390
Open
ModerRAS wants to merge 30 commits into
Open
refactor(llm): unify agent tool loop + built-in provider presets#390ModerRAS wants to merge 30 commits into
ModerRAS wants to merge 30 commits into
Conversation
…Service (3 loops -> 1)
…ll provider/gateway/models)
…rotocol, iteration limit, resume)
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Contributor
PR Check ReportSummary
Test Results
Code Quality
Test Artifacts
LinksThis report is auto-generated by GitHub Actions |
ModerRAS
force-pushed
the
refactor/llm-transport-abstraction
branch
from
September 10, 2026 09:25
e18cd79 to
c16738d
Compare
…leton + ExecWithHistoryAsync interface
…query, stateless transports, v2 snapshots, pure-DTO worker path - LlmMessage/LlmToolCall/LlmToolSpec/LlmTurnRequest/LlmStreamEvent: single normalized model across history, loop, transports, and v2 snapshots - LlmHistoryQueryService.LoadAsync: one batched DB pipeline replacing 4 per-provider N+1 query loops - LlmHistoryProjector: unified rows->LlmMessage projection (grouping by bot/user flip, unified reply formatting) - 5 transports rebuilt stateless per turn (OpenAI chat/Anthropic messages/OpenAI responses/Gemini/Ollama); provider history serialization pairs deleted - LlmToolLoop owns normalized history; v2 continuation snapshots (NormalizedHistory) preserve native tool-call ids; resume is shared - LlmServiceProxy: pure-DTO path, SeedTaskDataAsync fake InMemory DB seeding deleted; vision resolved from task capabilities
…service-layer dissolution)
…ovider + LlmProviderRegistry
… paths from provider services
…der resolution onto LlmProviderRegistry
… architecture and ER diagrams
…start of Phase 4.5); OpenAI ExecWithHistoryAsync delegates to runner
…; all 5 providers now runner-dispatched
…Vision + registry GetCatalog/GetEmbeddings/GetVision (S7)
… ILlmModelCatalog capability (S8)
…ice + LlmCapabilityChecks + LlmChatRunner (S10)
…resume/exec paths route through LlmChatRunner
…dialect}ModelApi classes remain (S11)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
{"body": "## 目标\n\n把 LLM/Agent 模块整体重写为现代 agent 架构(pi 式分层):一套归一化消息模型贯穿全程 + 每方言一个无状态 transport + 唯一共享工具循环 + 纯 DTO 历史管线。总蓝图见
Docs/Agent_Architecture_Refactor_Plan.md。\n\n## 变更\n\n### 1. 共享 Agent 循环(不再按 provider 复制)\n-LlmToolLoop:唯一的工具循环——归一化LlmMessage历史、工具执行、迭代上限、续跑快照。原先 10 份for cycle < MaxToolCycles循环体(5 provider × 各变体)全部收敛。\n\n### 2. 归一化消息模型\n-LlmMessage(role/text/thinking/toolCalls/toolCallId/image/isToolError)+LlmToolCall/LlmToolSpec/LlmTurnRequest/LlmStreamEvent事件协议\n- 贯穿历史投影、循环状态、transport 请求、快照 v2\n\n### 3. 历史管线纯 DTO(消灭"五道工序")\n-LlmHistoryQueryService.LoadAsync:唯一的 DB 管线(1h 窗口/last-10、可见性过滤、批量用户/扩展查询),替代 4 份带 N+1 查询的GetChatHistory\n-LlmHistoryProjector:rows →LlmMessage统一投影(旧 4 份仅标点差异,已归一)\n- LLMAgent worker 不再造假库:SeedTaskDataAsync(向 InMemory EF 播种伪造行)删除,task.History纯 DTO 直达 transport;vision 从任务 capabilities 取\n\n### 4. 无状态 transports(5 个方言)\n- OpenAI Chat / Anthropic Messages / OpenAI Responses / Gemini / Ollama:每回合把归一化历史转 SDK 请求,流式回LlmStreamEvent\n- 各 provider 的历史序列化对、tool 转换、prompt caching、quirk 全部收编内部\n- Anthropic 保留「首轮 prepare + 后续增量追加」的旧 wire 语义(user 消息保持 string 类型)\n\n### 5. 快照 v2\n-LlmContinuationSnapshot.NormalizedHistory(归一化历史,保留 native tool_call id——旧 v1 会丢);resume 共享一份实现\n- 旧 v1 快照 24h TTL 自然过期,不迁移\n\n### 6. 内置 Provider 预设\n-LlmProviderCatalog11 家预置(Anthropic / OpenAI Chat/Responses / Gemini / MiniMax / Ollama / LM Studio / DeepSeek / Moonshot / OpenCode Zen / OpenCode Go)\n- 新指令预制渠道:选编号 → 填 API Key(OpenCode Go 需先填网关地址;本地服务发-跳过)→ 自动建渠道 + 默认 binding + 预置默认模型\n- OpenCode Zen 按既有规则走 catalog≠entitlement(不自动建模型行);数据库表结构零变更\n\n### 7. 文档\n-Docs/Agent_Architecture_Refactor_Plan.md:重写策略 + 数据迁移映射表 + 后续阶段(P5 单入口/Redis 精简、P6 worker 合并评估)\n-Docs/Bot_Commands_User_Guide.md:预制渠道指令\n\n## 验证\n- 全 solution 0 error;测试 LLM 282 + 核心 445 + Search 6 全过\n- 新增LlmToolLoopTests(文本/native 协议、v2 快照、resume 语义);OpenCode wire 协议测试全部保持通过(wire 兼容回归修复:HttpClient 生命周期、ChatClient 按回合模型名、Anthropic user 消息 string 语义)\n- CI:ubuntu ✅ windows ✅\n\n## 后续(独立 PR)\n- P5:单入口(GeneralLLMController 旧直连路径并入 AgentChat 队列)+ Redis 状态精简\n- P6:worker 进程合并评估(默认不动)\n\n## Phase 4.5 追加(provider 层彻底消除,本 PR 内)\n\n-LlmChatRunner(Singleton):native→XML 降级 dispatch、bot 名/prompt-caching 开关、meta 组装集中一份;消息路径/worker 路径/快照恢复路径全部经 runner\n-Transports/*每方言static Create工厂吸收全部 client 构造胶水(端点归一化、MiniMax 判断、Opencode headers、Ollama pull)\n-ProviderApi/{OpenAi,Anthropic,Responses,Gemini,Ollama}ModelApi:目录/向量/视觉/健康,实现ILlmModelCatalog/ILlmEmbeddings/ILlmVision\n-LlmProviderRegistry:GetTransport(binding.Protocol 优先)+GetCatalog/GetEmbeddings/GetVision\n- 删除:ILLMService、ILLMFactory、LLMFactory、ILlmProvider、5 个*Service类(4520 行 → 2984 行 ModelApi);净删 ~2600 行聊天胶水/legacy\n- 架构图与 ER 图见Docs/Agent_Architecture_Refactor_Plan.md第七节\n"}