Runtime Tool Result Middleware • AI Agent SDK
RuntimeToolResultMiddleware: Protocol for runtime-scoped tool result middleware.
RuntimeToolResultMiddleware
Defined in the middleware module.
AI Agent
Protocol for runtime-scoped tool result middleware.
Plugin harnesses implement this to normalize their vendor-specific tool results into the standard NormalizedToolResult format.
Methods
normalize()
Normalize a tool result into standard format.
runtime_id()Unique identifier for the runtime this middleware handles.
Usage
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
View on GitHubpraisonaiagents/runtime/middleware.py at line 67