Skip to main content
PraisonAI provides two mechanisms for responding to agent events: Hooks (control flow) and Callbacks (observation). Understanding the difference is key to building effective integrations.

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

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) and on_task_complete(task, task_output)
Choose the right arity to avoid TypeError during execution.

Decision Flow


Hook Decisions

Hooks return HookResult with a decision:

Summary Table


Hooks

Full hooks documentation

Callbacks

Callback implementation

Guardrails

Output validation

Approval

Human-in-the-loop