Skip to main content
You can use tool hooks to perform validation, logging, or any other logic before or after a tool is called. Install dependencies: uv pip install agno openai Set your OpenAI API key:
A tool hook receives the function name, wrapped function call, and arguments. It can also access the Agent, Team, or RunContext. Call the wrapped function with the arguments to continue the chain. Raise an exception or return another result to stop or replace the call.
Use a supported parameter name when defining a tool hook: agent, team, run_context; name or function_name; function, func, or function_call; and args or arguments.
For example:
or
You can assign tool hooks on agents and teams. The tool hooks will be applied to all tool calls made by the agent or team. For example:
You can also get access to the RunContext object in the tool hook. Inside the run context, you will find the session state, dependencies, and metadata.

Multiple Tool Hooks

You can also assign multiple tool hooks at once. They will be applied in the order they are assigned.
You can also assign tool hooks to specific custom tools.

Pre and Post Hooks

Pre and post hooks let you modify what happens before and after a tool is called. They are an alternative to tool hooks. Set the pre_hook in the @tool decorator to run a function before the tool call. Set the post_hook in the @tool decorator to run a function after the tool call. Here’s an example that uses a pre_hook and post_hook along with agent dependencies.
pre_and_post_hooks.py