Adding Tools
Tools give your agent domain-specific capabilities. Strands supports two ways to define them: the @tool decorator (most common) and the TOOL_SPEC module pattern.
Using @tool (Recommended)
-
Create a Python file inside
strands_base_agent/tools/. -
Configure the tool path in
config.yaml:tools_dir: strands_base_agent/toolstools_files:- strands_base_agent/tools/local_tools.pyOr via environment variable:
export STRANDS__TOOLS_DIR=strands_base_agent/toolsexport STRANDS__TOOLS_FILES=strands_base_agent/tools/local_tools.pyTools load only from inside
tools_dir. Its default is the container path/app/strands_base_agent/tools, so withouttools_dir, local runs (just run,just demo) reject every tool. The relative path works both locally and in the container.For multiple files, use a YAML list or a comma-separated string.
Or name the file by its module path in
tools_modulesinstead:tools_dir: strands_base_agent/toolstools_modules:- strands_base_agent.tools.local_toolsOr via environment variable:
export STRANDS__TOOLS_DIR=strands_base_agent/toolsexport STRANDS__TOOLS_MODULES=strands_base_agent.tools.local_tools -
Decorate each function with
@tool, include type hints and a docstring:from strands import tool@tooldef flip_coin() -> bool:"""Flips a coin.Returns:Returns True for heads and False for tails."""import randomreturn random.random() >= 0.5@tooldef check_app_approval_status(app_name: str) -> bool:"""Checks if a given app is approved for use.Args:app_name: the name of the appReturns:Returns True if the app is approved."""return "ai" not in app_name
The docstring is what the model sees — write it clearly. Describe what the tool does, when to use it, what arguments mean, and what it returns.
Using TOOL_SPEC
For tools that need explicit JSON Schema input definitions:
-
Create a Python file inside
strands_base_agent/tools/. ATOOL_SPECfile holds one tool, and the file name must match the tool name. -
Configure the file path in
config.yaml:tools_dir: strands_base_agent/toolstools_files:- strands_base_agent/tools/send_report.pyOr via environment variable:
export STRANDS__TOOLS_DIR=strands_base_agent/toolsexport STRANDS__TOOLS_FILES=strands_base_agent/tools/send_report.pyList a
TOOL_SPECfile intools_files, not by module name intools_modules:foundry-strands-agent3.2.1 and earlier drop aTOOL_SPECmodule listed intools_moduleswithout an error, so the agent never gets the tool. -
Define
TOOL_SPECand the implementation function in the file:TOOL_SPEC = {"name": "send_report","description": "Submit a report to a manager.","inputSchema": {"json": {"type": "object","properties": {"content": {"type": "string","description": "The items in the report",},},"required": ["content"],}},}def send_report(tool, **kwargs):tool_use_id = tool["toolUseId"]tool_input = tool["input"]content = tool_input.get("content")result = "Report submitted successfully."return {"toolUseId": tool_use_id,"status": "success","content": [{"text": result}],}
For the full TOOL_SPEC reference, see Module Based Tools in the Strands documentation.
Verifying Tools Loaded
Run the agent and check the startup logs — registered tools are logged when the agent factory builds the tool registry. Then ask the agent something that should trigger your tool:
curl -X POST http://localhost:8000/api/v1/query \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-key>" \
-d '{"query": "Flip a coin for me"}'
Note on CLI Functionality
Please note that local tools are not supported when running the agent in the CLI. They will fail to load. MCP tools may still be used, however.