Skip to content

fix(frameworks): serialize Google ADK AgentTool and zod v4 schemas - #170

Closed
ling-senpeng13 wants to merge 1 commit into
mainfrom
fix/adk-agent-tool-serialization
Closed

fix(frameworks): serialize Google ADK AgentTool and zod v4 schemas#170
ling-senpeng13 wants to merge 1 commit into
mainfrom
fix/adk-agent-tool-serialization

Conversation

@ling-senpeng13

@ling-senpeng13 ling-senpeng13 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Fixes Google ADK agent-as-tool usage — examples/agents/adk/21-agent-tool.ts hung forever.

1. Detect ADK AgentTool. ADK's public AgentToolConfig holds the child agent under a plain agent property. _tryExtractAgentTool only knew the OpenAI SDK markers (_is_agent_tool/_agent_instance), so ADK agent-tools serialized as workers with no callable — the server scheduled tasks no worker ever polled (deadlock). Detection is by the documented agent shape: class names are minified in the published bundle, and ADK's own isAgentTool() guard can't be imported by this framework-agnostic serializer.

2. Support zod v4 schemas. ADK tool parameters are zod v4 (ToolInputParameters, and @google/adk depends on zod ^4.2.1). v4 dropped _def.typeName (changelog), so _isZodSchema missed v4 schemas and tool parameters serialized as raw zod internals — the LLM saw parameterless tools and called them with no arguments. Added v4 detection (_zod marker) and a structural _zod.def → JSON Schema walker (the SDK's own zod is v3, so no existing converter can read a v4 instance).

Verified: example 21 now completes with tool-grounded results and zero tool errors; ADK examples 15–22 pass in parallel with the new paths active; 25/25 serializer tests, 94/94 frameworks suite.

Two gaps made the ADK agent-as-tool example hang forever and, once
unblocked, call tools with no arguments:

1. _tryExtractAgentTool only recognized OpenAI Agents SDK markers
   (_is_agent_tool / _agent_instance). Google ADK's AgentTool exposes a
   plain 'agent' property (constructor names are minified), so it
   degraded into a generic tool entry with no callable — the server
   scheduled a worker task no local worker ever polled. Detect the ADK
   shape and recursively serialize the child agent.

2. _isZodSchema only matched zod v3 (_def.typeName). ADK bundles zod
   v4, whose schemas carry _zod internals instead, so tool parameter
   schemas fell through to generic enumeration and serialized as
   mangled internals — the LLM saw parameterless tools and called them
   argless. Add v4 detection and a structural _zod.def -> JSON Schema
   walker (the SDK's own zod is v3, so no library can convert a v4
   instance cross-package).

Verified: examples/agents/adk/21-agent-tool.ts, previously deadlocked,
now completes with tool-grounded results and zero tool errors.
@ling-senpeng13
ling-senpeng13 deleted the fix/adk-agent-tool-serialization branch August 18, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant