Before Tool • AI Agent SDK
before_tool: Decorator to mark a function as a before_tool hook.
before_tool
Function
</div>
This function is defined in the middleware module.
Decorator to mark a function as a before_tool hook.
The function receives a ToolRequest and should return a (possibly modified) ToolRequest.
Signature
def before_tool(func: BeforeToolFn) -> BeforeToolFnParameters
ParamField
BeforeToolFnNo description available.
Returns
ResponseField
BeforeToolFnThe result of the operation.
Usage
@before_tool
def validate_args(request):
if 'dangerous' in request.arguments:
raise ValueError("Dangerous argument detected")
return requestSource
View on GitHubpraisonaiagents/hooks/middleware.py at line 248