Skip to content

feat: add public tool_spec setter #1822

Merged
mkmeral merged 4 commits intostrands-agents:mainfrom
mkmeral:feat/tool-spec-setter
Mar 9, 2026
Merged

feat: add public tool_spec setter #1822
mkmeral merged 4 commits intostrands-agents:mainfrom
mkmeral:feat/tool-spec-setter

Conversation

@mkmeral
Copy link
Contributor

@mkmeral mkmeral commented Mar 5, 2026

Description

Add a public tool_spec setter property to DecoratedFunctionTool and PythonAgentTool, enabling runtime modification of a tool's schema after construction.

This is useful for dynamically adjusting tool configurations based on feature flags, user permissions, or other runtime conditions — for example, adding or removing parameters from a tool's input schema without recreating the tool instance.

Changes:

  • src/strands/tools/decorator.py — Added @tool_spec.setter on DecoratedFunctionTool
  • src/strands/tools/tools.py — Added @tool_spec.setter on PythonAgentTool
  • tests/strands/tools/test_tool_spec_setter.py — 5 unit tests covering both classes

Related Issues

Documentation PR

Type of Change

New feature

Testing

Added tests/strands/tools/test_tool_spec_setter.py with 5 tests:

  • TestDecoratedFunctionToolSpecSetter (3 tests): verifies spec replacement, persistence across reads, and adding properties via setter
  • TestPythonAgentToolSpecSetter (2 tests): verifies spec replacement and persistence across reads

All tests pass:

tests/strands/tools/test_tool_spec_setter.py::TestDecoratedFunctionToolSpecSetter::test_set_tool_spec_replaces_spec PASSED
tests/strands/tools/test_tool_spec_setter.py::TestDecoratedFunctionToolSpecSetter::test_set_tool_spec_persists_across_reads PASSED
tests/strands/tools/test_tool_spec_setter.py::TestDecoratedFunctionToolSpecSetter::test_add_property_via_setter PASSED
tests/strands/tools/test_tool_spec_setter.py::TestPythonAgentToolSpecSetter::test_set_tool_spec PASSED
tests/strands/tools/test_tool_spec_setter.py::TestPythonAgentToolSpecSetter::test_set_tool_spec_persists PASSED
  • I ran hatch run prepare

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.

@github-actions github-actions bot added the size/m label Mar 5, 2026
@mkmeral mkmeral changed the title feat: add public tool_spec setter to DecoratedFunctionTool and Python… feat: add public tool_spec setter Mar 5, 2026
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

zastrowm
zastrowm previously approved these changes Mar 6, 2026
The json wrapper inside inputSchema is not required — both
normalize_tool_spec and the registry's validate_tool_spec handle bare
schemas by wrapping them automatically. The setter should only enforce
what the ToolSpec TypedDict requires: name, description, inputSchema.
@mkmeral mkmeral enabled auto-merge (squash) March 9, 2026 17:30
@mkmeral mkmeral merged commit 98636ae into strands-agents:main Mar 9, 2026
19 of 21 checks passed
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.

3 participants