import type { Attributes, SpanContext } from "#compiled/@opentelemetry/api/index.js"; import type { InstrumentationToolCallKind, InstrumentationParentLineage, InstrumentationPrincipalSummary, InstrumentationTraceContext, InstrumentationTurnFailedEvent, InstrumentationTurnSettledEvent } from "#instrumentation/lifecycle.js"; import type { ChannelAudience } from "#shared/channel-audience.js"; import type { InstrumentationDecision } from "#shared/instrumentation-decision.js"; export interface AgentSessionTraceState { readonly traceSessionId: string; readonly channelAudience?: ChannelAudience; readonly agentName?: string; readonly channelKind?: string; readonly channelType?: string; readonly context: SpanContext; readonly decision?: InstrumentationDecision; readonly parentLineage?: InstrumentationParentLineage; readonly rootSessionId: string; readonly scheduleId?: string; readonly title?: string; } export interface AgentTurnTraceState { readonly traceSessionId: string; readonly caller?: SpanContext; readonly channelDelivery?: AgentTurnChannelDeliveryTraceState; readonly context: SpanContext; readonly currentPrincipal?: InstrumentationPrincipalSummary; readonly initiatorPrincipal?: InstrumentationPrincipalSummary; readonly parentLineage?: InstrumentationParentLineage; /** First model input projected onto the turn-level invoke_agent span. */ readonly inputMessagesAttribute?: string; readonly modelUsage?: { readonly inputTokens?: number; readonly outputTokens?: number; }; /** Latest model output projected onto the turn-level invoke_agent span. */ readonly outputMessagesAttribute?: string; readonly rootSessionId: string; readonly sequence: number; readonly startTimeMs: number; readonly subagentName?: string; readonly terminal?: { readonly error: unknown; readonly type: InstrumentationTurnFailedEvent["type"]; } | { readonly type: InstrumentationTurnSettledEvent["type"]; }; } export interface AgentTurnChannelDeliveryTraceState { readonly channelKind: string; readonly channelName: string; readonly deliveryId: string; readonly inputAttribute?: string; readonly requestId?: string; readonly requestTraceContext?: SpanContext; } export interface AgentActionTraceState { readonly traceSessionId: string; readonly attemptIndex: number; readonly callId: string; readonly channelAudience?: ChannelAudience; readonly inputAttribute?: string; readonly kind: InstrumentationToolCallKind; readonly name: string; readonly parent: InstrumentationTraceContext; readonly rootSessionId: string; readonly sessionId: string; readonly spanId: string; readonly startTimeMs: number; readonly stepIndex: number; readonly turnId: string; readonly toolAttributes?: Attributes; readonly toolEndTimeMs?: number; readonly toolFailed?: boolean; readonly toolErrorAttribute?: string; } /** Provider-owned serializable storage for durable agent trace state. */ export interface AgentTraceStateStore { deleteAction(idempotencyKey: string): void | PromiseLike; deleteActionAnchors(sessionId: string): void | PromiseLike; deleteActions(sessionId: string, turnId?: string): void | PromiseLike; deleteSession(sessionId: string): void | PromiseLike; deleteTurn(sessionId: string, turnId: string): void | PromiseLike; findAction(sessionId: string, callId: string): AgentActionTraceState | undefined | PromiseLike; findActionAnchor(sessionId: string, turnId: string, callId: string): AgentActionTraceState | undefined | PromiseLike; getAction(idempotencyKey: string): AgentActionTraceState | undefined | PromiseLike; getSession(sessionId: string): AgentSessionTraceState | undefined | PromiseLike; getTurn(sessionId: string, turnId: string): AgentTurnTraceState | undefined | PromiseLike; setAction(idempotencyKey: string, state: AgentActionTraceState): void | PromiseLike; setActionAnchor(idempotencyKey: string, state: AgentActionTraceState): void | PromiseLike; setSession(sessionId: string, state: AgentSessionTraceState): void | PromiseLike; setTurn(sessionId: string, turnId: string, state: AgentTurnTraceState): void | PromiseLike; /** Atomically updates an existing turn and does nothing after that turn is deleted. */ updateTurn(sessionId: string, turnId: string, update: (state: AgentTurnTraceState) => AgentTurnTraceState): void | PromiseLike; }