You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Fetch the age of the user, with access to tool metadata."""
91
+
print(ctx.tool_name) # e.g. "fetch_user_age"
92
+
print(ctx.tool_call_id) # unique ID for this invocation
93
+
print(ctx.tool_arguments) # raw arguments as string
94
+
returnf"The user {ctx.context.name} is 47 years old."
95
+
```
96
+
97
+
`ToolContext` provides the same `.context` property as `RunContextWrapper`,
98
+
plus additional fields specific to the current tool call:
99
+
100
+
-`tool_name` – the name of the tool being invoked
101
+
-`tool_call_id` – a unique identifier for this tool call
102
+
-`tool_arguments` – the raw argument string passed to the tool
103
+
104
+
Use `ToolContext` when you need tool-level metadata during execution.
105
+
For general context sharing between agents and tools, `RunContextWrapper` remains sufficient.
106
+
107
+
---
108
+
71
109
## Agent/LLM context
72
110
73
111
When an LLM is called, the **only** data it can see is from the conversation history. This means that if you want to make some new data available to the LLM, you must do it in a way that makes it available in that history. There are a few ways to do this:
0 commit comments