run_hooks_in_background at the AgentOS level. Guardrail hooks remain synchronous so they can accept or reject the run before processing continues.
1
Create a Python file
background_hooks_global.py
2
Set up your virtual environment
3
Install dependencies
4
Export your OpenAI API key
5
Run the server
6
Test the endpoint
What Happens
- The agent processes the request
- The response is sent immediately to the user
- Non-guardrail pre-hooks and post-hooks run in the background
- Guardrail hooks run synchronously and can block the request
- The user doesn’t have to wait for background tasks to complete
With
run_hooks_in_background=True on AgentOS, non-guardrail hooks for all agents run in the background. Guardrail hooks remain synchronous. Use the @hook decorator for per-hook control.