> ## 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.

# Runtime Tool Result Middleware • AI Agent SDK

> RuntimeToolResultMiddleware: Protocol for runtime-scoped tool result middleware.

# RuntimeToolResultMiddleware

> Defined in the [**middleware**](../modules/middleware) module.

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

Protocol for runtime-scoped tool result middleware.

Plugin harnesses implement this to normalize their vendor-specific
tool results into the standard NormalizedToolResult format.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#8B0000', 'primaryTextColor': '#fff', 'primaryBorderColor': '#710101', 'lineColor': '#189AB4', 'secondaryColor': '#189AB4', 'tertiaryColor': '#fff' }}}%%

graph LR
    agent["Agent"] -- "uses" --> tool["Tool: RuntimeToolResultMiddleware"]
    tool -- "returns" --> result["Result"]
    style tool fill:#189AB4,color:#fff
    style agent fill:#8B0000,color:#fff
    style result fill:#8B0000,color:#fff
```

## Methods

<CardGroup cols={2}>
  <Card title="normalize()" icon="function" href="../functions/RuntimeToolResultMiddleware-normalize">
    Normalize a tool result into standard format.
  </Card>

  <Card title="runtime_id()" icon="function" href="../functions/RuntimeToolResultMiddleware-runtime_id">
    Unique identifier for the runtime this middleware handles.
  </Card>
</CardGroup>

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
class MyHarnessMiddleware:
        def normalize(self, result: Any, tool_name: str, ctx: MiddlewareContext) -> NormalizedToolResult:
            # Convert vendor-specific result format to standard format
            if isinstance(result, MyVendorResult):
                return NormalizedToolResult(
                    content=result.data,
                    success=result.status == "ok",
                    error_message=result.error if result.status != "ok" else None,
                    metadata={
                        "vendor": "my_vendor",
                        "result_type": type(result).__name__
                    },
                    raw_result=result
                )
            return NormalizedToolResult(content=result)
```

## Source

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

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Tools Concept" icon="wrench" href="/docs/docs/concepts/tools" />

  <Card title="Create Custom Tools" icon="plus" href="/docs/docs/guides/tools/create-custom-tools" />

  <Card title="Tool Development" icon="code" href="/docs/docs/tutorials/advanced-tool-development" />

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