-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
Description
Background
Currently, the RunHooks API only exposes the Tool instance (e.g. FunctionTool or ComputerTool) to on_tool_start and on_tool_end, but does not include the raw arguments passed in the tool call. The ToolContext object does not carry these call arguments, so hook implementers cannot inspect or log the payload that the model requested.
Proposal
- Include arguments on
ToolContext- Add an
arguments: Anyfield toToolContext, populated with the JSON-decoded payload of the tool call.
- Add an
- Populate
ToolContextwith arguments- Update runner code to call
ToolContext.from_agent_context(context_wrapper, call_id, tool_call.arguments)when building the context.
- Update runner code to call
- Expose
context.argumentsin hooks- Users can then read
context.argumentsinon_tool_startandon_tool_end.
- Users can then read
Benefits
- Hooks can log or audit exactly what inputs were provided to each tool.
- Enables richer lifecycle monitoring and debugging.
Example Hook Usage
class LoggingHooks(RunHooks):
async def on_tool_start(self, context: ToolContext, agent: Agent, tool: Tool):
print(f"Tool {tool.name} started with args: {context.arguments!r}")ludovicoserrani-nautes, lovepeacemz, lilian-zh and yuto-ueda