Skip to main content
memory.HooksManager runs pre/post scripts from .praisonai/hooks.json when you call .execute() — it does not fire automatically inside an Agent.
This is a standalone, opt-in utility. memory.HooksManager is NOT auto-wired into the agent/tool execution pipeline. It only runs when you construct it and call HooksManager.execute() yourself (e.g. inside a custom tool or wrapper). For hooks that fire automatically around an Agent’s tool/LLM calls, use the live praisonaiagents.hooks package instead.

Two Hook Systems

PraisonAI has two hook systems with the same short name. Pick the right one.

Quick Start

1

Create the manager

Use the correct import from praisonaiagents.memory:
2

Call .execute() yourself

Nothing calls this for you — invoke it from your own code:

How It Works

The “event” is triggered by whoever calls .execute() — not by the Agent lifecycle.

Hook Events

All ten events from the HookEvent type in praisonaiagents/memory/hooks.py:

HookResult

execute() returns a HookResult dataclass:

HookConfig

Each configured hook loads into a HookConfig:

Configuration File

Configure scripts in .praisonai/hooks.json:
Generate one programmatically with create_config:
The praisonai hooks list, praisonai hooks stats, and praisonai hooks init CLI commands read this same file — see CLI Hooks.

Common Patterns

Gate a write inside your own tool

The way to make HooksManager “gate” an operation is to call .execute() inside your tool — the Agent framework will not do it for you.

Register a Python callable


Best Practices

If you want a hook to fire automatically before every tool call, use praisonaiagents.hooks with Agent(hooks=registry). memory.HooksManager never runs on its own.
Put the .execute() call inside the tool or wrapper that performs the operation, so the hook runs at the right moment with the right context.
Scripts run inline via subprocess with a per-hook timeout (default 30s). Slow scripts delay your own code.
Check result.blocked and stop the operation yourself — nothing downstream enforces it.

Live Agent Hooks

Hooks that fire automatically around Agent tool and LLM calls.

Hooks CLI

List, inspect, and initialize .praisonai/hooks.json.