Skip to content

feat(strands-py-wasm): add DecoratedTool for host-side Python tools#2412

Merged
pgrayy merged 3 commits into
strands-agents:mainfrom
pgrayy:add-decorated-tool
Jun 1, 2026
Merged

feat(strands-py-wasm): add DecoratedTool for host-side Python tools#2412
pgrayy merged 3 commits into
strands-agents:mainfrom
pgrayy:add-decorated-tool

Conversation

@pgrayy
Copy link
Copy Markdown
Member

@pgrayy pgrayy commented Jun 1, 2026

Description

Introduce DecoratedTool and the @tool decorator as the way to register Python callbacks the agent can invoke. Replaces the prior Tool / PydanticTool pair with a single user-facing type.

from strands import Agent, BedrockModel, tool

@tool
def get_weather(city: str) -> str:
    """Return the current weather for a city."""
    return f"It is 72F and sunny in {city}."

agent = Agent(model=BedrockModel(...), tools=[get_weather])

On the guest (strands-wasm/entry.ts), 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. Without this, tool-use events trapped the wasm module on the very first model tool call.

Pin pgrayy-wasmtime to the wasmtime-v46.0.7 release 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

  • Added tests/test_tools.py::test_decorated_tool_invocation. Registers @tool def get_weather(...), asks the model "What is the weather in Seattle?", awaits agent.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.
  • Verified existing tests/test_agent.py::test_stream_async_hello_world continues to pass.
  • Manually inspected the model's full final response to confirm the tool's content was incorporated naturally (e.g., "The weather in Seattle is currently 72°F and sunny. It's a nice day!").

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

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.
Comment thread strands-py-wasm/pyproject.toml
Comment thread strands-py-wasm/src/strands/__init__.py
Comment thread strands-py-wasm/src/strands/__init__.py Outdated
Comment thread strands-py-wasm/src/strands/__init__.py
Comment thread strands-py-wasm/src/strands/__init__.py Outdated
Rename _coerce_tool_result to _normalize_tool_result and fix the
docstring reference to render as @tool.
@github-actions github-actions Bot added size/m and removed size/m labels Jun 1, 2026
@pgrayy pgrayy requested a deployment to manual-approval June 1, 2026 18:05 — with GitHub Actions Waiting
@pgrayy pgrayy enabled auto-merge (squash) June 1, 2026 18:08
@pgrayy pgrayy merged commit 5fd6c17 into strands-agents:main Jun 1, 2026
21 of 23 checks passed
@pgrayy pgrayy deleted the add-decorated-tool branch June 1, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants