Skip to content

feat!: restore full tool results and parsed load_artifact (re-applies #27) - #32

Closed
benclarkeio wants to merge 1 commit into
mainfrom
feat/restore-full-tool-results
Closed

benclarkeio wants to merge 1 commit into
mainfrom
feat/restore-full-tool-results

Conversation

@benclarkeio

Copy link
Copy Markdown
Contributor

Summary

#27 (ed4626d) changed what tool calls and load_artifact give the code, but neither 2.1.0 nor main contains it. #29 (a238bfd) was squash-merged five hours after #27, and its last commit, "fix: preserve Code Mode 2.x result contracts", put back the 2.x formats so that 2.1.0 could ship as a minor release. #27's PR also told release-please to record it as a chore:, so the 2.1.0 changelog doesn't mention it. git diff ed4626d a238bfd shows the revert.

So production still swaps any tool result over 50 KB for a {"tool_result_artifact", "note"} pointer, and load_artifact still returns raw JSON text that the model then parses by hand.

This PR re-applies #27 on top of main as a breaking change, so release-please cuts 3.0.0.

What's restored

  • 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 pointer are gone.

    • Saved results use the same JSON-safe conversion as the RPC reply (_json.json_safe), so a dataclass or Pydantic result reloads as the value the code received.
  • load_artifact returns the content itself:

    • JSON (application/json, *+json): the parsed value
    • other text: a str
    • binary: {"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 a str.

  • Remote sandbox: RemoteBackend refuses a frame over max_message_size before sending it. An oversized tool reply reaches the code as an error, and the sandbox stays connected.

  • feat!: return full tool results and artifact content to the code #27's README text, docstrings and tests.

What's kept from #28 and #29

How the conflicts were resolved

I applied git diff dcb15ab ed4626d to main with a 3-way merge and resolved the rest by hand.

Breaking changes

  • load_artifact no longer returns {"kind", "data", "mime_type"}.
  • Tool results over 50,000 bytes are returned in full instead of as a tool_result_artifact pointer.
  • DEFAULT_LARGE_RESULT_THRESHOLD is removed, along with the large_result_threshold parameter of ToolResultArtifactTool and wrap_tool_result_as_artifact.
  • Wrapped tools' stub and catalog return types no longer include | ToolResultArtifact.

Sandbox and release

  • The sandbox needs no changes. ToolResultFrame and PROTOCOL_VERSION are unchanged, and nothing under sandbox-wheel/ changes. The size check runs on the host. The sandbox's WebSocket limit is 256 MiB, the same as the default RemoteBackend.max_message_size.
  • release-please bumps both __about__.py files together through extra-files. On release, release-please.yml builds and publishes both adk-code-mode and adk-code-mode-sandbox to PyPI, then the base image. Both will be 3.0.0.
  • Merging this PR only opens the 3.0.0 release PR. Merging that release PR publishes to PyPI.

What the agent-run pin bump needs

agent-run doesn't pass anything this PR removes. It never uses large_result_threshold, DEFAULT_LARGE_RESULT_THRESHOLD or wrap_tool_result_as_artifact, and doesn't read load_artifact's old shape. What it does use is unchanged: ExecuteCodeTool(tools=, backend=, timeout_seconds=, on_artifacts_saved=), RemoteBackend(url=, token=, connect_timeout=, start_attempts=, start_retry_delay_seconds=, start_retry_jitter_seconds=), and the TOOL_RESULT_* metadata keys.

  • Change adk-code-mode==2.1.0 to ==3.0.0 in pyproject.toml, in both dependencies and the dev group's adk-code-mode[docker], then run uv lock.
  • No code changes. cloudbuild.sandbox.yaml reads the sandbox version from uv.lock, so the sandbox image moves to adk-code-mode-sandbox==3.0.0 with it. Deploy the host and the sandbox together.
  • Expect the new behaviour: large tool results reach the code in full, and uploaded files loaded with load_artifact come back as {"mime_type", "bytes"}, a str or parsed JSON. Agent instructions kept outside the repo that tell the model to read ["data"] or json.loads a loaded artifact should be updated.

Tests

  • make ci passes locally: ruff, mypy and pytest (256 passed). The 3 Docker-marked tests didn't run because no Docker daemon was available.

Generated by Claude Code

…27)

#29's squash ended with a commit that put back the 2.x result formats, so
2.1.0 and main lost #27. 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
- 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

BREAKING CHANGE: `load_artifact` returns the content itself rather than
`{"kind", "data", "mime_type"}`. Large tool results are returned in full
instead of as a `tool_result_artifact` pointer. `DEFAULT_LARGE_RESULT_THRESHOLD`
and the `large_result_threshold` parameter of `ToolResultArtifactTool` and
`wrap_tool_result_as_artifact` are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013TYQ7F1kLDzPsAwBRC5KV1

Copy link
Copy Markdown
Contributor Author

Superseded by #33, which ships the same behaviour as opt-in options with the 2.x defaults kept, so it releases as 2.2.0 instead of 3.0.0. Please do not merge this PR; it can be closed.


Generated by Claude Code

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.

2 participants