Skip to content

Attach and invoke tools

Once you have tools, whether you wrote them yourself, pulled them from an MCP server, or picked them from a prebuilt package, you attach them to an agent and the agent decides when to call them. This page covers how tools load onto an agent and the two ways to invoke them.

Pass tools to an agent at initialization or add them at runtime. Once loaded, the agent can call them in response to user requests:

from strands import Agent
from strands.vended_tools import http_request, notebook
# Add tools to our agent
agent = Agent(tools=[http_request, notebook])
# Agent will automatically determine when to use the notebook tool
agent('Create a notebook named "ideas" and add three project ideas.')
print("\n\n") # Print new lines
# Agent will use the HTTP request tool when appropriate
agent("Get https://example.com and summarize the response status.")

We can see which tools are loaded in our agent:

Access agent.tool_names for a list of tool names, and agent.tool_registry.get_all_tools_config() for a JSON representation including descriptions and input parameters:

print(agent.tool_names)
print(agent.tool_registry.get_all_tools_config())

Load tools from a file by passing its path at initialization:

agent = Agent(tools=["/path/to/my_tool.py"])

Tools placed in your current working directory ./tools/ can be automatically loaded at agent initialization, and automatically reloaded when modified. This helps when developing and debugging tools: modify the tool code and any agent using it reloads the latest version.

Automatic loading and reloading of tools in the ./tools/ directory is disabled by default. To enable this behavior, set load_tools_from_directory=True during Agent initialization:

from strands import Agent
agent = Agent(load_tools_from_directory=True)

You can invoke tools in two ways.

Agents have context about tool calls and their results as part of conversation history. See Using State in Tools for more information.

The most common way agents use tools is through natural language requests. The agent determines when and how to invoke tools based on the user’s input:

# Agent decides when to use tools based on the request
agent('Read the "ideas" notebook.')

Tools can be invoked programmatically in addition to natural language invocation.

Every tool added to an agent becomes a method accessible directly on the agent object:

# Directly invoke a tool as a method
result = agent.tool.notebook(mode="read", name="ideas")

When calling tools directly as methods, always use keyword arguments. Positional arguments are not supported:

# Positional arguments are not supported, this raises an error
result = agent.tool.notebook("read", "ideas")

If a tool name contains hyphens, you can invoke the tool using underscores instead:

# Directly invoke a tool named "read-all"
result = agent.tool.read_all(path="/path/to/file.txt")

When a model returns several tool requests at once, a tool executor controls whether they run concurrently (the default) or sequentially.