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

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.
Treat background hook arguments as read-only. AgentOS attempts to deep-copy run_input, run_context, run_output, session_state, dependencies, and metadata before queueing a hook. If a value cannot be copied, AgentOS logs a warning and passes the original reference. Background hooks can write to databases and external services.

See Also