Version: 0.7.6.dev.260325
后端: - ♻️ 将 `taskquery` 模块迁移至 `agent2`,并完成与 `agent2` 业务链路及整体结构的正式接入 前端: - 🧱 已完成基础框架搭建,并完成了登录、注册、主页等页面并对接了对应接口;但整体功能实现仍在完善中
This commit is contained in:
@@ -12,24 +12,22 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// QuickNoteGraphName 是“随口记”图编排的稳定标识。
|
||||
// 保留这个名字的目的:
|
||||
// 1. 让 compile 后的 graph 名称在日志、调试、可视化工具里有固定口径;
|
||||
// 2. 后续如果接入更多技能图,可以统一按技能名识别。
|
||||
// QuickNoteGraphName 是随口记图编排的稳定标识。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 仅用于 graph 编译和链路标识,方便日志与排障统一定位。
|
||||
// 2. 不参与意图判断,也不承载任务写库的业务语义。
|
||||
QuickNoteGraphName = "quick_note"
|
||||
)
|
||||
|
||||
// RunQuickNoteGraph 执行“随口记”图编排。
|
||||
// RunQuickNoteGraph 负责执行“随口记 -> 判断 -> 提取 -> 落库 -> 收口”的整条图链路。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 这里只负责 graph 连线与运行时装配,不负责节点内部业务细节;
|
||||
// 2. graph 层只挂 node 层对外暴露的方法,不再维护额外 runner 适配层;
|
||||
// 3. 工具注册、时间基准补齐、compile 参数收口都在这里统一完成。
|
||||
// 1. 负责输入兜底、工具装配、节点注册与 graph 运行。
|
||||
// 2. 不负责每个节点的具体业务决策,节点内部逻辑由 node 层实现。
|
||||
// 3. 返回的 state 表示整条链路的最终状态,供上层继续拼接响应或写日志。
|
||||
func RunQuickNoteGraph(ctx context.Context, input agentnode.QuickNoteGraphRunInput) (*agentmodel.QuickNoteState, error) {
|
||||
// 1. 启动前先做硬校验。
|
||||
// 1.1 model 为空时无法调模型,直接失败;
|
||||
// 1.2 state 为空时图无法承载共享上下文,也必须直接拦截;
|
||||
// 1.3 tool deps 不完整时,后续 persist 节点必然失败,因此这里提前收口。
|
||||
// 1. 先校验最基础依赖,避免图已经启动后才发现模型或状态为空。
|
||||
if input.Model == nil {
|
||||
return nil, errors.New("quick note graph: model is nil")
|
||||
}
|
||||
@@ -40,9 +38,7 @@ func RunQuickNoteGraph(ctx context.Context, input agentnode.QuickNoteGraphRunInp
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 2. 统一补齐本次请求的时间基准。
|
||||
// 2.1 RequestNow 只在整条 quicknote 链路入口确定一次,避免同一次请求里相对时间口径漂移;
|
||||
// 2.2 RequestNowText 是 prompt 注入用文本,缺失时也在这里统一补齐。
|
||||
// 2. 补齐当前请求时间,保证后续提示词、时间解析和落库字段都基于同一时刻。
|
||||
if input.State.RequestNow.IsZero() {
|
||||
input.State.RequestNow = agentshared.NowToMinute()
|
||||
}
|
||||
@@ -50,9 +46,7 @@ func RunQuickNoteGraph(ctx context.Context, input agentnode.QuickNoteGraphRunInp
|
||||
input.State.RequestNowText = agentshared.FormatMinute(input.State.RequestNow)
|
||||
}
|
||||
|
||||
// 3. 构建工具包并提取“创建任务”工具。
|
||||
// 3.1 graph 层只关心“拿到一个可执行工具”,不关心工具内部如何注册;
|
||||
// 3.2 失败时直接返回,避免把半残依赖继续交给 node 层。
|
||||
// 3. 图运行前统一准备工具与节点容器,避免节点内部重复做依赖解析。
|
||||
toolBundle, err := agentnode.BuildQuickNoteToolBundle(ctx, input.Deps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -62,18 +56,13 @@ func RunQuickNoteGraph(ctx context.Context, input agentnode.QuickNoteGraphRunInp
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 4. 在 node 层创建节点容器。
|
||||
// 4.1 这一步就是“请求级依赖注入”的唯一收口点;
|
||||
// 4.2 graph 后续只认 `nodes.Intent / nodes.Priority / nodes.Persist` 这些方法,不再额外造 runner。
|
||||
nodes, err := agentnode.NewQuickNoteNodes(input, createTaskTool)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 5. 创建状态图容器,输入输出统一都是 *QuickNoteState。
|
||||
// 4. 主链路保持“意图识别 -> 优先级评估 -> 持久化 -> 退出”,中间通过 branch 决定是否提前结束或重试写库。
|
||||
graph := compose.NewGraph[*agentmodel.QuickNoteState, *agentmodel.QuickNoteState]()
|
||||
|
||||
// 6. 注册节点。
|
||||
if err = graph.AddLambdaNode(agentnode.QuickNoteGraphNodeIntent, compose.InvokableLambda(nodes.Intent)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -87,14 +76,9 @@ func RunQuickNoteGraph(ctx context.Context, input agentnode.QuickNoteGraphRunInp
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 7. 所有请求统一从 intent 节点开始。
|
||||
if err = graph.AddEdge(compose.START, agentnode.QuickNoteGraphNodeIntent); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 8. intent 后分支:
|
||||
// 8.1 命中随口记且时间合法 -> priority;
|
||||
// 8.2 非随口记,或时间校验失败 -> exit。
|
||||
if err = graph.AddBranch(agentnode.QuickNoteGraphNodeIntent, compose.NewGraphBranch(
|
||||
nodes.NextAfterIntent,
|
||||
map[string]bool{
|
||||
@@ -104,22 +88,12 @@ func RunQuickNoteGraph(ctx context.Context, input agentnode.QuickNoteGraphRunInp
|
||||
)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 9. 显式 exit 节点仍然保留。
|
||||
// 这样后续若要统一加日志、埋点、收尾逻辑,不需要再改 branch 结构。
|
||||
if err = graph.AddEdge(agentnode.QuickNoteGraphNodeExit, compose.END); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 10. priority 后固定进入 persist。
|
||||
if err = graph.AddEdge(agentnode.QuickNoteGraphNodeRank, agentnode.QuickNoteGraphNodePersist); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 11. persist 后分支:
|
||||
// 11.1 已成功写入 -> END;
|
||||
// 11.2 仍可重试 -> 回到 persist;
|
||||
// 11.3 重试耗尽 -> END,由 state 中的失败文案兜底。
|
||||
if err = graph.AddBranch(agentnode.QuickNoteGraphNodePersist, compose.NewGraphBranch(
|
||||
nodes.NextAfterPersist,
|
||||
map[string]bool{
|
||||
@@ -130,13 +104,12 @@ func RunQuickNoteGraph(ctx context.Context, input agentnode.QuickNoteGraphRunInp
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 12. 为 persist 重试预留运行步数余量,避免异常状态把图跑成死循环。
|
||||
// 5. persist 节点允许有限次重试,因此最大步数要覆盖首次执行与重试回路。
|
||||
maxSteps := input.State.MaxToolRetry + 10
|
||||
if maxSteps < 12 {
|
||||
maxSteps = 12
|
||||
}
|
||||
|
||||
// 13. 编译并执行图。
|
||||
runnable, err := graph.Compile(ctx,
|
||||
compose.WithGraphName(QuickNoteGraphName),
|
||||
compose.WithMaxRunSteps(maxSteps),
|
||||
|
||||
Reference in New Issue
Block a user