Files
smartmate/backend/services/agent/model/chat_contract.go
Losita d7184b776b Version: 0.9.75.dev.260505
后端:
1.收口阶段 6 agent 结构迁移,将 newAgent 内核与 agentsvc 编排层迁入 services/agent
- 切换 Agent 启动装配与 HTTP handler 直连 agent sv,移除旧 service agent bridge
- 补齐 Agent 对 memory、task、task-class、schedule 的 RPC 适配与契约字段
- 扩展 schedule、task、task-class RPC/contract 支撑 Agent 查询、写入与 provider 切流
- 更新迁移文档、README 与相关注释,明确 agent 当前切流点和剩余 memory 迁移面
2026-05-05 16:00:57 +08:00

87 lines
2.8 KiB
Go
Raw Permalink 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 model
import (
"fmt"
"strings"
)
// ChatRoute 表示 Chat 节点路由决策的目标路径。
type ChatRoute string
const (
// ChatRouteDirectReply 简单任务Chat 节点直接输出回复,不再调用下游节点。
ChatRouteDirectReply ChatRoute = "direct_reply"
// ChatRouteExecute 中等任务:需要用工具处理,直接进 Execute ReAct 循环。
ChatRouteExecute ChatRoute = "execute"
// ChatRouteDeepAnswer 复杂问答需要深度思考但不需工具Chat 节点原地开 thinking 回答。
ChatRouteDeepAnswer ChatRoute = "deep_answer"
// ChatRoutePlan 复杂规划:需要先制定计划,进 Plan 节点。
ChatRoutePlan ChatRoute = "plan"
// ChatRouteQuickTask 快捷任务:随口记增查改删等轻量任务操作,走 QuickTask 轻量路径。
ChatRouteQuickTask ChatRoute = "quick_task"
)
// ChatRoutingDecision 是 Chat 节点单次路由决策的结构化输出。
//
// 职责边界:
// 1. Route 决定后续处理路径;
// 2. NeedsRoughBuild 仅在 route=execute 且满足粗排条件时为 true
// 3. NeedsRefineAfterRoughBuild 仅在 needs_rough_build=true 时有效;
// 4. AllowReorder 表示是否允许打乱 suggested 任务顺序,仅用户明确授权时应为 true
// 5. Thinking 表示下游 Execute 节点是否应开启深度思考;
// 6. Raw 保留控制码原文,供日志排查;
// 7. 用户可见内容speak由流式输出自然产出不由本结构承载。
type ChatRoutingDecision struct {
Route ChatRoute
NeedsRoughBuild bool
NeedsRefineAfterRoughBuild bool
AllowReorder bool
Thinking bool
Raw string
}
// Normalize 统一清洗路由决策中的字符串字段。
func (d *ChatRoutingDecision) Normalize() {
if d == nil {
return
}
d.Route = ChatRoute(strings.TrimSpace(string(d.Route)))
d.Raw = strings.TrimSpace(d.Raw)
}
// Validate 校验路由决策的最小合法性。
func (d *ChatRoutingDecision) Validate() error {
if d == nil {
return fmt.Errorf("chat routing decision 不能为空")
}
d.Normalize()
switch d.Route {
case ChatRouteDirectReply, ChatRouteExecute, ChatRouteDeepAnswer, ChatRoutePlan, ChatRouteQuickTask:
// ok
case "":
return fmt.Errorf("chat routing decision.route 不能为空")
default:
return fmt.Errorf("未知 route: %s", d.Route)
}
// 非 execute 路由不应携带粗排和粗排后微调标记,统一归一化为 false。
if d.Route != ChatRouteExecute {
d.NeedsRoughBuild = false
d.NeedsRefineAfterRoughBuild = false
d.AllowReorder = false
d.Thinking = false
}
// 只有 needs_rough_build=true 时needs_refine_after_rough_build 才有语义。
if !d.NeedsRoughBuild {
d.NeedsRefineAfterRoughBuild = false
}
return nil
}