> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Middleware Registry • AI Agent SDK

> MiddlewareRegistry: Registry for runtime-scoped tool result middleware.

# MiddlewareRegistry

> Defined in the [**Middleware Registry**](../modules/middleware_registry) module.

<Badge color="blue">AI Agent</Badge>

Registry for runtime-scoped tool result middleware.

Thread-safe singleton-like registry that manages middleware instances
for different runtime environments. Plugin harnesses register their
middleware here, and the core tool execution system uses it to normalize
results before they reach hooks and memory adapters.

## Methods

<CardGroup cols={2}>
  <Card title="register()" icon="function" href="../functions/MiddlewareRegistry-register">
    Register middleware for a specific runtime.
  </Card>

  <Card title="unregister()" icon="function" href="../functions/MiddlewareRegistry-unregister">
    Unregister middleware for a runtime.
  </Card>

  <Card title="get_middleware()" icon="function" href="../functions/MiddlewareRegistry-get_middleware">
    Get middleware for a runtime.
  </Card>

  <Card title="has_middleware()" icon="function" href="../functions/MiddlewareRegistry-has_middleware">
    Check if middleware is registered for a runtime.
  </Card>

  <Card title="list_runtimes()" icon="function" href="../functions/MiddlewareRegistry-list_runtimes">
    List all registered runtime IDs.
  </Card>

  <Card title="clear()" icon="function" href="../functions/MiddlewareRegistry-clear">
    Clear all registered middleware.
  </Card>
</CardGroup>

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# In plugin harness initialization
    registry = MiddlewareRegistry()
    registry.register("claude_harness", ClaudeHarnessMiddleware())
    
    # In core tool execution (agent.execute_tool)
    registry = MiddlewareRegistry()
    middleware = registry.get_middleware("claude_harness")
    normalized = middleware.normalize(result, tool_name, ctx)
```

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/runtime/middleware_registry.py#L20">
  `praisonaiagents/runtime/middleware_registry.py` at line 20
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Middleware Feature" icon="layer-group" href="/docs/docs/features/middleware" />
</CardGroup>
