The Open Framework for Building Agents
fix(eve): require canonical instrumentation agent ids (#2757)
Chad Hietala69e9bff083e0
diff --git a/.changeset/require-instrumentation-agent-id.md b/.changeset/require-instrumentation-agent-id.mdnew file mode 100644index 000000000..edc9b5dc8--- /dev/null+++ b/.changeset/require-instrumentation-agent-id.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Instrumentation trace policies now always receive the active agent's canonical ID, including for configless agents and cancelled turns. Explicit provider policies must be bound to an agent before events are published.diff --git a/packages/eve/src/execution/node-step.test.ts b/packages/eve/src/execution/node-step.test.tsindex 7c8e7d73c..025c32ee4 100644--- a/packages/eve/src/execution/node-step.test.ts+++ b/packages/eve/src/execution/node-step.test.ts@@ -401,6 +401,7 @@ describe("createExecutionNodeStep", () => {shutdown: async () => undefined,};const instrumentation = bindInstrumentationRuntime(runtime, new ContextContainer(), {+ agentName: "test-agent",rootSessionId: "sess-root",sessionId: "sess-root",});diff --git a/packages/eve/src/execution/settle-cancelled-turn-step.integration.test.ts b/packages/eve/src/execution/settle-cancelled-turn-step.integration.test.tsindex ada627f5e..463f1c268 100644--- a/packages/eve/src/execution/settle-cancelled-turn-step.integration.test.ts+++ b/packages/eve/src/execution/settle-cancelled-turn-step.integration.test.ts@@ -1,4 +1,4 @@-import { describe, expect, it } from "vitest";+import { describe, expect, it, vi } from "vitest";import { createTestRuntime } from "#internal/testing/app-harness.js";import { createBundledRuntimeCompiledArtifactsSource } from "#runtime/compiled-artifacts-source.js";@@ -14,6 +14,18 @@ import {} from "#harness/handles/store.js";import type { HarnessSession } from "#harness/types.js";+const bindSessionInstrumentationSpy = vi.hoisted(() => vi.fn());+vi.mock("#instrumentation/runtime.js", async (importOriginal) => {+ const actual = await importOriginal<typeof import("#instrumentation/runtime.js")>();+ return {+ ...actual,+ bindSessionInstrumentation(input: Parameters<typeof actual.bindSessionInstrumentation>[0]) {+ bindSessionInstrumentationSpy(input);+ return actual.bindSessionInstrumentation(input);+ },+ };+});+/*** The cancellation epilogue is the last write that can move a cancelled* child's handle: `cancelDescendantTurnsStep` only requests cancellation,@@ -100,6 +112,7 @@ function buildSerializedContext(): Record<string, unknown> {describe("settleCancelledTurnStep handle store", () => {it("parks abandoned running handles as cancelled and keeps parked ones", async () => {+ bindSessionInstrumentationSpy.mockClear();const runtime = await createTestRuntime({ agent: { name: "settle-cancel-handles" } });await runtime.run(async () => {@@ -123,6 +136,9 @@ describe("settleCancelledTurnStep handle store", () => {],});expect(result.sessionState.snapshot?.session.outputSchema).toBeUndefined();+ expect(bindSessionInstrumentationSpy).toHaveBeenCalledWith(+ expect.objectContaining({ agentName: "settle-cancel-handles" }),+ );});});});diff --git a/packages/eve/src/execution/settle-cancelled-turn-step.ts b/packages/eve/src/execution/settle-cancelled-turn-step.tsindex b59417445..54b9079ab 100644--- a/packages/eve/src/execution/settle-cancelled-turn-step.ts+++ b/packages/eve/src/execution/settle-cancelled-turn-step.ts@@ -73,7 +73,7 @@ export async function settleCancelledTurnStep(input: {turnAgent: effectiveAgent.turnAgent,});const instrumentation = bindSessionInstrumentation({- agentName: bundle.graph.root.agent?.config?.name,+ agentName: effectiveAgent.turnAgent.id,ctx,rootSessionId: session.rootSessionId ?? session.sessionId,sessionId: session.sessionId,diff --git a/packages/eve/src/execution/workflow-steps.test.ts b/packages/eve/src/execution/workflow-steps.test.tsindex 2aac23d24..6278b50b2 100644--- a/packages/eve/src/execution/workflow-steps.test.ts+++ b/packages/eve/src/execution/workflow-steps.test.ts@@ -66,6 +66,18 @@ import {workflowEntryReference,} from "#execution/workflow-runtime.js";+const bindSessionInstrumentationSpy = vi.hoisted(() => vi.fn());+vi.mock("#instrumentation/runtime.js", async (importOriginal) => {+ const actual = await importOriginal<typeof import("#instrumentation/runtime.js")>();+ return {+ ...actual,+ bindSessionInstrumentation(input: Parameters<typeof actual.bindSessionInstrumentation>[0]) {+ bindSessionInstrumentationSpy(input);+ return actual.bindSessionInstrumentation(input);+ },+ };+});+vi.mock("./durable-session-store.js", async (importOriginal) => {const actual = await importOriginal<typeof import("./durable-session-store.js")>();return {@@ -1878,6 +1890,7 @@ describe("turnStep", () => {});it("uses the selected dynamic subagent model for execution identity", async () => {+ bindSessionInstrumentationSpy.mockClear();const session = createStubSession();installSessionStoreMocks([session]);vi.mocked(createExecutionNodeStep).mockImplementation(() => {@@ -1938,6 +1951,9 @@ describe("turnStep", () => {expect(createExecutionNodeStep).toHaveBeenCalledWith(expect.objectContaining({ node: effectiveNode }),);+ expect(bindSessionInstrumentationSpy).toHaveBeenCalledWith(+ expect.objectContaining({ agentName: TestTurnAgent.id }),+ );});it("returns tasksEnabled on park results so the turn workflow selects dispatchTaskStep", async () => {diff --git a/packages/eve/src/execution/workflow-steps.ts b/packages/eve/src/execution/workflow-steps.tsindex ad406ad54..d85eaf1f5 100644--- a/packages/eve/src/execution/workflow-steps.ts+++ b/packages/eve/src/execution/workflow-steps.ts@@ -198,7 +198,7 @@ export async function turnStep(rawInput: TurnStepInput): Promise<DurableStepResu});const history = createExecutionHistoryView(initialSession);const instrumentation = bindSessionInstrumentation({- agentName: bundle.graph.root.agent?.config?.name,+ agentName: effectiveAgent.turnAgent.id,ctx,rootSessionId: initialSession.rootSessionId ?? initialSession.sessionId,sessionId: initialSession.sessionId,diff --git a/packages/eve/src/harness/tool-loop.test.ts b/packages/eve/src/harness/tool-loop.test.tsindex 96469187e..8d503de79 100644--- a/packages/eve/src/harness/tool-loop.test.ts+++ b/packages/eve/src/harness/tool-loop.test.ts@@ -185,6 +185,7 @@ function declareTelemetry(declaredRuntime,createInstrumentationContext(decision, audience),{+ agentName: "test-agent",rootSessionId: "test-session",sessionId: "test-session",},@@ -214,7 +215,7 @@ function bindHookInstrumentation(useDeclaredRuntime ? declaredDecision : undefined,useDeclaredRuntime ? declaredAudience : "unknown",),- { rootSessionId: "test-session", sessionId: "test-session" },+ { agentName: "test-agent", rootSessionId: "test-session", sessionId: "test-session" },)!.prepareExecution();}diff --git a/packages/eve/src/instrumentation/ai-sdk-hook-bridge.test.ts b/packages/eve/src/instrumentation/ai-sdk-hook-bridge.test.tsindex 2e608974e..f34712196 100644--- a/packages/eve/src/instrumentation/ai-sdk-hook-bridge.test.ts+++ b/packages/eve/src/instrumentation/ai-sdk-hook-bridge.test.ts@@ -3,7 +3,7 @@ import { describe, expect, it, vi } from "vitest";import { createAiSdkHookBridge } from "#instrumentation/ai-sdk-hook-bridge.js";import {attemptIdempotencyKey,- createInstrumentationHooks,+ createInstrumentationHooks as createUnboundInstrumentationHooks,modelCallIdempotencyKey,type InstrumentationAttemptScope,type InstrumentationModelCallStartedEvent,@@ -23,10 +23,19 @@ const scope: InstrumentationAttemptScope = {turnId: "turn-1",};+function createInstrumentationHooks(+ ...args: Parameters<typeof createUnboundInstrumentationHooks>+): ReturnType<typeof createUnboundInstrumentationHooks> {+ return createUnboundInstrumentationHooks(...args).forTrace!({+ agentName: "test-agent",+ audience: "unknown",+ });+}+describe("createAiSdkHookBridge", () => {- it("withholds content when a bridge is not bound to a trace", async () => {+ it("does not publish when a bridge is not bound to a trace", async () => {const started = vi.fn();- const hooks = createInstrumentationHooks([+ const hooks = createUnboundInstrumentationHooks([{ events: { "model.call.started": started }, name: "default-policy" },]);const bridge = createAiSdkHookBridge({ ...scope, channelAudience: "public" }, hooks);@@ -41,7 +50,7 @@ describe("createAiSdkHookBridge", () => {},]);- expect(started.mock.calls[0]?.[0].input).toBeUndefined();+ expect(started).not.toHaveBeenCalled();});it("publishes normalized model lifecycle to every provider", async () => {diff --git a/packages/eve/src/instrumentation/channel-delivery.test.ts b/packages/eve/src/instrumentation/channel-delivery.test.tsindex 165b6f9cc..50e645312 100644--- a/packages/eve/src/instrumentation/channel-delivery.test.ts+++ b/packages/eve/src/instrumentation/channel-delivery.test.ts@@ -14,7 +14,7 @@ import {function bindHooks(hooks: InstrumentationRuntime["hooks"],ctx: ContextContainer,- agentName?: string,+ agentName = "test-agent",) {return bindInstrumentationRuntime({diff --git a/packages/eve/src/instrumentation/channel-delivery.ts b/packages/eve/src/instrumentation/channel-delivery.tsindex b38214116..19963e90c 100644--- a/packages/eve/src/instrumentation/channel-delivery.ts+++ b/packages/eve/src/instrumentation/channel-delivery.ts@@ -20,7 +20,7 @@ export interface ChannelDeliveryStartInstrumentation {readonly ctx: AlsContext;readonly delivery: DeliverHookPayload;readonly hooks: InstrumentationHooks | undefined;- readonly policyAgentName?: string;+ readonly policyAgentName: string;readonly rootSessionId: string;readonly sequence: number;readonly sessionId: string;@@ -45,9 +45,11 @@ export async function instrumentChannelDelivery(const type =`channel.delivery.${input.outcome}` as InstrumentationChannelDeliveryTerminalEvent["type"];for (const item of active) {+ const policyAgentName = item.policyAgentName ?? item.agentName;+ if (policyAgentName === undefined) continue;const hooks =input.hooks.forTrace?.({- agentName: item.policyAgentName,+ agentName: policyAgentName,audience: normalizeChannelAudience(item.delivery.channelAudience),channelType: item.channelType,}) ?? input.hooks;diff --git a/packages/eve/src/instrumentation/dispatch.ts b/packages/eve/src/instrumentation/dispatch.tsindex 47f777550..32de798b2 100644--- a/packages/eve/src/instrumentation/dispatch.ts+++ b/packages/eve/src/instrumentation/dispatch.ts@@ -43,7 +43,7 @@ export function createInstrumentationDispatcher(const providers = [...groups.serialBefore, ...groups.parallel, ...groups.serialAfter];const warnedPolicyFailures = new Set<InstrumentationProviderDefinition>();- const forTrace = (trace: TraceCaptureContext): InstrumentationHooks => {+ function forTrace(trace: TraceCaptureContext): InstrumentationHooks {const snapshots = new WeakMap<object, unknown>();const decisions = new Map(providers.map((provider) => [@@ -159,14 +159,11 @@ export function createInstrumentationDispatcher(};return { capturesContent, capturesInputs, capturesOutputs, forTrace, publish };- };+ }- let unboundHooks: InstrumentationHooks | undefined;let loggedUnboundPublish = false;return {- capturesContent: providers.some(- (provider) => provider.tracePolicy === undefined && provider.capture === "content",- ),+ capturesContent: false,forTrace,async publish(event) {if (!loggedUnboundPublish) {@@ -175,8 +172,6 @@ export function createInstrumentationDispatcher(eventType: event.type,});}- unboundHooks ??= forTrace({ audience: "unknown" });- await unboundHooks.publish(event);},};}diff --git a/packages/eve/src/instrumentation/lifecycle.test.ts b/packages/eve/src/instrumentation/lifecycle.test.tsindex 2eacee6ca..6cd61cc48 100644--- a/packages/eve/src/instrumentation/lifecycle.test.ts+++ b/packages/eve/src/instrumentation/lifecycle.test.ts@@ -5,7 +5,7 @@ import { deserializeContext, serializeContext } from "#context/serialize.js";import {actionIdempotencyKey,attemptIdempotencyKey,- createInstrumentationHooks,+ createInstrumentationHooks as createUnboundInstrumentationHooks,inputIdempotencyKey,modelCallIdempotencyKey,sessionIdempotencyKey,@@ -29,6 +29,15 @@ vi.mock("#internal/logging.js", () => ({formatError: (error: unknown) => error,}));+function createInstrumentationHooks(+ ...args: Parameters<typeof createUnboundInstrumentationHooks>+): ReturnType<typeof createUnboundInstrumentationHooks> {+ return createUnboundInstrumentationHooks(...args).forTrace!({+ agentName: "test-agent",+ audience: "unknown",+ });+}+const scope: InstrumentationAttemptScope = {attemptId: "session-1:turn-1:0:0",attemptIndex: 0,@@ -826,8 +835,12 @@ describe("trace policies", () => {it("defaults provider content to the audience-aware policy", () => {const hooks = createInstrumentationHooks([{ name: "provider" }]);- expect(hooks.forTrace?.({ audience: "public" }).capturesContent).toBe(true);- expect(hooks.forTrace?.({ audience: "private" }).capturesContent).toBe(false);+ expect(hooks.forTrace?.({ agentName: "weather", audience: "public" }).capturesContent).toBe(+ true,+ );+ expect(hooks.forTrace?.({ agentName: "weather", audience: "private" }).capturesContent).toBe(+ false,+ );});it("passes trace context to each provider policy", () => {@@ -848,9 +861,14 @@ describe("trace policies", () => {expect(tracePolicy).toHaveBeenCalledExactlyOnceWith(trace);});- it("evaluates unbound policies once with an unknown trace", async () => {+ it("does not dispatch providers before trace binding", async () => {const tracePolicy = vi.fn(() => true);- const hooks = createInstrumentationHooks([{ name: "provider", tracePolicy }]);+ const policyObserved = vi.fn();+ const defaultObserved = vi.fn();+ const hooks = createUnboundInstrumentationHooks([+ { events: { "turn.started": policyObserved }, name: "policy", tracePolicy },+ { events: { "turn.started": defaultObserved }, name: "default" },+ ]);await hooks.publish({idempotencyKey: turnIdempotencyKey("session-1", "turn-1"),@@ -860,18 +878,10 @@ describe("trace policies", () => {turnId: "turn-1",type: "turn.started",});- await hooks.publish({- idempotencyKey: turnIdempotencyKey("session-1", "turn-1"),- sessionId: "session-1",- turnId: "turn-1",- type: "turn.completed",- });- expect(tracePolicy).toHaveBeenCalledExactlyOnceWith({- agentName: undefined,- audience: "unknown",- channelType: undefined,- });+ expect(tracePolicy).not.toHaveBeenCalled();+ expect(policyObserved).not.toHaveBeenCalled();+ expect(defaultObserved).not.toHaveBeenCalled();});it("lets an explicit provider policy authorize private content", async () => {@@ -882,7 +892,7 @@ describe("trace policies", () => {name: "private-audit",tracePolicy: () => ({ emit: true, recordInputs: true, recordOutputs: false }),},- ]).forTrace!({ audience: "private" });+ ]).forTrace!({ agentName: "weather", audience: "private" });await hooks.publish({callId: "call-1",@@ -915,7 +925,7 @@ describe("trace policies", () => {name: "outputs",tracePolicy: () => ({ emit: true, recordInputs: false, recordOutputs: true }),},- ]).forTrace!({ audience: "public" });+ ]).forTrace!({ agentName: "weather", audience: "public" });await hooks.publish({idempotencyKey: "model-1",@@ -957,7 +967,7 @@ describe("trace policies", () => {name: "inputs-only",tracePolicy: () => ({ emit: true, recordInputs: true, recordOutputs: false }),},- ]).forTrace!({ audience: "public" });+ ]).forTrace!({ agentName: "weather", audience: "public" });await hooks.publish({error,@@ -972,7 +982,7 @@ describe("trace policies", () => {it("reports content capture only when an admitted provider requests it", () => {expect(- createInstrumentationHooks([+ createUnboundInstrumentationHooks([{name: "unbound",tracePolicy: () => ({ emit: true, recordInputs: true, recordOutputs: true }),@@ -980,10 +990,10 @@ describe("trace policies", () => {]).capturesContent,).toBe(false);expect(- createInstrumentationHooks([{ capture: "content", name: "legacy" }]).capturesContent,- ).toBe(true);+ createUnboundInstrumentationHooks([{ capture: "content", name: "legacy" }]).capturesContent,+ ).toBe(false);expect(- createInstrumentationHooks([+ createUnboundInstrumentationHooks([{capture: "content",name: "explicit-policy",@@ -992,8 +1002,10 @@ describe("trace policies", () => {]).capturesContent,).toBe(false);expect(- createInstrumentationHooks([{ name: "quiet" }]).forTrace!({ audience: "private" })- .capturesContent,+ createInstrumentationHooks([{ name: "quiet" }]).forTrace!({+ agentName: "weather",+ audience: "private",+ }).capturesContent,).toBe(false);expect(createInstrumentationHooks([@@ -1005,7 +1017,7 @@ describe("trace policies", () => {name: "also-quiet",tracePolicy: () => ({ emit: true, recordInputs: false, recordOutputs: false }),},- ]).forTrace!({ audience: "public" }).capturesContent,+ ]).forTrace!({ agentName: "weather", audience: "public" }).capturesContent,).toBe(false);expect(createInstrumentationHooks([@@ -1014,7 +1026,7 @@ describe("trace policies", () => {name: "loud",tracePolicy: () => ({ emit: true, recordInputs: true, recordOutputs: true }),},- ]).forTrace!({ audience: "public" }).capturesContent,+ ]).forTrace!({ agentName: "weather", audience: "public" }).capturesContent,).toBe(true);expect(createInstrumentationHooks({@@ -1024,7 +1036,7 @@ describe("trace policies", () => {tracePolicy: () => ({ emit: true, recordInputs: true, recordOutputs: true }),},],- }).forTrace!({ audience: "public" }).capturesContent,+ }).forTrace!({ agentName: "weather", audience: "public" }).capturesContent,).toBe(true);});@@ -1036,7 +1048,7 @@ describe("trace policies", () => {name: "dropped",tracePolicy: () => false,},- ]).forTrace!({ audience: "public" });+ ]).forTrace!({ agentName: "weather", audience: "public" });await hooks.publish({idempotencyKey: turnIdempotencyKey("session-1", "turn-1"),@@ -1067,8 +1079,8 @@ describe("trace policies", () => {tracePolicy: () => ({ emit: true, recordInputs: false, recordOutputs: false }),},]);- const hooks = unboundHooks.forTrace!({ audience: "public" });- unboundHooks.forTrace!({ audience: "private" });+ const hooks = unboundHooks.forTrace!({ agentName: "weather", audience: "public" });+ unboundHooks.forTrace!({ agentName: "weather", audience: "private" });await hooks.publish({idempotencyKey: turnIdempotencyKey("session-1", "turn-1"),@@ -1102,7 +1114,7 @@ describe("trace policies", () => {events: { "step.attempt.metadata": wantsContent },name: "content",},- ]);+ ]).forTrace!({ agentName: "weather", audience: "private" });const providerMetadata = {gateway: {cost: "0.01",@@ -1141,7 +1153,7 @@ describe("trace policies", () => {name: "content",tracePolicy: () => ({ emit: true, recordInputs: true, recordOutputs: true }),},- ]);+ ]).forTrace!({ agentName: "weather", audience: "private" });const error = { output: "private tool output", requestBody: "private request" };const actionScope = { ...scope };@@ -1208,7 +1220,7 @@ describe("trace policies", () => {},name: "content",},- ]);+ ]).forTrace!({ agentName: "weather", audience: "private" });const idempotencyKey = inputIdempotencyKey(scope.sessionId, scope.turnId, "request-1");await hooks.publish({@@ -1260,7 +1272,7 @@ describe("trace policies", () => {name: "content",},],- });+ }).forTrace!({ agentName: "weather", audience: "private" });const event = {idempotencyKey: toolCallIdempotencyKey(scope, "call-1", 0),diff --git a/packages/eve/src/instrumentation/lifecycle.ts b/packages/eve/src/instrumentation/lifecycle.tsindex 926396398..3e1de8b9f 100644--- a/packages/eve/src/instrumentation/lifecycle.ts+++ b/packages/eve/src/instrumentation/lifecycle.ts@@ -330,6 +330,7 @@ export type InstrumentationSessionTransitionEvent =export interface InstrumentationTurnStartedEvent {readonly type: "turn.started";+ readonly agentName?: string;readonly idempotencyKey: string;readonly parentLineage?: InstrumentationParentLineage;readonly parentTraceContext?: InstrumentationTraceContext;diff --git a/packages/eve/src/instrumentation/native-events.test.ts b/packages/eve/src/instrumentation/native-events.test.tsindex 6d1a30948..48a6f6b67 100644--- a/packages/eve/src/instrumentation/native-events.test.ts+++ b/packages/eve/src/instrumentation/native-events.test.ts@@ -51,6 +51,7 @@ describe("createInstrumentationHandleEvent", () => {channelName: "slack",deliveryId: "delivery-1",},+ policyAgentName: "weather",rootSessionId: "session-1",sequence: 0,sessionId: "session-1",diff --git a/packages/eve/src/instrumentation/prepare-trace-context.ts b/packages/eve/src/instrumentation/prepare-trace-context.tsindex ec8818d20..cf9239701 100644--- a/packages/eve/src/instrumentation/prepare-trace-context.ts+++ b/packages/eve/src/instrumentation/prepare-trace-context.ts@@ -63,6 +63,7 @@ export async function prepareTurnTraceContext(if (input.instrumentation?.prepareTurnTrace !== undefined) {try {prepared = await input.instrumentation.prepareTurnTrace({+ agentName: input.agentName,idempotencyKey: turnIdempotencyKey(input.sessionId, input.turnId),parentLineage: input.parentLineage,parentTraceContext: input.parentTraceContext,diff --git a/packages/eve/src/instrumentation/providers-otel-policy.test.ts b/packages/eve/src/instrumentation/providers-otel-policy.test.tsindex 41ccf141e..39d2fa49d 100644--- a/packages/eve/src/instrumentation/providers-otel-policy.test.ts+++ b/packages/eve/src/instrumentation/providers-otel-policy.test.ts@@ -51,9 +51,13 @@ describe("otel and authored provider composition", () => {}),});const runtime = finalizeInstrumentationProviders({ serviceName: "weather-agent" });+ const hooks = runtime.hooks.forTrace!({+ agentName: "weather-agent",+ audience: "private",+ });await contextStorage.run(new ContextContainer(), () =>- runtime.hooks.publish({+ hooks.publish({idempotencyKey: "model:session-1:turn-1:0:0:0",input: {instructions: "private instructions",diff --git a/packages/eve/src/instrumentation/providers.integration.test.ts b/packages/eve/src/instrumentation/providers.integration.test.tsindex 63c78600c..ae30e6000 100644--- a/packages/eve/src/instrumentation/providers.integration.test.ts+++ b/packages/eve/src/instrumentation/providers.integration.test.ts@@ -69,7 +69,8 @@ describe("authored instrumentation provider dispatch", () => {expect(order).toEqual(["first:setup", "first:setup-complete", "second:setup"]);const runtime = finalizeInstrumentationProviders({ serviceName: "weather" });- const publication = runtime.hooks.publish({+ const hooks = runtime.hooks.forTrace!({ agentName: "weather", audience: "unknown" });+ const publication = hooks.publish({idempotencyKey: turnIdempotencyKey("session-1", "turn-1"),rootSessionId: "session-1",sequence: 0,diff --git a/packages/eve/src/instrumentation/providers.test.ts b/packages/eve/src/instrumentation/providers.test.tsindex 89a9f8671..83e1f03df 100644--- a/packages/eve/src/instrumentation/providers.test.ts+++ b/packages/eve/src/instrumentation/providers.test.ts@@ -208,7 +208,9 @@ describe("finalizeInstrumentationProviders", () => {await register("rows", defineInstrumentation({ events: { "turn.started": started } }));const runtime = finalizeInstrumentationProviders({ serviceName: "weather-agent" });- await runtime.hooks.publish(turnStarted);+ await runtime.hooks.forTrace!({ agentName: "weather-agent", audience: "unknown" }).publish(+ turnStarted,+ );expect(runtime.instrumentationProviders).toBe(true);expect(started).toHaveBeenCalledOnce();@@ -225,7 +227,9 @@ describe("finalizeInstrumentationProviders", () => {const runtime = finalizeInstrumentationProviders({ serviceName: "weather-agent" });- expect(runtime.hooks.forTrace?.({ audience: "private" }).capturesContent).toBe(expected);+ expect(+ runtime.hooks.forTrace?.({ agentName: "weather", audience: "private" }).capturesContent,+ ).toBe(expected);},);@@ -240,7 +244,9 @@ describe("finalizeInstrumentationProviders", () => {const runtime = finalizeInstrumentationProviders({ serviceName: "weather-agent" });- expect(runtime.hooks.forTrace?.({ audience: "private" }).capturesContent).toBe(true);+ expect(+ runtime.hooks.forTrace?.({ agentName: "weather", audience: "private" }).capturesContent,+ ).toBe(true);});it("still runs execution when no destination was declared", async () => {diff --git a/packages/eve/src/instrumentation/runtime.test.ts b/packages/eve/src/instrumentation/runtime.test.tsindex aa48cdf10..3d7e163e9 100644--- a/packages/eve/src/instrumentation/runtime.test.ts+++ b/packages/eve/src/instrumentation/runtime.test.ts@@ -18,7 +18,11 @@ import {import { ContextAgentTraceStateStore } from "#tracing/agent-trace-context-store.js";import type { TraceCapturePolicy } from "#tracing/otel-declaration.js";-const boundSession = { rootSessionId: "session-1", sessionId: "session-1" };+const boundSession = {+ agentName: "test-agent",+ rootSessionId: "session-1",+ sessionId: "session-1",+};function createRuntime(hooks: InstrumentationHooks,@@ -278,6 +282,7 @@ describe("bindSessionInstrumentation", () => {});const instrumentation = bindSessionInstrumentation({+ agentName: "test-agent",ctx,rootSessionId: "session-1",sessionId: "session-1",@@ -298,6 +303,7 @@ describe("bindSessionInstrumentation", () => {);const ctx = createContext();const instrumentation = bindSessionInstrumentation({+ agentName: "test-agent",ctx,rootSessionId: "session-1",sessionId: "session-1",@@ -323,6 +329,7 @@ describe("bindSessionInstrumentation", () => {const ctx = createContext();ctx.set(OtelTraceEnabledKey, false);const instrumentation = bindSessionInstrumentation({+ agentName: "test-agent",ctx,rootSessionId: "session-1",sessionId: "session-1",diff --git a/packages/eve/src/instrumentation/runtime.ts b/packages/eve/src/instrumentation/runtime.tsindex 57064aaa5..d83e076c5 100644--- a/packages/eve/src/instrumentation/runtime.ts+++ b/packages/eve/src/instrumentation/runtime.ts@@ -136,7 +136,7 @@ export interface PreparedInstrumentationAttempt {export type InstrumentationAttempt = InstrumentationAttemptScope;export interface BoundInstrumentationSession {- readonly agentName?: string;+ readonly agentName: string;readonly rootSessionId: string;readonly sessionId: string;}@@ -470,7 +470,7 @@ export function bindInstrumentationRuntime(}export function bindSessionInstrumentation(input: {- readonly agentName?: string;+ readonly agentName: string;readonly ctx: ContextContainer;readonly rootSessionId: string;readonly sessionId: string;@@ -483,7 +483,7 @@ export function bindSessionInstrumentation(input: {}export function initializeSessionInstrumentation(input: {- readonly agentName?: string;+ readonly agentName: string;readonly ctx: ContextContainer;readonly parentTraceContext?: SessionTraceContext;}): void {@@ -502,7 +502,7 @@ export function initializeSessionInstrumentation(input: {}function allocateSessionTraceSeed(input: {- readonly agentName?: string;+ readonly agentName: string;readonly audience: ReturnType<typeof normalizeChannelAudience>;readonly channelType?: string;readonly parentTraceContext?: SessionTraceContext;@@ -536,7 +536,7 @@ function allocateSessionTraceSeed(input: {function resolveStepInstrumentationDecision(settings: OtelHarnessSettings | undefined,- agentName: string | undefined,+ agentName: string,channel: ChannelInstrumentationProjection | undefined,traceSeed: SessionTraceSeed | undefined,persisted: InstrumentationDecision | undefined,diff --git a/packages/eve/src/shared/trace-policy.ts b/packages/eve/src/shared/trace-policy.tsindex 6e1b6ca39..a46a4bb63 100644--- a/packages/eve/src/shared/trace-policy.ts+++ b/packages/eve/src/shared/trace-policy.ts@@ -9,7 +9,7 @@ import {export type InstrumentationCapture = "content" | "metadata";export interface TraceCaptureContext {- readonly agentName?: string;+ readonly agentName: string;readonly audience: ChannelAudience;readonly channelType?: string;}diff --git a/packages/eve/src/tracing/agent-otel-provider.test.ts b/packages/eve/src/tracing/agent-otel-provider.test.tsindex 0f8b589e0..5799a3bf3 100644--- a/packages/eve/src/tracing/agent-otel-provider.test.ts+++ b/packages/eve/src/tracing/agent-otel-provider.test.ts@@ -89,7 +89,10 @@ function createRuntime(};if (tracePolicy !== null) agentOtelInput.tracePolicy = tracePolicy;const agentOtel = createAgentOtelInstrumentation(agentOtelInput);- const hooks = createInstrumentationHooks([agentOtel.hook]);+ const hooks = createInstrumentationHooks([agentOtel.hook]).forTrace!({+ agentName: "weather",+ audience: "public",+ });return {exporter,hooks,@@ -549,6 +552,7 @@ describe("createAgentOtelInstrumentation", () => {await contextStorage.run(ctx, async () => {await runtime.hooks.publish({+ agentName: "weather",delivery,idempotencyKey,rootSessionId: "session-1",@@ -1620,7 +1624,10 @@ describe("createAgentOtelInstrumentation", () => {stateStore: new InMemoryAgentTraceStateStore(),tracer: provider.getTracer("eve.agent"),});- const hooks = createInstrumentationHooks([agentOtel.hook]);+ const hooks = createInstrumentationHooks([agentOtel.hook]).forTrace!({+ agentName: "weather",+ audience: "public",+ });await emitAttempt({hooks,runInContext: agentOtel.runInContext,diff --git a/packages/eve/src/tracing/agent-otel-session-context.ts b/packages/eve/src/tracing/agent-otel-session-context.tsindex f7eeb0841..a45036d60 100644--- a/packages/eve/src/tracing/agent-otel-session-context.ts+++ b/packages/eve/src/tracing/agent-otel-session-context.ts@@ -156,7 +156,7 @@ export function createAgentOtelSessionContext(}const session = await ensureSessionContext({- agentName: undefined,+ agentName: event.agentName,channelAudience: "unknown",channelKind: undefined,idempotencyKey: sessionIdempotencyKey(event.sessionId),@@ -222,6 +222,9 @@ function resolveSessionTraceDecision(if (event.parentTraceContext !== undefined) {return resolveTracePolicyDecision(isSampledTrace(event.parentTraceContext), audience);}+ if (event.agentName === undefined) {+ return policy === undefined ? resolveTracePolicyDecision(true, audience) : { action: "drop" };+ }// The tool loop can evaluate the same policy before this first-session// preparation path; the persisted decision removes that window on replay.return resolveTracePolicy(policy, {diff --git a/packages/eve/src/tracing/install-instrumentation-runtime.test.ts b/packages/eve/src/tracing/install-instrumentation-runtime.test.tsindex 08fb7495c..477fb2cd4 100644--- a/packages/eve/src/tracing/install-instrumentation-runtime.test.ts+++ b/packages/eve/src/tracing/install-instrumentation-runtime.test.ts@@ -99,9 +99,10 @@ describe("installInstrumentationRuntime", () => {serviceName: "weather",});const idempotencyKey = turnIdempotencyKey("session-1", "turn-1");+ const hooks = runtime.hooks.forTrace!({ agentName: "weather", audience: "unknown" });await contextStorage.run(new ContextContainer(), async () => {- await runtime.hooks.publish({+ await hooks.publish({idempotencyKey,rootSessionId: "session-1",sequence: 0,@@ -109,7 +110,7 @@ describe("installInstrumentationRuntime", () => {turnId: "turn-1",type: "turn.started",});- await runtime.hooks.publish({+ await hooks.publish({idempotencyKey,sessionId: "session-1",turnId: "turn-1",diff --git a/packages/eve/src/tracing/local-instrumentation-runtime.scenario.test.ts b/packages/eve/src/tracing/local-instrumentation-runtime.scenario.test.tsindex becefc65e..27c6fb94c 100644--- a/packages/eve/src/tracing/local-instrumentation-runtime.scenario.test.ts+++ b/packages/eve/src/tracing/local-instrumentation-runtime.scenario.test.ts@@ -59,16 +59,17 @@ describe("local instrumentation runtime", () => {};const delivery = runtimeTrace.getTracer("workflow").startSpan("workflow.delivery");const activeContext = runtimeTrace.setSpan(COMPILED_ROOT_CONTEXT, delivery);+ const hooks = runtime.hooks.forTrace!({ agentName: "weather", audience: "unknown" });const exerciseRuntime = async () => {- await runtime.hooks.publish({+ await hooks.publish({agentName: "weather",idempotencyKey: sessionIdempotencyKey("session-1"),rootSessionId: "session-1",sessionId: "session-1",type: "session.started",});- await runtime.hooks.publish({+ await hooks.publish({idempotencyKey: turnIdempotencyKey("session-1", "turn-1"),rootSessionId: "session-1",sequence: 0,@@ -76,7 +77,7 @@ describe("local instrumentation runtime", () => {turnId: "turn-1",type: "turn.started",});- const bridge = createAiSdkHookBridge(scope, runtime.hooks, runtime.runInContext);+ const bridge = createAiSdkHookBridge(scope, hooks, runtime.runInContext);Reflect.apply(bridge.onStart!, bridge, [{callId: "call-1",@@ -115,7 +116,7 @@ describe("local instrumentation runtime", () => {},]);const actionKey = actionIdempotencyKey("session-1", "turn-1", "tool-1");- await runtime.hooks.publish({+ await hooks.publish({callId: "tool-1",idempotencyKey: actionKey,input: {},@@ -149,26 +150,26 @@ describe("local instrumentation runtime", () => {toolOutput: { output: { temperature: 72 }, type: "tool-result" },},]);- await runtime.hooks.publish({+ await hooks.publish({idempotencyKey: actionKey,outcome: "completed",output: { output: { temperature: 72 }, type: "result" },scope,type: "action.completed",});- await runtime.hooks.publish({+ await hooks.publish({idempotencyKey: attemptIdempotencyKey(scope),scope,type: "step.attempt.completed",});- await runtime.hooks.publish({+ await hooks.publish({idempotencyKey: turnIdempotencyKey("session-1", "turn-1"),sessionId: "session-1",turnId: "turn-1",type: "turn.completed",});// Settling the turn emits the turn span with the pre-allocated id.- await runtime.hooks.publish({+ await hooks.publish({idempotencyKey: sessionIdempotencyKey("session-1"),sessionId: "session-1",turnId: "turn-1",diff --git a/packages/eve/src/tracing/local-traces.test.ts b/packages/eve/src/tracing/local-traces.test.tsindex f9ca53da3..22f7e3cce 100644--- a/packages/eve/src/tracing/local-traces.test.ts+++ b/packages/eve/src/tracing/local-traces.test.ts@@ -107,6 +107,7 @@ describe("localTracePolicy", () => {] as const)("accepts the %s audience: %s", (audience, accepted) => {expect(localTracePolicy({+ agentName: "weather",audience,}),).toBe(accepted);diff --git a/packages/eve/src/tracing/sampled-trace.test.ts b/packages/eve/src/tracing/sampled-trace.test.tsindex dd7600a54..7f9be14c3 100644--- a/packages/eve/src/tracing/sampled-trace.test.ts+++ b/packages/eve/src/tracing/sampled-trace.test.ts@@ -58,7 +58,7 @@ describe("resolveTracePolicyDecision", () => {() => {throw new Error("boom");},- { audience: "public" },+ { agentName: "weather", audience: "public" },),).toEqual({ action: "drop" });});@@ -69,7 +69,7 @@ describe("resolveTracePolicyDecision", () => {() => {throw new Error("policy failed");},- { audience: "public" },+ { agentName: "weather", audience: "public" },() => {throw new Error("reporting failed");},@@ -82,7 +82,7 @@ describe("resolveTracePolicyDecision", () => {["private", false],["unknown", false],] as const)("emits the default %s trace with the expected content", (audience, content) => {- expect(resolveTracePolicy(undefined, { audience })).toEqual({+ expect(resolveTracePolicy(undefined, { agentName: "weather", audience })).toEqual({action: "record",recordInputs: content,recordOutputs: content,diff --git a/packages/eve/test/scenarios/compiled-artifacts-bootstrap.scenario.test.ts b/packages/eve/test/scenarios/compiled-artifacts-bootstrap.scenario.test.tsindex 05ea736bd..40596675b 100644--- a/packages/eve/test/scenarios/compiled-artifacts-bootstrap.scenario.test.ts+++ b/packages/eve/test/scenarios/compiled-artifacts-bootstrap.scenario.test.ts@@ -213,7 +213,9 @@ describe("writeCompiledArtifactsFiles", () => {]);const providers = getInstrumentationProviders();expect(providers.map((entry) => entry.slot)).toEqual(["local", "otel"]);- expect(providers[0]?.provider.tracePolicy?.({ audience: "public" })).toEqual({+ expect(+ providers[0]?.provider.tracePolicy?.({ agentName: "weather", audience: "public" }),+ ).toEqual({emit: true,recordInputs: true,recordOutputs: false,diff --git a/research/channel-audience-content-policy.md b/research/channel-audience-content-policy.mdindex 4ae21835e..9a387b3f7 100644--- a/research/channel-audience-content-policy.md+++ b/research/channel-audience-content-policy.md@@ -32,7 +32,7 @@ The process-wide declaration owns trace creation:```tsinterface TraceCaptureContext {- readonly agentName?: string;+ readonly agentName: string;readonly audience: ChannelAudience;readonly channelType?: string;}