fix(go-agent): preserve realtime stream deltas (#17791)

- Start the Agent model-stream collector before ReAct execution.
- Preserve all streamed reasoning/content deltas and drain the collector
on errors.
- Add coverage for delayed thinking streams and tool-call execution.
This commit is contained in:
Hz_
2026-08-04 15:43:15 +08:00
committed by GitHub
parent 64041e885f
commit f0bdd90aa2
5 changed files with 395 additions and 8 deletions

View File

@@ -91,6 +91,68 @@ func TestCodeExec_Info(t *testing.T) {
if !strings.Contains(info.Desc, "Python") {
t.Errorf("Desc = %q, want to mention Python", info.Desc)
}
params, err := info.ParamsOneOf.ToJSONSchema()
if err != nil {
t.Fatalf("Info schema: %v", err)
}
encoded, err := json.Marshal(params)
if err != nil {
t.Fatalf("marshal Info schema: %v", err)
}
var schema map[string]any
if err := json.Unmarshal(encoded, &schema); err != nil {
t.Fatalf("decode Info schema: %v", err)
}
properties, ok := schema["properties"].(map[string]any)
if !ok {
t.Fatalf("Info schema properties = %#v, want object", schema["properties"])
}
for _, name := range []string{"lang", "script"} {
if _, ok := properties[name]; !ok {
t.Errorf("Info schema missing %q", name)
}
}
for _, name := range []string{"language", "code", "arguments", "outputs"} {
if _, ok := properties[name]; ok {
t.Errorf("Info schema unexpectedly exposes node field %q", name)
}
}
required, ok := schema["required"].([]any)
if !ok {
t.Fatalf("Info schema required = %#v, want array", schema["required"])
}
requiredFields := make(map[string]bool, len(required))
for _, field := range required {
if name, ok := field.(string); ok {
requiredFields[name] = true
}
}
if !requiredFields["lang"] || !requiredFields["script"] {
t.Errorf("Info schema required = %#v, want lang and script", required)
}
langProp, ok := properties["lang"].(map[string]any)
if !ok {
t.Fatalf("lang property = %#v, want object", properties["lang"])
}
if typ, _ := langProp["type"].(string); typ != "string" {
t.Errorf("lang.type = %q, want string", typ)
}
enum, ok := langProp["enum"].([]any)
if !ok {
t.Fatalf("lang.enum = %#v, want array", langProp["enum"])
}
gotEnum := make([]string, len(enum))
for i, e := range enum {
s, ok := e.(string)
if !ok {
t.Fatalf("lang.enum[%d] = %#v, want string", i, e)
}
gotEnum[i] = s
}
if len(gotEnum) != 2 || gotEnum[0] != "python" || gotEnum[1] != "javascript" {
t.Errorf("lang.enum = %v, want [python javascript]", gotEnum)
}
}
// TestCodeExec_ResultExtractsArtifacts pins the artifact