✨ feat(agent): 重构 Agent 分层并修复普通聊天助手消息未写入 Redis 的问题 🔧 按职责重构 backend/agent 目录为 route/chat/quicknote 三层结构 🔄 将随口记链路拆分为 graph/nodes/tool/state/prompt,其中 graph 仅负责连线 🏃 新增 quicknote runner(方法引用)来收口节点依赖,提升代码可读性 🔀 将控制码分流逻辑抽离到 agent/route,服务层改为薄封装调用 📚 更新相关 README 与测试引用路径,保持原业务逻辑不变 🐛 修复普通聊天链路遗漏 assistant 写入 Redis 的问题(确保 MySQL 和 Redis 的口径一致)
54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
package quicknote
|
||
|
||
import (
|
||
"context"
|
||
|
||
"github.com/cloudwego/eino/components/tool"
|
||
)
|
||
|
||
// quickNoteRunner 是“单次图运行”的请求级依赖容器。
|
||
// 设计目标:
|
||
// 1) 把节点运行所需依赖(input/tool/emit)就近收口;
|
||
// 2) 让 graph.go 只保留“节点连线”和“方法引用”,提升可读性;
|
||
// 3) 避免在 graph.go 里重复出现内联闭包和参数透传。
|
||
type quickNoteRunner struct {
|
||
input QuickNoteGraphRunInput
|
||
createTaskTool tool.InvokableTool
|
||
emitStage func(stage, detail string)
|
||
}
|
||
|
||
func newQuickNoteRunner(input QuickNoteGraphRunInput, createTaskTool tool.InvokableTool, emitStage func(stage, detail string)) *quickNoteRunner {
|
||
return &quickNoteRunner{
|
||
input: input,
|
||
createTaskTool: createTaskTool,
|
||
emitStage: emitStage,
|
||
}
|
||
}
|
||
|
||
func (r *quickNoteRunner) intentNode(ctx context.Context, st *QuickNoteState) (*QuickNoteState, error) {
|
||
return runQuickNoteIntentNode(ctx, st, r.input, r.emitStage)
|
||
}
|
||
|
||
func (r *quickNoteRunner) priorityNode(ctx context.Context, st *QuickNoteState) (*QuickNoteState, error) {
|
||
return runQuickNotePriorityNode(ctx, st, r.input, r.emitStage)
|
||
}
|
||
|
||
func (r *quickNoteRunner) persistNode(ctx context.Context, st *QuickNoteState) (*QuickNoteState, error) {
|
||
return runQuickNotePersistNodeInternal(ctx, st, r.createTaskTool, r.input, r.emitStage)
|
||
}
|
||
|
||
func (r *quickNoteRunner) nextAfterIntent(ctx context.Context, st *QuickNoteState) (string, error) {
|
||
_ = ctx
|
||
return selectQuickNoteNextAfterIntent(st), nil
|
||
}
|
||
|
||
func (r *quickNoteRunner) nextAfterPersist(ctx context.Context, st *QuickNoteState) (string, error) {
|
||
_ = ctx
|
||
return selectQuickNoteNextAfterPersist(st), nil
|
||
}
|
||
|
||
func (r *quickNoteRunner) exitNode(ctx context.Context, st *QuickNoteState) (*QuickNoteState, error) {
|
||
_ = ctx
|
||
return st, nil
|
||
}
|