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.

Diagram

uses

returns

Agent

Tool: before_tool

Result

Signature

python
def before_tool(func: BeforeToolFn) -> BeforeToolFn

Parameters

ParamField BeforeToolFn

No description available.

Returns

ResponseField BeforeToolFn

The result of the operation.

Usage

python
@before_tool
    def validate_args(request):
        if 'dangerous' in request.arguments:
            raise ValueError("Dangerous argument detected")
        return request

Source

View on GitHub

praisonaiagents/hooks/middleware.py at line 248


Related Documentation