Hooks
Tool Hooks
You can use tool hooks to perform validation, logging, or any other logic before or after a tool is called.
A tool hook is a function that takes a function name, function call, and arguments. Inside the tool hook, you have to call the function call and return the result.
For example:
or
You can assign tool hooks on agents and teams. The tool hooks will be applied to all tools in the agent or team.
For example:
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 (Deprecated)
Pre and post hooks let’s you modify what happens before and after a tool is called.
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 a demo example of using a pre_hook
, post_hook
along with Agent Context.