feat(agent): 云端 Agent 运行时 - 完善 Pi 桥接、上下文压力与临时故障重试

This commit is contained in:
ddcat666 committed 2026-10-04 02:20:30 +08:00
1 parent 0030f4da9b
commit 76ca0fd247
32 files changed
+1663 -1485

No files matched your search

+33 -5
View File
@@ -399,7 +399,7 @@ func TestParseAgentToolPayloadSupportsResponses(t *testing.T) {
"output": []interface{}{
map[string]interface{}{"type": "reasoning", "summary": []interface{}{map[string]interface{}{"type": "summary_text", "text": "先读取画布,再决定操作"}}},
map[string]interface{}{"type": "message", "content": []interface{}{map[string]interface{}{"type": "output_text", "text": "开始操作"}}},
map[string]interface{}{"type": "function_call", "call_id": "call-2", "name": "canvas_apply_ops", "arguments": `{"ops":[]}`},
map[string]interface{}{"type": "function_call", "id": "fc-2", "call_id": "call-2", "name": "canvas_apply_ops", "arguments": `{"ops":[]}`},
},
}, "responses")
if err != nil {
@@ -417,7 +417,7 @@ func TestParseAgentToolPayloadSupportsResponses(t *testing.T) {
}
call, _ := calls[0].(map[string]interface{})
function, _ := call["function"].(map[string]interface{})
if call["id"] != "call-2" || function["name"] != "canvas_apply_ops" || function["arguments"] != `{"ops":[]}` {
if call["id"] != "call-2" || call["item_id"] != "fc-2" || function["name"] != "canvas_apply_ops" || function["arguments"] != `{"ops":[]}` {
t.Fatalf("tool call = %#v", call)
}
}
@@ -491,7 +491,8 @@ func TestCanonicalAgentBodiesPreserveAssistantToolCalls(t *testing.T) {
Messages: []map[string]any{
{"role": "user", "content": "读取画布"},
{"role": "assistant", "content": "我先查看当前内容。", "tool_calls": []cloudAgentCall{{
ID: "call-5",
ID: "call-5",
ItemID: "fc-5",
Function: struct {
Name string `json:"name"`
Arguments string `json:"arguments"`
@@ -532,13 +533,16 @@ func TestCanonicalAgentBodiesPreserveAssistantToolCalls(t *testing.T) {
t.Fatalf("claude assistant lost tool use: %#v", claudeAssistant)
}
responses := canonicalAgentResponsesBody(&request)
responses, err := canonicalAgentResponsesBody(&request)
if err != nil {
t.Fatal(err)
}
responseInput, _ := responses["input"].([]interface{})
if len(responseInput) != 4 {
t.Fatalf("responses input = %#v", responseInput)
}
functionCall, _ := responseInput[2].(map[string]interface{})
if functionCall["type"] != "function_call" || functionCall["name"] != "canvas_get_state" {
if functionCall["type"] != "function_call" || functionCall["name"] != "canvas_get_state" || functionCall["id"] != "fc-5" || functionCall["item_reference"] != "fc-5" {
t.Fatalf("responses function call = %#v", functionCall)
}
}
@@ -782,6 +786,30 @@ data: [DONE]
}
}
func TestStreamingAgentParserPreservesResponsesFunctionCallItemID(t *testing.T) {
parser := newStreamingAgentParser("responses", nil)
parser.consume("text/event-stream", []byte(`event: response.output_item.added
data: {"type":"response.output_item.added","output_index":0,"item":{"type":"function_call","id":"fc-stream","call_id":"call-stream","name":"canvas_get_state","arguments":""}}
event: response.function_call_arguments.delta
data: {"type":"response.function_call_arguments.delta","item_id":"fc-stream","delta":"{\"nodeId\":"}
event: response.function_call_arguments.done
data: {"type":"response.function_call_arguments.done","item_id":"fc-stream","arguments":"{\"nodeId\":\"n1\"}"}
`))
parser.flush()
result, err := parser.result()
if err != nil {
t.Fatalf("streamingAgentParser.result() error = %v", err)
}
calls, _ := result["toolCalls"].([]interface{})
call, _ := calls[0].(map[string]interface{})
if call["id"] != "call-stream" || call["item_id"] != "fc-stream" {
t.Fatalf("responses tool call identity = %#v", call)
}
}
func TestStreamingAgentParserSeparatesResponsesReasoningFromVisibleText(t *testing.T) {
var deltas strings.Builder
parser := newStreamingAgentParser("responses", func(delta string) {