Principle:AIPexStudio AIPex Tool Event Normalization
| Knowledge Sources | |
|---|---|
| Domains | AI_Agent, Event_Processing |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
A transformation layer that converts heterogeneous SDK tool-call events into a unified, consumer-friendly event format with business-level error detection.
Description
AI agent SDKs emit tool events in provider-specific shapes with nested raw items, varying status fields, and unstructured output. Tool Event Normalization inspects these raw events, extracts tool names and arguments via safe JSON parsing, detects business-level failures (where `success === false` in the result object even though the SDK reports "completed"), and sanitizes error messages by masking sensitive patterns like API keys and bearer tokens. This produces a clean discriminated-union output that downstream consumers can pattern-match without understanding SDK internals.
Usage
Use this principle when integrating an AI agent SDK whose event shapes are complex or provider-dependent. It is the boundary between SDK-specific concerns and application-level event handling.
Theoretical Basis
The normalization pipeline:
input: SDK RunItemStreamEvent (name: "tool_called"|"tool_output")
↓
extract toolName from rawItem.name
extract arguments from rawItem.arguments (JSON-safe-parse)
extract output from item.output or rawItem.output (JSON-safe-parse)
↓
if status !== "completed" → tool_call_error (sanitized message)
if result.success === false → tool_call_error (sanitized message)
else → tool_call_complete(result)
↓
sanitize: mask Bearer tokens, API keys, truncate to 500 chars