diff --git a/go/adk/pkg/models/base.go b/go/adk/pkg/models/base.go index 3a659ffa9..ea0c3ecb1 100644 --- a/go/adk/pkg/models/base.go +++ b/go/adk/pkg/models/base.go @@ -150,9 +150,23 @@ func extractFunctionResponseContent(resp any) string { if c, ok := m["content"].([]any); ok && len(c) > 0 { var parts []string for _, item := range c { - if itemMap, ok := item.(map[string]any); ok { - if t, ok := itemMap["text"].(string); ok { - parts = append(parts, t) + itemMap, ok := item.(map[string]any) + if !ok { + continue + } + if t, ok := itemMap["text"].(string); ok { + parts = append(parts, t) + continue + } + // "resource" content (e.g. GitHub MCP's get_file_contents) carries + // its payload nested under resource.text rather than a top-level + // text key; without this the caller only ever sees the sibling + // placeholder text item. + if itemMap["type"] == "resource" { + if resource, ok := itemMap["resource"].(map[string]any); ok { + if t, ok := resource["text"].(string); ok { + parts = append(parts, t) + } } } } diff --git a/go/adk/pkg/models/base_test.go b/go/adk/pkg/models/base_test.go index 69a574eae..b7652214e 100644 --- a/go/adk/pkg/models/base_test.go +++ b/go/adk/pkg/models/base_test.go @@ -64,3 +64,52 @@ func TestMergeSystemInstructionFromConfig(t *testing.T) { }) } } + +func TestExtractFunctionResponseContent(t *testing.T) { + tests := []struct { + name string + resp any + want string + }{ + { + name: "plain string response", + resp: "hello", + want: "hello", + }, + { + name: "content array with top-level text items", + resp: map[string]any{ + "content": []any{ + map[string]any{"type": "text", "text": "line1"}, + map[string]any{"type": "text", "text": "line2"}, + }, + }, + want: "line1\nline2", + }, + { + name: "resource content nested under resource.text (GitHub MCP get_file_contents)", + resp: map[string]any{ + "content": []any{ + map[string]any{"type": "text", "text": "successfully downloaded text file (SHA: abc123)"}, + map[string]any{ + "type": "resource", + "resource": map[string]any{ + "uri": "repo://owner/repo/contents/path.yaml", + "text": "p, role:foo-developer, applications, get, *, allow", + }, + }, + }, + }, + want: "successfully downloaded text file (SHA: abc123)\np, role:foo-developer, applications, get, *, allow", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := extractFunctionResponseContent(tt.resp) + if got != tt.want { + t.Errorf("extractFunctionResponseContent() = %q, want %q", got, tt.want) + } + }) + } +}