Version: 0.9.1.dev.260406

后端:
  1.新建conv/schedule_persist.go:ScheduleState Diff 持久化,事务内逐变更写库,支持 place/move/unplace 三种操作(当前
  event source)
  2.新建conv/schedule_provider.go:ScheduleState 加载适配,从 DB 合并 existing events + pending task items
  3.新建dao/agent_state_store_adapter.go:Redis 状态快照存取适配,实现 AgentStateStore 接口
  4.新建service/agentsvc/agent_newagent.go:newAgent service 集成层,串联 LLM
  客户端、ScheduleProvider、SchedulePersistor 和 ChunkEmitter
  5.更新node/execute.go:接入 SchedulePersistor(写操作确认后持久化)、完善 confirm resume 路径(PendingConfirmTool
  恢复分支)、correction 机制增加连续失败计数上限
  6.更新api/agent.go + cmd/start.go:接入 newAgent service,完成 API 层路由注册
  7.新建node/execute_confirm_flow_test.go + llm_tool_orchestration_test.go:确认回路 7 个测试 + 端到端排课 5
  个测试全部通过
  8.新建newAgent/ARCHITECTURE.md + ROADMAP.md:全链路架构文档和缺口分析
  9.代码审查整理:提取 prompt/base.go(通用 buildStageMessages 等5个辅助)、tools/args.go(参数解析辅助);write_tools
  尾部辅助移入 write_helpers;修复 queryRangeSpecific sb.Reset() 逻辑缺陷和 Unplace guest Duration
  未恢复;ScheduleStateProvider/SchedulePersistor 归入 state_store.go;emitter 内部 Build*Text 函数降级为私有
前端:无
仓库:无
This commit is contained in:
Losita
2026-04-06 15:33:34 +08:00
parent bcee43b610
commit b1eb6bedf9
29 changed files with 2600 additions and 427 deletions

View File

@@ -32,18 +32,19 @@ func (r *AgentGraphRequest) Normalize() {
// AgentGraphDeps 描述 graph/node 层运行时真正依赖的可插拔能力。
//
// 设计目的:
// 1. 让 graph 不再只拿到裸状态”,而是能拿到上下文、模型和输出能力;
// 1. 让 graph 不再只拿到裸状态”,而是能拿到上下文、模型和输出能力;
// 2. Chat/Plan/Execute/Deliver 允许分别挂不同 client但也允许先复用同一个 client
// 3. ChunkEmitter 统一承接阶段提示、正文、工具事件、确认请求等 SSE 输出。
type AgentGraphDeps struct {
ChatClient *newagentllm.Client
PlanClient *newagentllm.Client
ExecuteClient *newagentllm.Client
DeliverClient *newagentllm.Client
ChunkEmitter *newagentstream.ChunkEmitter
StateStore AgentStateStore
ToolRegistry *newagenttools.ToolRegistry
ScheduleProvider ScheduleStateProvider // 按 DAO 注入Execute 节点按需加载 ScheduleState
ChatClient *newagentllm.Client
PlanClient *newagentllm.Client
ExecuteClient *newagentllm.Client
DeliverClient *newagentllm.Client
ChunkEmitter *newagentstream.ChunkEmitter
StateStore AgentStateStore
ToolRegistry *newagenttools.ToolRegistry
ScheduleProvider ScheduleStateProvider // 按 DAO 注入Execute 节点按需加载 ScheduleState
SchedulePersistor SchedulePersistor // 按 DAO 注入,用于写工具执行后持久化变更
}
// EnsureChunkEmitter 保证 graph 运行时始终有一个可用的 chunk 发射器。
@@ -131,19 +132,6 @@ type AgentGraphRunInput struct {
Deps AgentGraphDeps
}
// AgentGraphState 是 graph 内部真正流转的运行态容器。
//
// 职责边界:
// 1. 负责把“流程状态 + 对话上下文 + 请求输入 + 运行依赖”收口到同一个对象;
// 2. 负责给 graph 分支和 node 提供最小必要的兜底访问方法;
// 3. 不负责持久化,不负责真正业务执行。
// ScheduleStateProvider 定义加载 ScheduleState 的接口。
// 由 DAO 层或 Service 层实现,注入到 AgentGraphDeps 中。
// 使用接口而非具体 DAO 类型,避免 model → dao 的循环依赖。
type ScheduleStateProvider interface {
LoadScheduleState(ctx context.Context, userID int) (*newagenttools.ScheduleState, error)
}
// AgentGraphState 是 graph 内部真正流转的运行态容器。
//
// 职责边界:
@@ -151,11 +139,12 @@ type ScheduleStateProvider interface {
// 2. 负责给 graph 分支和 node 提供最小必要的兜底访问方法;
// 3. 不负责持久化,不负责真正业务执行。
type AgentGraphState struct {
RuntimeState *AgentRuntimeState
ConversationContext *ConversationContext
Request AgentGraphRequest
Deps AgentGraphDeps
ScheduleState *newagenttools.ScheduleState // 工具操作的内存数据源Execute 节点按需加载
RuntimeState *AgentRuntimeState
ConversationContext *ConversationContext
Request AgentGraphRequest
Deps AgentGraphDeps
ScheduleState *newagenttools.ScheduleState // 工具操作的内存数据源Execute 节点按需加载
OriginalScheduleState *newagenttools.ScheduleState // 首次加载时的原始快照,供 diff 用
}
// NewAgentGraphState 把入口参数整理成 graph 内部状态。
@@ -239,5 +228,7 @@ func (s *AgentGraphState) EnsureScheduleState(ctx context.Context) (*newagenttoo
return nil, err
}
s.ScheduleState = state
// 保存原始快照,供后续 diff 使用。
s.OriginalScheduleState = state.Clone()
return state, nil
}