Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions go/adk/pkg/models/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down
49 changes: 49 additions & 0 deletions go/adk/pkg/models/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}