Skip to main content
The @hook decorator allows you to configure individual hook behavior. It can be applied to both pre-hooks and post-hooks.

Import

Parameters

ParameterTypeDefaultDescription
run_in_backgroundboolFalseWhen True, the hook runs as a background task after the response is sent. Requires AgentOS.

Usage

Background Execution

Mark a hook to run in the background without blocking the API response:

Combining with Regular Hooks

You can mix background and regular hooks on the same agent:

Important Notes

Background execution requires AgentOS. When running agents directly (not through AgentOS), hooks marked with run_in_background=True will execute synchronously.
Background hooks cannot modify data. Since background hooks run after the response is sent, any modifications to run_input, run_output, or other parameters won’t affect the agent’s processing. Use background mode only for logging, analytics, or notifications.

See Also