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.
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#8B0000', 'primaryTextColor': '#fff', 'primaryBorderColor': '#710101', 'lineColor': '#189AB4', 'secondaryColor': '#189AB4', 'tertiaryColor': '#fff' }}}%%
graph LR
agent["Agent"] -- "uses" --> tool["Tool: before_tool"]
tool -- "returns" --> result["Result"]
style tool fill:#189AB4,color:#fff
style agent fill:#8B0000,color:#fff
style result fill:#8B0000,color:#fffSignature
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