Repository navigation
feat: return full tool results and parsed load_artifact content (re-applies #27) - #34
Merged
Merged
Conversation
…pplies #27) #29's squash put the 2.x result formats back before 2.1.0, so #27 never shipped. Re-apply #27's diff on top of main, keeping the typed stubs, catalog return types and MCP result envelope from #28/#29. - Drop the 50,000-byte large-result threshold and its `{"tool_result_artifact", "note"}` substitute: the code always gets the real tool result, which is still saved as an artifact - Save tool results with the same JSON-safe conversion as the RPC reply (`_json.json_safe`), so a saved result reloads as the value the code got - `load_artifact` returns parsed JSON, a `str` for other text, or `{"mime_type", "bytes"}` for binary, instead of `{"kind", "data", "mime_type"}`; text is encoded and decoded with the mime type's charset, defaulting to UTF-8 - `RemoteBackend` refuses a frame over `max_message_size` before sending it, so an oversized tool reply reaches the code as an error instead of closing the sandbox connection - Remove `DEFAULT_LARGE_RESULT_THRESHOLD` and the `large_result_threshold` parameter of `ToolResultArtifactTool` and `wrap_tool_result_as_artifact` - Drop the `ToolResultArtifact` pointer #29 added to wrapped tools' stub and catalog return types, and the description's large-result sentence - Restore #27's tests and update the README and docstrings Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013TYQ7F1kLDzPsAwBRC5KV1
benclarkeio
commented
Nov 16, 2026
benclarkeio
left a comment
Contributor
Author
There was a problem hiding this comment.
Found two P2 regressions that should be addressed before merging:
- Parsed artifact JSON containing
isError: trueis treated as a failed MCP call, preventing the code from reading valid artifact contents. - Rejecting an oversized
RunFrameafter staging the workspace leaves the remote protocol out of sync and loses the turn on the next block.
Both reproductions pass on base commit c97dca8517e262756cd6c6f35e1f43031c8430e2 and fail on PR commit 7cd5c128790719b1c72f21991e0b9ca3bdc83a91.
Validation: lint, formatting, and type checks pass. The existing non-Docker suite reports 253 passed and three timeout-test failures; all three failures also reproduce on the base commit. The three Docker-marked tests were excluded.
- Run the MCP failure check only for `McpTool`, as the REST check already does for `RestApiTool`; `load_artifact` now returns parsed JSON, so a saved failed MCP result (or any JSON with `isError: true`) raised `McpToolError` when reloaded - Raise `RuntimeError` for a frame over `max_message_size`, so a block whose `RunFrame` is refused discards its turn instead of leaving the sandbox waiting for it after the workspace archive was sent - Use an `McpTool` in the MCP failure tests and check that other tools returning the same shape are left alone Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013TYQ7CXLVCru82aWPycMKN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes #27's behaviour the default again, for release as 2.2.0. #27 gave the code full tool results and parsed artifact content. #29 held it back on purpose for 2.1.0: its last commit, "fix: preserve Code Mode 2.x result contracts", put the 2.x formats back so 2.1.0 could ship as a minor release. So 2.1.0 and
mainstill swap any tool result over 50 KB for a pointer, andload_artifactstill returns raw JSON text that the model then parses by hand.The changes only affect what the agent's code sees. The agent's tools are loaded on every call, so no existing code relies on the old formats.
This replaces #32 and #33.
What changes
Tool results: the code always gets the real result. Results are still saved as artifacts so later turns can reload them. The 50,000-byte threshold and its
{"tool_result_artifact", "note"}pointer are gone, and so are the| ToolResultArtifactstub return type and the pointer sentence in the tool description._json.json_safe), so a dataclass or Pydantic result reloads as the value the code received.load_artifactreturns the content itself:application/json,*+json): the parsed valuestr{"mime_type": str, "bytes": <base64 str>}Text is encoded and decoded with the mime type's
charset, with UTF-8 as the default. JSON that fails to parse comes back as astr.MCP failures: only an
McpToolresult withisError: trueraisesToolError, the same way only aRestApiToolresult can raiseHTTPStatusError. Other tools that return that shape, such asload_artifactreading a saved failed MCP result, return it as data.Remote sandbox:
RemoteBackendrefuses a frame overmax_message_sizebefore sending it. An oversized tool reply reaches the code as an error, and the sandbox stays connected. An oversized code block fails the call, and the next block gets a fresh sandbox.API:
DEFAULT_LARGE_RESULT_THRESHOLDis removed, along with thelarge_result_thresholdparameter ofToolResultArtifactToolandwrap_tool_result_as_artifact. agent-run uses none of these.The README, docstrings and tests now describe the new behaviour.
What's kept from #28 and #29
TypedDictreturn types in the catalog, escaped docstrings, the names-tier hint to read a function's stub, and the tool description's sentence on what is saved and how to load it.structuredContenttyped from the tool'soutputSchema.How #27 was re-applied
I applied
git diff dcb15ab ed4626dtomainwith a 3-way merge and resolved the rest by hand._artifact_tools.pyandruntime/remote.pymatched4626d.tool_result_artifacts.pyis feat!: return full tool results and artifact content to the code #27's version, without thestructured_resultimport, which feat: show return types in the catalog and point the names tier at stubs #29 removed.tool.py,tools/stubs.pyandREADME.md, the parts of feat: show return types in the catalog and point the names tier at stubs #29 that mention the pointer are removed.Sandbox, release and agent-run
ToolResultFrameandPROTOCOL_VERSIONare unchanged, and nothing undersandbox-wheel/changes.__about__.pyfiles together. On release,release-please.ymlpublishes bothadk-code-modeandadk-code-mode-sandbox, then the base image. Merging this PR only opens the 2.2.0 release PR; merging that release PR publishes to PyPI.adk-code-mode==2.2.0inpyproject.toml, in bothdependenciesand the dev group'sadk-code-mode[docker], then runuv lock. No code changes are needed. The sandbox image picks upadk-code-mode-sandbox==2.2.0fromuv.lock.Tests
load_artifactfor each mime type andcharset, andsave_artifact→load_artifactround-tripsmax_message_sizewithout sending itMcpTool, and a non-MCP tool returning anisError: trueresult is checked to come back unchanged.make cipasses locally:ruff,mypyandpytest(257 passed). The 3 Docker-marked tests didn't run because no Docker daemon was available.Generated by Claude Code