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
16 changes: 13 additions & 3 deletions go/adk/pkg/models/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down
11 changes: 11 additions & 0 deletions go/adk/pkg/models/openai_adk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":[]}`},
Expand Down