Repository navigation
feat: opt in to full tool results and parsed load_artifact (re-applies #27) - #33
Closed
benclarkeio wants to merge 1 commit into
Closed
benclarkeio wants to merge 1 commit into
benclarkeio wants to merge 1 commit into
Conversation
#27 returned full tool results and parsed artifact content, but #29's squash put the 2.x formats back before 2.1.0. Bring #27's behaviour back as opt-ins on `ExecuteCodeTool`, keeping the 2.x formats as the defaults. - `large_result_threshold` (default 50,000 bytes): `None` never swaps a tool result for the `tool_result_artifact` pointer, so the code always gets the full result, which is still saved as an artifact. Stubs, the catalog and the tool description only mention the pointer when it can occur. `ToolResultArtifactTool` and `wrap_tool_result_as_artifact` also accept `None` - `load_artifact_format` (default `"envelope"`): `"parsed"` injects a `load_artifact` that returns parsed JSON, a `str` for other text, or `{"mime_type", "bytes"}` for binary, with a docstring to match - Save tool results with the same JSON-safe conversion as the reply to the code, so a saved result reloads as the value the code received - Encode and decode artifact text with the mime type's charset (UTF-8 by default), and ignore mime parameters when deciding what is text - `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 - Export `DEFAULT_LARGE_RESULT_THRESHOLD` and `LoadArtifactFormat` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013TYQ7F1kLDzPsAwBRC5KV1
Contributor
Author
|
Superseded by #34. Generated by Claude Code |
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
#27 returned full tool results and parsed artifact content to the code, but #29's squash put the 2.x formats back, so 2.1.0 and
maindon't have it. This PR brings #27's behaviour back as opt-in options onExecuteCodeTool. It keeps the 2.x formats as the defaults, so it is a minor release (2.2.0). It replaces #32, which shipped the same change as a major release.Defaults stay 2.x
{"tool_result_artifact", "note"}pointer. Wrapped tools' stubs and catalog entries still return<type> | ToolResultArtifact, and the tool description still says large results return a pointer.load_artifactstill returns{"kind", "data", "mime_type"}.New options
Both are
ExecuteCodeToolarguments:large_result_threshold: int | None = 50_000. Results over this many bytes become the pointer.Nonenever substitutes: the code always gets the full result, which is still saved as an artifact. WithNone, stubs and the catalog drop| ToolResultArtifact, and the tool description drops the pointer sentence.ToolResultArtifactToolandwrap_tool_result_as_artifactalso acceptNone, and the wrapper exposeslarge_result_threshold.load_artifact_format: Literal["envelope", "parsed"] = "envelope"."parsed"injects aload_artifactthat returns the content itself: parsed JSON, astrfor other text, or{"mime_type": str, "bytes": <base64 str>}for binary. JSON that fails to parse comes back as astr. Its docstring in the stubs and catalog describes that format, so the model is told what it gets. Any other value raisesValueError.DEFAULT_LARGE_RESULT_THRESHOLDandLoadArtifactFormatare now exported fromadk_code_mode.Fixes from #27, on by default
These fix bugs without changing any return format:
_json.json_safe). A dataclass or Pydantic result used to be saved as itsstr(); now it reloads as the value the code received.charset, with UTF-8 as the default. Mime parameters no longer change what counts as text, soapplication/json; charset=utf-8loads askind="text"instead ofkind="bytes".RemoteBackendrefuses a frame overmax_message_sizebefore sending it. An oversized tool reply now reaches the code as an error instead of closing the sandbox connection.What agent-run passes to opt in
In
create_execute_code_toolinsrc/a2anet_agent_run/agent_factory.py:Also pin
adk-code-mode==2.2.0inpyproject.toml(bothdependenciesand the dev group'sadk-code-mode[docker]), then runuv lock. agent-run uses nothing else this PR changes.cloudbuild.sandbox.yamlreads the sandbox version fromuv.lock, so the sandbox image moves toadk-code-mode-sandbox==2.2.0with it.Sandbox and release
ToolResultFrameandPROTOCOL_VERSIONare unchanged, and nothing undersandbox-wheel/changes. The size check runs on the host. The sandbox's WebSocket limit is 256 MiB, the same as the defaultmax_message_size.__about__.pyfiles together.release-please.ymlpublishes bothadk-code-modeandadk-code-mode-sandboxto PyPI, then the base image. Merging this PR only opens the 2.2.0 release PR; merging that release PR publishes.Tests
main's 2.x tests still pass unchanged: the envelope, the pointer and its type, and the description. New tests check that the default threshold elides a result over 50,000 bytes, and that a large result reaches sandbox code as a pointer end to end.load_artifactfor each mime type, including a non-UTF-8charset, andsave_artifact→load_artifactround-trips.large_result_threshold=Nonereturns a 200 KB result in full and still saves it.ExecuteCodeToolpasses the threshold to the wrappers and injects the parsedload_artifact.max_message_sizewithout sending it.make cipasses locally:ruff,mypyandpytest(278 passed). The 3 Docker-marked tests didn't run because no Docker daemon was available.Generated by Claude Code