/** * High-level pi Agent SDK integration for Introspection. * * Wraps {@link @introspection-sdk/introspection-pi} behind a zero-config * interface so users don't need to manage OpenTelemetry tracers directly. * * @example * ```ts * import { IntrospectionPiInstrumentor, setupTracing } from "@introspection-sdk/introspection-node/otel"; * import { Agent } from "@earendil-works/pi-agent-core"; * * setupTracing({ serviceName: "my-app" }); * const instrumentor = new IntrospectionPiInstrumentor(); * * const agent = new Agent({ ... }); * instrumentor.instrument(agent, { * conversationId: "conv-123", * agentId: "weather-agent", * agentName: "Weather", * }); * * await agent.prompt("What's the weather in Tokyo?"); * instrumentor.stop(); * ``` */ import type { Agent } from "@earendil-works/pi-agent-core"; import { type AgentMeta } from "@introspection-sdk/introspection-pi"; export type { AgentMeta, AgentMeta as PiAgentMeta, } from "@introspection-sdk/introspection-pi"; export interface IntrospectionPiInstrumentorOptions { /** Tracer name used for all spans produced by this instrumentor. */ tracerName?: string; } /** * Zero-config pi Agent SDK integration for Introspection. * * Uses the global OTel tracer provider (registered by {@link setupTracing}). * Call {@link instrument} once per {@link Agent} instance, then {@link stop} * to unsubscribe all tool instrumentation and finalize open spans. */ export declare class IntrospectionPiInstrumentor { private _tracer; /** Per instrumented agent: its loop subscription and how to unwrap it. */ private _active; constructor(opts?: IntrospectionPiInstrumentorOptions); /** * Instrument a pi {@link Agent}: * - Wraps the agent stream function to emit a `chat ${model}` span per * LLM call. * - Subscribes to the agent loop to emit an `execute_tool ${name}` span per * tool execution. * * Re-instrumenting an agent replaces its previous instrumentation rather * than stacking on top. `AgentMeta` carries the conversation id, so a host * reusing one `Agent` across conversations calls this again by design; * without the replace, the stream was wrapped twice and `subscribe` fired * twice, so every call produced two `chat` spans and two `execute_tool` * spans, the inner pair stamped with the previous conversation. * * @param agent - The pi Agent instance to instrument. * @param meta - Identity metadata stamped on every span produced by this agent. */ instrument(agent: Agent, meta: AgentMeta): void; /** * Unsubscribe all active tool instrumentations, finalize any open spans, and * put each agent's original stream function back. * * Restoring matters: without it a stopped instrumentor's agents kept * emitting `chat` spans onto a provider that had already been shut down. */ stop(): void; private _detach; } //# sourceMappingURL=pi.d.ts.map