Hooks (Control)
Intercept and modify agent behavior. Can allow, deny, or block execution.Callbacks (Observe)
Receive notifications about events. Cannot modify or block execution.Quick Comparison
When to Use Each
- Use Hooks When
- Use Callbacks When
You need to control behavior:Examples:
- Block specific tool calls
- Modify prompts before LLM
- Validate tool arguments
- Implement rate limiting
- Enforce security policies
Code Examples
Hook: Block and Modify
Callback: Log and Notify
Callback Signature Distinction:
- Task-level callbacks (set on
Task()constructor): Use 1 argument -on_task_complete(task_output) - Multi-agent level callbacks (set via
MultiAgentHooksConfig): Use 2 arguments -on_task_start(task, task_id)andon_task_complete(task, task_output)
TypeError during execution.Decision Flow
Hook Decisions
Hooks returnHookResult with a decision:
Summary Table
Related
Hooks
Full hooks documentation
Callbacks
Callback implementation
Guardrails
Output validation
Approval
Human-in-the-loop

