Skip to content

fix(tools): preserve JSON fragments in AgentTool structured output - #8350

Open
xixi-box wants to merge 1 commit into
google:mainfrom
xixi-box:fix/agent-tool-structured-output
Open

xixi-box wants to merge 1 commit into
google:mainfrom
xixi-box:fix/agent-tool-structured-output

Conversation

@xixi-box

Copy link
Copy Markdown

Link to Issue or Description of Change

This is the Python follow-up to google/adk-go#2468. Thanks to baptmont for requesting the matching Python fix. #5481 provides context for keeping code output in plain-text replies.

Problem

AgentTool can pass executable code and execution output to the JSON validator. It also inserts newlines between text parts, which breaks a JSON token split across two parts.

Solution

For agents with an output schema, join non-thought text parts in order without a separator before validation. A reply with no non-whitespace answer text uses the existing empty-result or error-message convention. Schema-less replies still include code and execution output in their newline-separated text.

Testing Plan

  • pytest -q tests/unittests/tools/test_agent_tool.py tests/unittests/utils/test_schema_utils.py passed on Python 3.11, 3.12, 3.13, and 3.14 with 186 tests per version.
  • On the upstream base, five new structured cases failed and the schema-less case passed. The six cases all pass with the fix.
  • Ruff, isort, Pyink, codespell, and the repository's compliance checks passed. The repository's full tox matrix was started locally on Windows and is still running.

End-to-end reproduction

Run pytest -q tests/unittests/tools/test_agent_tool.py -k test_agent_tool_output_parts. A real parent runner calls AgentTool, which runs a nested LlmAgent using scripted model replies. The test checks the function response received by the parent and requires no model credentials.

Checklist

  • Read the contribution guide.
  • Reviewed the diff and added regression tests.
  • Verified the parent-to-child AgentTool path locally.

OpenAI Codex assisted with implementation, testing, and preparation of this pull request.

Join answer text without separators before schema validation. Treat whitespace-only structured replies as empty and preserve code output for schema-less callers.
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