Skip to content

Commit 45ff7d6

Browse files
Liljazastrowm
andauthored
fix: clarify tool_context parameter name. (#279)
* fix: clarify `tool_context` parameter name. * feat: Add some additional detail regarding tool_context parameter name --------- Co-authored-by: Mackenzie Zastrow <[email protected]>
1 parent 5198855 commit 45ff7d6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

docs/user-guide/concepts/agents/state.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ except ValueError as e:
155155

156156
### Using State in Tools
157157

158+
!!! note
159+
160+
To use `ToolContext` in your tool function, the parameter must be named `tool_context`. See [ToolContext documentation](../tools/python-tools.md#toolcontext) for more information.
161+
162+
158163
Agent state is particularly useful for maintaining information across tool executions:
159164

160165
```python

docs/user-guide/concepts/tools/python-tools.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ agent("What is the tool use id?")
172172
agent("What is the invocation state?", custom_data="You're the best agent ;)")
173173
```
174174

175+
To use a different parameter name for ToolContext, specify the desired name as the value of the `@tool.context` argument:
176+
177+
```python
178+
from strands import tool, Agent, ToolContext
179+
180+
@tool(context="context")
181+
def get_self_name(context: ToolContext) -> str:
182+
return f"The agent name is {context.agent.name}"
183+
184+
agent = Agent(tools=[get_self_name], name="Best agent")
185+
186+
agent("What is your name?")
187+
```
188+
175189
#### Accessing Invocation State in Tools
176190

177191
The `invocation_state` attribute in `ToolContext` provides access to data passed through the agent invocation. This is particularly useful for:

0 commit comments

Comments
 (0)