Version: 0.8.7.dev.260402
后端: 1.Plan节点实现两阶段LLM调用:Phase1无thinking快速评估复杂度,复杂任务自动开启Phase2深度规划 2.Execute节点新增GoalCheck自省机制:LLM输出next_plan/done时必须附带对照done_when的完成验证,为空则追加修正重试 前端:无 仓库:无
This commit is contained in:
@@ -38,10 +38,11 @@ const (
|
||||
// 3. Reason 是给后端和日志看的简短解释,不直接等价于完成证明;
|
||||
// 4. ToolCall 只是“意图”,不代表工具已经真正执行成功。
|
||||
type ExecuteDecision struct {
|
||||
Speak string `json:"speak,omitempty"`
|
||||
Action ExecuteAction `json:"action"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
ToolCall *ToolCallIntent `json:"tool_call,omitempty"`
|
||||
Speak string `json:"speak,omitempty"`
|
||||
Action ExecuteAction `json:"action"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
GoalCheck string `json:"goal_check,omitempty"`
|
||||
ToolCall *ToolCallIntent `json:"tool_call,omitempty"`
|
||||
}
|
||||
|
||||
// Normalize 统一清洗 execute 决策中的字符串字段。
|
||||
@@ -52,6 +53,7 @@ func (d *ExecuteDecision) Normalize() {
|
||||
d.Speak = strings.TrimSpace(d.Speak)
|
||||
d.Action = ExecuteAction(strings.TrimSpace(string(d.Action)))
|
||||
d.Reason = strings.TrimSpace(d.Reason)
|
||||
d.GoalCheck = strings.TrimSpace(d.GoalCheck)
|
||||
if d.ToolCall != nil {
|
||||
d.ToolCall.Normalize()
|
||||
}
|
||||
|
||||
@@ -5,6 +5,20 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PlanComplexity 表示规划阶段评估的任务复杂度。
|
||||
type PlanComplexity string
|
||||
|
||||
const (
|
||||
// PlanComplexitySimple 表示简单明确的操作,步骤之间无复杂依赖。
|
||||
PlanComplexitySimple PlanComplexity = "simple"
|
||||
|
||||
// PlanComplexityModerate 表示多步操作,需要一定推理但不涉及深度分析。
|
||||
PlanComplexityModerate PlanComplexity = "moderate"
|
||||
|
||||
// PlanComplexityComplex 表示需要深度推理、多方案比较或复杂依赖关系的任务。
|
||||
PlanComplexityComplex PlanComplexity = "complex"
|
||||
)
|
||||
|
||||
// PlanAction 表示规划阶段单轮决策的动作类型。
|
||||
//
|
||||
// 设计原则:
|
||||
@@ -32,10 +46,12 @@ const (
|
||||
// 3. Reason 是给后端和日志看的简短解释;
|
||||
// 4. PlanSteps 只在 plan_done 时要求返回,表示本轮最终确认下来的完整自然语言计划。
|
||||
type PlanDecision struct {
|
||||
Speak string `json:"speak,omitempty"`
|
||||
Action PlanAction `json:"action"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
PlanSteps []PlanStep `json:"plan_steps,omitempty"`
|
||||
Speak string `json:"speak,omitempty"`
|
||||
Action PlanAction `json:"action"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
Complexity PlanComplexity `json:"complexity"`
|
||||
NeedThinking bool `json:"need_thinking"`
|
||||
PlanSteps []PlanStep `json:"plan_steps,omitempty"`
|
||||
}
|
||||
|
||||
// Normalize 统一清洗规划决策中的字符串字段。
|
||||
@@ -46,6 +62,7 @@ func (d *PlanDecision) Normalize() {
|
||||
d.Speak = strings.TrimSpace(d.Speak)
|
||||
d.Action = PlanAction(strings.TrimSpace(string(d.Action)))
|
||||
d.Reason = strings.TrimSpace(d.Reason)
|
||||
d.Complexity = PlanComplexity(strings.TrimSpace(string(d.Complexity)))
|
||||
for i := range d.PlanSteps {
|
||||
d.PlanSteps[i].Normalize()
|
||||
}
|
||||
@@ -67,6 +84,16 @@ func (d *PlanDecision) Validate() error {
|
||||
return fmt.Errorf("plan decision.action 不能为空")
|
||||
}
|
||||
|
||||
// 复杂度兜底:未填写时默认 moderate,不因此拒绝整个决策。
|
||||
switch d.Complexity {
|
||||
case PlanComplexitySimple, PlanComplexityModerate, PlanComplexityComplex:
|
||||
// ok
|
||||
case "":
|
||||
d.Complexity = PlanComplexityModerate
|
||||
default:
|
||||
return fmt.Errorf("未知 complexity: %s", d.Complexity)
|
||||
}
|
||||
|
||||
switch d.Action {
|
||||
case PlanActionContinue, PlanActionAskUser:
|
||||
if len(d.PlanSteps) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user