Hooks and autonomy

Prompts tell an agent what you *hope* it will do. Hooks, rules, and bounded autonomy enforce what it *actually* does in code — auditing every tool call, applying repo-wide rules, and capping autonomous iterations and spend.

This 9-step course builds step by step from the agent lifecycle to live-firing HooksConfig callbacks, blocking middleware, MultiAgentHooksConfig, RulesConfig + AGENTS.md, AutonomyConfig levels, GoalEngineer, Heartbeat, and a guarded autonomous repo maintainer.

Every single Python lesson here executes live in Try it Yourself using real tool calls and deterministic offline models so you see hooks fire and caps trigger firsthand.

See a hook fire on a real tool call

Click Try it Yourself to watch on_tool_call intercept a real ToolRequest object mid-run.

Example

from praisonai import Agent, HooksConfig

def check_health() -> str:
    """Return service health status."""
    return 'healthy'

audit_log = []
def record_tool(event):
    audit_log.append(f'{event.tool_name}({event.arguments})')

agent = Agent(
    name='HealthBot',
    instructions='Always call check_health and report the status in one short sentence.',
    tools=[check_health],
    hooks=HooksConfig(on_tool_call=record_tool),
    output='silent',
)
print('Reply:', agent.start('Check service health'))
print('Hooks captured:', audit_log)

Try it Yourself

Example explained

  • record_tool(event) — Receives a ToolRequest object containing event.tool_name and event.arguments.
  • HooksConfig(on_tool_call=record_tool) — Wires your callback into the agent execution loop without editing prompts.

Next

Exercises · Quiz · Reference