feat(strands-py-wasm): add DecoratedTool for host-side Python tools#2412
Merged
Conversation
Introduce DecoratedTool and the @tool decorator as the way to register Python callbacks that the agent can invoke. Replaces the prior Tool / PydanticTool pair with a single user-facing type. On the guest side, fix mapContentBlock so the toJSON outer wrappers from SDK content blocks are stripped to match the WIT inner-record shape, and add mapToolResultBlock / mapToolResultContent helpers for tool result events. Pin pgrayy-wasmtime to the v46.0.7 release wheel.
pgrayy
commented
Jun 1, 2026
pgrayy
commented
Jun 1, 2026
mehtarac
reviewed
Jun 1, 2026
Rename _coerce_tool_result to _normalize_tool_result and fix the docstring reference to render as @tool.
mehtarac
approved these changes
Jun 1, 2026
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.
Description
Introduce
DecoratedTooland the@tooldecorator as the way to register Python callbacks the agent can invoke. Replaces the priorTool/PydanticToolpair with a single user-facing type.On the guest (
strands-wasm/entry.ts), fixmapContentBlockso thetoJSON()outer wrappers from SDK content blocks are stripped to match the WIT inner-record shape, and addmapToolResultBlock/mapToolResultContenthelpers for tool-result events. Without this, tool-use events trapped the wasm module on the very first model tool call.Pin
pgrayy-wasmtimeto thewasmtime-v46.0.7release wheel so installation no longer requires a git clone with submodule resolution.Related Issues
#2421
#2374
Documentation PR
N/A
Type of Change
New feature
Testing
tests/test_tools.py::test_decorated_tool_invocation. Registers@tool def get_weather(...), asks the model "What is the weather in Seattle?", awaitsagent.invoke_async, and asserts the tool's value reached the final response ("72" in str(result)). Exercises the full host→guest→host round trip: tool registration, model-issued tool call, Python callback execution, result marshaled back to the model, and final assistant response.tests/test_agent.py::test_stream_async_hello_worldcontinues to pass.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.