Documentation Index
Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The middleware system provides before/after hooks and wrap decorators for intercepting model and tool calls.
Quick Start
from praisonaiagents import Agent, tool
from praisonaiagents.hooks import before_model, wrap_tool_call
@before_model
def add_context(request):
print("Before model call")
return request
@wrap_tool_call
def retry_on_error(tool_call, call_next):
try:
return call_next(tool_call)
except Exception:
return call_next(tool_call) # Retry once
agent = Agent(
name="Bot",
instructions="Helper",
hooks=[add_context, retry_on_error]
)
Available Decorators
| Decorator | Purpose |
|---|
@before_model | Run before LLM call |
@after_model | Run after LLM call |
@wrap_model_call | Wrap entire LLM call |
@before_tool | Run before tool execution |
@after_tool | Run after tool execution |
@wrap_tool_call | Wrap entire tool execution |
Types
from praisonaiagents.hooks import (
InvocationContext,
ModelRequest,
ModelResponse,
ToolRequest,
ToolResponse
)
Zero Overhead
When no hooks are registered, middleware adds zero overhead to execution.