As Tool Call Hook • AI Agent SDK
as_tool_call_hook: Adapt a plain “on_tool_call“ callback into a “before_tool“ hook.
as_tool_call_hook
Function
</div>
This function is defined in the middleware module.
Adapt a plain `on_tool_call callback into a before_tool` hook.
`HooksConfig(on_tool_call=...) is routed onto the existing before_tool middleware slot, so it fires for every tool the agent executes (sync and async paths both run through :class:MiddlewareManager). The callback receives the :class:ToolRequest`; its return value is ignored so the request passes through unchanged.
Signature
def as_tool_call_hook(callback: Callable[[Any], Any]) -> BeforeToolFnParameters
ParamField
CallableNo description available.
Returns
ResponseField
BeforeToolFnThe result of the operation.
Source
View on GitHubpraisonaiagents/hooks/middleware.py at line 358