Use this file to discover all available pages before exploring further.
Hooks let you intercept agent execution at key points - before/after LLM calls, tool executions, and task completions.
Breaking change in PR #1558: execute_sync() cannot be called from within a running event loop. Use await runner.execute(event, input_data, target) instead in async contexts.Error message: execute_sync() cannot be called from within a running event loop. Use 'await runner.execute(event, input_data, target)' instead in async contexts.
from praisonaiagents.hooks import add_hook, HookResult@add_hook('before_tool')def log_tool(event_data): print(f"Tool: {event_data.tool_name}") return HookResult.allow()
2
Create Agent
from praisonaiagents import Agentagent = Agent( name="Hooked Agent", instructions="You are a helpful assistant")# Hooks are automatically appliedagent.start("Help me with a task")
from praisonaiagents import HooksConfigconfig = HooksConfig( on_step=my_step_callback, # Called on each step on_tool_call=my_tool_callback, # Called on tool execution middleware=[my_middleware], # Request/response middleware)
# Before (silently fire-and-forget, results dropped)runner.execute_sync(event, input_data, target)# After (in async context)await runner.execute(event, input_data, target)# Still works (in non-async context)runner.execute_sync(event, input_data, target)