Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions docs/user-guide/concepts/tools/python-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ asyncio.run(async_example())

### ToolContext

Tools can access their execution context by setting `context=True` and including a `tool_context` parameter. The `ToolContext` provides access to the invoking agent and current tool use data:
Tools can access their execution context by setting `context=True` and including a `tool_context` parameter. The [`ToolContext`](../../../api-reference/types.md#strands.types.tools.ToolContext) provides access to the invoking agent, current tool use data, and invocation state:

```python
from strands import tool, Agent, ToolContext
Expand All @@ -161,9 +161,15 @@ def get_self_name(tool_context: ToolContext) -> str:
def get_tool_use_id(tool_context: ToolContext) -> str:
return f"Tool use is {tool_context.tool_use["toolUseId"]}"

agent = Agent(tools=[get_self_name, get_tool_use_id], name="Best agent")
@tool(context=True)
def get_invocation_state(tool_context: ToolContext) -> str:
return f"Invocation state: {tool_context.invocation_state["custom_data"]}"

agent = Agent(tools=[get_self_name, get_tool_use_id, get_invocation_state], name="Best agent")

agent("What is your name?")
agent("What is the tool use id?")
agent("What is the invocation state?", custom_data="You're the best agent ;)")
```

### Tool Streaming
Expand Down