Version: 0.9.47.dev.260427
后端: 1. execute 节点继续拆职责——超大 execute.go 下沉为 node/execute 子包,按决策流、动作路由、上下文锚点、工具执行、状态快照、工具展示与参数解析拆分;顶层 execute.go 收敛为桥接导出,降低单文件编排/业务/模型/工具逻辑混写 2. 节点公共能力继续沉到 shared——抽出 LLM 纠错回灌、完整上下文调试日志、thinking 开关、统一上下文压缩、可见 assistant 文本持久化等 node_* 公共件,减少 execute 独占实现并为其他节点复用铺路 3. speak 文本整理能力独立收口——新增 speak_text 辅助文件,补齐正文归一化的独立承载,继续收缩 execute 主文件体积 前端: 4. NewAgent 时间线接入 business_card 业务卡片协议——schedule_agent.ts 新增 task_query / task_record 卡片载荷类型与 business_card kind;AssistantPanel 增加业务卡片事件存储、时间线恢复、块渲染分支与 BusinessCardRenderer 接入,同时保留 interrupt / status / tool / reasoning 多块并存 5. 新增任务查询卡片与任务记录卡片组件,并补充 DesignDemo 设计预览页与路由,前端可先行验证 business_card 的视觉与交互落点 文档: 6. 新增 newagent business card 前后端对接说明,明确 timeline kind、payload 结构、卡片分类、前后端发射/渲染约束
This commit is contained in:
119
backend/newAgent/node/execute/action_text.go
Normal file
119
backend/newAgent/node/execute/action_text.go
Normal file
@@ -0,0 +1,119 @@
|
||||
package newagentexecute
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
newagentmodel "github.com/LoveLosita/smartflow/backend/newAgent/model"
|
||||
)
|
||||
|
||||
func resolveExecuteAskUserText(decision *newagentmodel.ExecuteDecision) string {
|
||||
if decision == nil {
|
||||
return "执行过程中遇到不确定的情况,需要向你确认。"
|
||||
}
|
||||
if strings.TrimSpace(decision.Speak) != "" {
|
||||
return strings.TrimSpace(decision.Speak)
|
||||
}
|
||||
if strings.TrimSpace(decision.Reason) != "" {
|
||||
return strings.TrimSpace(decision.Reason)
|
||||
}
|
||||
return "执行过程中遇到不确定的情况,需要向你确认。"
|
||||
}
|
||||
|
||||
func pickExecuteVisibleSpeak(
|
||||
streamed string,
|
||||
afterText string,
|
||||
beforeText string,
|
||||
decision *newagentmodel.ExecuteDecision,
|
||||
) string {
|
||||
if text := strings.TrimSpace(streamed); text != "" {
|
||||
return text
|
||||
}
|
||||
if text := strings.TrimSpace(afterText); text != "" {
|
||||
return text
|
||||
}
|
||||
if text := strings.TrimSpace(beforeText); text != "" {
|
||||
return text
|
||||
}
|
||||
return buildExecuteSpeakWithFallback(decision)
|
||||
}
|
||||
|
||||
func buildExecuteSpeakWithFallback(decision *newagentmodel.ExecuteDecision) string {
|
||||
if decision == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
speak := strings.TrimSpace(decision.Speak)
|
||||
if speak != "" {
|
||||
return speak
|
||||
}
|
||||
|
||||
switch decision.Action {
|
||||
case newagentmodel.ExecuteActionContinue,
|
||||
newagentmodel.ExecuteActionAskUser,
|
||||
newagentmodel.ExecuteActionConfirm:
|
||||
if reason := strings.TrimSpace(decision.Reason); reason != "" {
|
||||
return reason
|
||||
}
|
||||
switch decision.Action {
|
||||
case newagentmodel.ExecuteActionAskUser:
|
||||
return "我还缺少一条关键信息,想先向你确认。"
|
||||
case newagentmodel.ExecuteActionConfirm:
|
||||
return "我先整理好这一步操作,等待你的确认。"
|
||||
default:
|
||||
return "我先继续这一步处理,马上给你结果。"
|
||||
}
|
||||
default:
|
||||
return speak
|
||||
}
|
||||
}
|
||||
|
||||
func handleExecuteActionConfirm(
|
||||
decision *newagentmodel.ExecuteDecision,
|
||||
runtimeState *newagentmodel.AgentRuntimeState,
|
||||
flowState *newagentmodel.CommonState,
|
||||
) error {
|
||||
toolCall := decision.ToolCall
|
||||
|
||||
argsJSON := ""
|
||||
if toolCall.Arguments != nil {
|
||||
if raw, err := json.Marshal(toolCall.Arguments); err == nil {
|
||||
argsJSON = string(raw)
|
||||
}
|
||||
}
|
||||
|
||||
runtimeState.PendingConfirmTool = &newagentmodel.PendingToolCallSnapshot{
|
||||
ToolName: toolCall.Name,
|
||||
ArgsJSON: argsJSON,
|
||||
Summary: strings.TrimSpace(decision.Speak),
|
||||
}
|
||||
|
||||
flowState.Phase = newagentmodel.PhaseWaitingConfirm
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleExecuteActionAbort(
|
||||
decision *newagentmodel.ExecuteDecision,
|
||||
flowState *newagentmodel.CommonState,
|
||||
) error {
|
||||
if decision == nil || decision.Abort == nil {
|
||||
return fmt.Errorf("abort 动作缺少终止信息")
|
||||
}
|
||||
if flowState == nil {
|
||||
return fmt.Errorf("abort 动作缺少流程状态")
|
||||
}
|
||||
|
||||
internalReason := strings.TrimSpace(decision.Abort.InternalReason)
|
||||
if internalReason == "" {
|
||||
internalReason = strings.TrimSpace(decision.Reason)
|
||||
}
|
||||
|
||||
flowState.Abort(
|
||||
executeStageName,
|
||||
decision.Abort.Code,
|
||||
decision.Abort.UserMessage,
|
||||
internalReason,
|
||||
)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user