Skip to main content
Runtime tool result middleware converts vendor-shaped tool outputs from plugin harnesses into a standard format before hooks and memory adapters run.
The user runs tools through a plugin harness; middleware normalises vendor-shaped results before hooks and memory run.

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 in tool_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 — set success=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

Middleware runs on the hot path after every tool call. Avoid heavy imports or deep copies inside normalize().
Preserve the original vendor object in raw_result so hooks and debugging can inspect the pre-normalised payload.
Middleware failures are caught and logged; tool execution continues with the raw result.
Do not register middleware for "praisonai" — the core runtime bypasses it for zero overhead.

Hooks

Hooks receive the normalised payload via AfterToolInput

Agent Runtime Protocol

Pluggable agent execution runtimes (turn/stream abstraction)