feat(agent): 云端 Agent - 加固运行时并新增导演工具

This commit is contained in:
ddcat666 committed 2026-09-27 09:45:43 +08:00
1 parent 1080b22196
commit 1a4598e496
16 files changed
+815 -195

No files matched your search

@@ -52,6 +52,7 @@ func TestCloudAgentInheritedPlanReachesFirstModelRequest(t *testing.T) {
s, db, root := reliableAgentRoot(t)
run, state := agentInterjectionState(t, s, root.ID)
state.Plan = []cloudAgentPlanItem{{ID: "1", Title: "生成镜头2视频", Status: "doing"}}
state.ConfirmationRounds = 1
if err := cloudAgentSave(run, &state); err != nil {
t.Fatal(err)
}
@@ -87,6 +88,9 @@ func TestCloudAgentInheritedPlanReachesFirstModelRequest(t *testing.T) {
if len(childState.Plan) != 1 || childState.Plan[0].Title != "生成镜头2视频" {
t.Fatalf("运行态没有继承清单: %+v", childState.Plan)
}
if childState.ConfirmationRounds != 1 {
t.Fatalf("运行态没有继承确认轮次: %d", childState.ConfirmationRounds)
}
wired := cloudAgentCanonicalWithPlan(&childState)
if strings.Contains(wired.SystemPrompt, "生成镜头2视频") || strings.Contains(wired.SystemPrompt, "本轮待办清单") {
t.Fatalf("清单不得写进系统提示,否则会打爆前缀缓存: %s", wired.SystemPrompt)
@@ -118,6 +122,30 @@ func TestCloudAgentAskUserRequiresChoices(t *testing.T) {
}
}
func TestCloudAgentAskUserTracksConfirmationRoundsAndDefaults(t *testing.T) {
call := cloudAgentCall{ID: "ask-1"}
call.Function.Name = "ask_user"
call.Function.Arguments = `{"question":"选哪个方向?","options":[{"label":"A"},{"label":"B"}]}`
state := &cloudAgentRuntime{}
for round := 1; round <= cloudAgentMaxConfirmationRounds; round++ {
result, err := cloudAgentAskUser(call, state)
if err != nil {
t.Fatal(err)
}
body := result.(map[string]any)
if body["phase"] != "question" || body["round"] != round || body["maxRounds"] != cloudAgentMaxConfirmationRounds {
t.Fatalf("round %d payload = %+v", round, body)
}
}
result, err := cloudAgentAskUser(call, state)
if err != nil {
t.Fatal(err)
}
body := result.(map[string]any)
if body["phase"] != "defaulted" || body["defaulted"] != true || state.ConfirmationRounds != cloudAgentMaxConfirmationRounds {
t.Fatalf("exhausted ask_user payload/state = %+v / %+v", body, state)
}
}
func TestCloudAgentPlanNudgePrefersLatestUserInstruction(t *testing.T) {
state := &cloudAgentRuntime{
Canonical: canonicalAgentRequest{Messages: []map[string]any{{"role": "user", "content": "改成 16:9"}}},