Quick Start
1
Simple Usage
The native
praisonai runtime needs no middleware — results pass straight to hooks:2
With Configuration
Register harness middleware once, then set
agent._runtime_id:How It Works
Middleware runs intool_execution.py before the AFTER_TOOL hook fires.
When agent._runtime_id is missing or equals "praisonai", middleware is bypassed entirely (zero allocation).
Configuration Options
MiddlewareContext
NormalizedToolResult
Registry API
Module helpers:
register_middleware, get_middleware, get_default_middleware_registry().
Common Patterns
Error handling — setsuccess=False and fill error_message; failed tools surface as "Tool Error: <message>" to the agent.
Rich metadata — attach vendor, version, cache hit, or region in metadata for observability hooks.
Conditional normalization — branch on tool_name prefix (e.g. search_ vs db_) inside normalize().
User Interaction Flow
Best Practices
Keep normalize() allocation-light
Keep normalize() allocation-light
Middleware runs on the hot path after every tool call. Avoid heavy imports or deep copies inside
normalize().Always set raw_result
Always set raw_result
Preserve the original vendor object in
raw_result so hooks and debugging can inspect the pre-normalised payload.Do not raise from normalize()
Do not raise from normalize()
Middleware failures are caught and logged; tool execution continues with the raw result.
Skip middleware for native praisonai
Skip middleware for native praisonai
Do not register middleware for
"praisonai" — the core runtime bypasses it for zero overhead.Related
Hooks
Hooks receive the normalised payload via AfterToolInput
Agent Runtime Protocol
Pluggable agent execution runtimes (turn/stream abstraction)

