diff --git a/go/adk/pkg/models/base.go b/go/adk/pkg/models/base.go index 3a659ffa9..eeba6f091 100644 --- a/go/adk/pkg/models/base.go +++ b/go/adk/pkg/models/base.go @@ -112,7 +112,7 @@ func (t *headerTransport) RoundTrip(req *http.Request) (*http.Response, error) { // parametersJsonSchemaToMap converts a genai.FunctionDeclaration.ParametersJsonSchema value // to map[string]any. ParametersJsonSchema is typed as `any` and can hold: -// - map[string]any (rare — only if someone constructs it manually) +// - map[string]any (rare, only if someone constructs it manually) // - *jsonschema.Schema (from functiontool.New and MCP tools via mcptoolset) // - any other JSON-serializable type func parametersJsonSchemaToMap(v any) map[string]any { @@ -150,8 +150,18 @@ 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 { + itemMap, ok := item.(map[string]any) + if !ok { + continue + } + if t, ok := itemMap["text"].(string); ok { + parts = append(parts, t) + continue + } + // Embedded resource content (type: "resource") carries its text + // under resource.text instead of a top-level text field. + 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/openai_adk_test.go b/go/adk/pkg/models/openai_adk_test.go index dde5959be..a3e9cb525 100644 --- a/go/adk/pkg/models/openai_adk_test.go +++ b/go/adk/pkg/models/openai_adk_test.go @@ -39,6 +39,17 @@ func TestFunctionResponseContentString(t *testing.T) { }, "result": "from result", }, "from content"}, + {"map with content[0].resource.text", map[string]any{ + "content": []any{ + map[string]any{"type": "resource", "resource": map[string]any{"text": "embedded resource text"}}, + }, + }, "embedded resource text"}, + {"map with text and resource blocks joined", map[string]any{ + "content": []any{ + map[string]any{"text": "summary line"}, + map[string]any{"type": "resource", "resource": map[string]any{"text": "full file content"}}, + }, + }, "summary line\nfull file content"}, {"map empty content slice falls back to JSON", map[string]any{ "content": []any{}, }, `{"content":[]}`},