Files
smartmate/backend/agent/scheduleplan/runner.go
LoveLosita 059b25872a Version: 0.7.1.dev.260320
🧠 agent智能编排:删除了落库相关逻辑。再次重申:agent智能编排旨在为用户预览排程结果,实际的落库由用户决定,并通过按钮触发常规接口进行落库。目前仅保留 ReAct 精排循环链路(待改进)。
📄 修改了 ReAct 智能精排决策文档相关内容。
🔄 undo:当前 agent 智能排程逻辑待改进。
2026-03-20 19:40:11 +08:00

106 lines
3.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package scheduleplan
import (
"context"
"github.com/cloudwego/eino-ext/components/model/ark"
"github.com/cloudwego/eino/schema"
)
// schedulePlanRunner 是"单次图运行"的请求级依赖容器。
//
// 设计目标:
// 1) 把节点运行所需依赖model/deps/emit/extra/history就近收口
// 2) 让 graph.go 只保留"节点连线"和"方法引用",提升可读性;
// 3) 避免在 graph.go 里重复出现内联闭包和参数透传。
type schedulePlanRunner struct {
chatModel *ark.ChatModel
deps SchedulePlanToolDeps
emitStage func(stage, detail string)
userMessage string
extra map[string]any
chatHistory []*schema.Message
// ── ReAct 精排所需 ──
outChan chan<- string // SSE 流式输出通道,用于推送 reasoning_content
modelName string // 模型名称,用于构造 OpenAI 兼容 chunk
}
// newSchedulePlanRunner 构造请求级 runner。
// 生命周期仅限一次 graph invoke不做跨请求复用。
func newSchedulePlanRunner(
chatModel *ark.ChatModel,
deps SchedulePlanToolDeps,
emitStage func(stage, detail string),
userMessage string,
extra map[string]any,
chatHistory []*schema.Message,
outChan chan<- string,
modelName string,
) *schedulePlanRunner {
return &schedulePlanRunner{
chatModel: chatModel,
deps: deps,
emitStage: emitStage,
userMessage: userMessage,
extra: extra,
chatHistory: chatHistory,
outChan: outChan,
modelName: modelName,
}
}
// ── 节点方法引用适配层 ──
func (r *schedulePlanRunner) planNode(ctx context.Context, st *SchedulePlanState) (*SchedulePlanState, error) {
return runPlanNode(ctx, st, r.chatModel, r.userMessage, r.extra, r.chatHistory, r.emitStage)
}
func (r *schedulePlanRunner) previewNode(ctx context.Context, st *SchedulePlanState) (*SchedulePlanState, error) {
return runPreviewNode(ctx, st, r.deps, r.emitStage)
}
// ── ReAct 精排节点适配层 ──
func (r *schedulePlanRunner) hybridBuildNode(ctx context.Context, st *SchedulePlanState) (*SchedulePlanState, error) {
return runHybridBuildNode(ctx, st, r.deps, r.emitStage)
}
func (r *schedulePlanRunner) reactRefineNode(ctx context.Context, st *SchedulePlanState) (*SchedulePlanState, error) {
return runReactRefineNode(ctx, st, r.chatModel, r.outChan, r.modelName, r.emitStage)
}
func (r *schedulePlanRunner) returnPreviewNode(ctx context.Context, st *SchedulePlanState) (*SchedulePlanState, error) {
return runReturnPreviewNode(ctx, st, r.emitStage)
}
func (r *schedulePlanRunner) exitNode(_ context.Context, st *SchedulePlanState) (*SchedulePlanState, error) {
// exit 节点不做任何业务逻辑,仅把当前状态原样透传到 END。
return st, nil
}
// ── 分支决策适配层 ──
func (r *schedulePlanRunner) nextAfterPlan(_ context.Context, st *SchedulePlanState) (string, error) {
return selectNextAfterPlan(st), nil
}
// nextAfterPreview 根据 preview 结果决定下一步。
//
// 分支规则:
// 1) preview 失败(无候选方案)-> exit
// 2) 否则 -> hybridBuild进入 ReAct 精排路径)
func (r *schedulePlanRunner) nextAfterPreview(_ context.Context, st *SchedulePlanState) (string, error) {
if st == nil || len(st.CandidatePlans) == 0 {
return schedulePlanGraphNodeExit, nil
}
return schedulePlanGraphNodeHybridBuild, nil
}
// nextAfterHybridBuild 根据 hybridBuild 结果决定下一步。
func (r *schedulePlanRunner) nextAfterHybridBuild(_ context.Context, st *SchedulePlanState) (string, error) {
if st == nil || len(st.HybridEntries) == 0 {
return schedulePlanGraphNodeExit, nil
}
return schedulePlanGraphNodeReactRefine, nil
}