Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

12.0 KB
Raw Blame

issue: https://github.com/vercel/eve/issues/2331 status: implemented last_updated: "2026-10-15"

Audience-aware trace content policy

Summary

Messaging agents need different trace behavior for public and private conversations. Public messages may be traced with model and tool content; private conversations should not produce traces unless an author explicitly admits them. Zero-config local tracing additionally retains unclassified HTTP/TUI sessions for debugging.

This design adds a fail-closed audience(input) classification hook to channels, persists one framework-owned conversation context, classifies built-in messaging channels from durable platform state, and separates the process-wide trace gate from each destination's ordered export pipeline.

Channel contract

Channels declare a synchronous audience(input) hook. It runs after route authentication and receives channel state, the authenticated principal, channel identity, run mode, and deployment environment:

type ChannelAudience = "public" | "private" | "unknown";

interface AudienceInput<TState> {
  readonly state: TState;
  readonly auth: AudiencePrincipal | null;
  readonly channel: { readonly kind: InstrumentationChannelKind; readonly name?: string };
  readonly mode: RunMode;
  readonly environment: "development" | "preview" | "production";
}

The hook is optional for authored channels. eve normalizes absent, malformed, throwing, asynchronous, and unsupported results to unknown. Built-in channels classify only from platform evidence already captured during dispatch; ambiguous and proactive destinations remain unknown rather than performing observability-only network requests. Proactive Slack receive / ctx.send targets may optionally supply audience state when the caller already knows channel visibility, for example a webhook that classified the Slack destination before handoff. metadata(state) returns custom observability fields only.

The framework builds one ConversationContext when a session is created and persists it under eve.conversation:

interface ConversationContext {
  readonly channel: { readonly kind: InstrumentationChannelKind; readonly name?: string };
  readonly audience: ChannelAudience;
  readonly mode: RunMode;
  readonly environment: "development" | "preview" | "production";
  readonly principalType: string;
}

The normalized audience is exported as agent.channel.audience only on each agent.session window. Durable eve state and an internal OpenTelemetry context key make the same value available to descendant export policies without duplicating a public attribute onto every span. Local subagents inherit the parent audience. A remote agent with principal forwarding propagates the immutable origin audience and the current hop's effective directional ceiling through one eve.audience W3C Baggage member. The receiver accepts it only with the same trustedForwarders decision that admitted the principal, then intersects it with its own process policy. Every later hop forwards that intersection; malformed and mixed-version assertions become metadata-only.

Public tracing API

This surface is available only when experimental.instrumentationProviders is enabled.

The process-wide declaration owns trace creation:

type TraceCaptureContext = {
  readonly agentName: string;
} & ConversationContext;
}

type TracePolicyDecision =
  | { readonly emit: false }
  | {
      readonly emit: true;
      readonly recordInputs: boolean;
      readonly recordOutputs: boolean;
    };

type TraceCapturePolicy = (trace: TraceCaptureContext) => TracePolicyDecision | boolean;

interface OtelOptions {
  // Other process-wide OTel settings are unchanged.
  readonly tracePolicy?: TraceCapturePolicy;
}

interface ProviderDefinition {
  readonly tracePolicy?: TraceCapturePolicy;
}

declare function otel(options?: OtelOptions): OtelDeclaration;

The otel() trace decision is a process-wide OTel ceiling. Each local delivery is intersected with its own audience classification. An accepted remote ceiling is instead intersected with the receiver policy evaluated against the immutable origin audience, permitting private content only when both sides explicitly approve it. Destination settings may narrow the result further. A provider's defineInstrumentation({ tracePolicy }) decision is independent: false skips that provider, true uses audience-aware content, and an explicit emitted decision authorizes its input and output directions even for private channels. An omitted provider policy uses the default audience-aware behavior.

Agent Runs and local traces expose the managed export policy:

interface SpanExportContext {
  readonly attributes: Readonly<Record<string, unknown>>;
  readonly audience: ChannelAudience;
  readonly name: string;
  readonly spanId: string;
  readonly traceId: string;
}

type SpanExportDecision =
  /** @deprecated Return `{ emit: boolean }` instead. */
  | boolean
  | { readonly emit: boolean }
  | {
      readonly redact: true;
      readonly inputs?: boolean;
      readonly outputs?: boolean;
    };

type SpanAttributeDecision =
  | { readonly emit: boolean }
  | {
      readonly replace: true;
      readonly value:
        | string
        | number
        | boolean
        | readonly string[]
        | readonly number[]
        | readonly boolean[];
    };

interface SpanExportPolicy {
  readonly span?: (span: SpanExportContext) => SpanExportDecision;
  readonly attribute?: (input: {
    readonly key: string;
    readonly span: SpanExportContext;
    readonly value: unknown;
  }) => SpanAttributeDecision;
}

interface ManagedTraceOptions {
  readonly exportPolicy?: SpanExportPolicy | readonly SpanExportPolicy[];
}

declare function agentRuns(options?: ManagedTraceOptions): OtelIntegration;
declare function localTraces(options?: ManagedTraceOptions): OtelIntegration;

A span callback can return { redact: true, inputs: true }, { redact: true, outputs: true }, or both directions together. The direction fields accept booleans, but at least one must resolve to true; otherwise the span is dropped. Input redaction removes known prompt, instruction, document, and tool-argument attributes. Output redaction removes known response, reasoning, embedding, ranking, and tool-result attributes, plus exception details, event attributes, and status messages. A redaction decision implies emission and does not mutate the shared OpenTelemetry span; each destination receives a filtered facade.

exportPolicy accepts one policy or an array applied in declaration order. A later span or attribute policy sees the facade produced by earlier redactors. A span callback returning { emit: false } removes that span from one destination without suppressing the rest of its trace. Attribute policies run once for each attribute still visible at their stage.

For example, this retains every conversation while capturing content only for public audiences:

// agent/instrumentation/otel.ts
export default otel({
  tracePolicy: ({ audience, environment }) => ({
    emit: true,
    recordInputs: audience === "public" || environment === "development",
    recordOutputs: audience === "public" || environment === "development",
  }),
});

// agent/instrumentation/agent-runs.ts
export default agentRuns({
  exportPolicy: [
    {
      span: ({ name }) => ({ emit: name !== "internal.cache.refresh" }),
      attribute: ({ key }) =>
        key === "user.email" ? { replace: true, value: "[redacted]" } : { emit: true },
    },
    {
      span: ({ audience }) =>
        audience === "public" ? { emit: true } : { redact: true, inputs: true, outputs: true },
    },
  ],
});

Defaults and ordering

The default authored and production head policy is equivalent to:

({ audience, environment }) => ({
  emit: true,
  recordInputs: audience === "public" || environment === "development",
  recordOutputs: audience === "public" || environment === "development",
});
Audience Development content Preview and production content
public Yes Yes
private Yes No
unknown Yes No

An explicit provider policy can authorize content for any audience. The OTel policy remains subject to its process-wide audience ceiling.

The default policy for local tracing for eve dev is equivalent to:

() => true,

This admits conversations classified as private to the local spool without changing the persisted conversation audience or forwarded origin audience. Because local tracing runs in development, every emitted trace uses the development content default.

The runtime order is:

  1. Build and persist the conversation context, deriving and normalizing the channel audience once.
  2. Evaluate the process-wide tracePolicy before creating agent.session.
  3. For accepted traces, capture complete eve and AI SDK spans.
  4. Run each managed destination's export policy pipeline in declaration order. Custom integrations run their declared span processors.
  5. Hand the resulting facade to that destination's processors or exporter.

The lifecycle bus separately evaluates each instrumentation provider's policy against the same agent and channel context, skips rejected providers, and applies directional content projection before invoking accepted handlers.

There is no implicit content redaction after a custom trace policy admits an audience. Redaction occurs only when an export policy returns a redaction decision.

Policies fail closed at their boundary: a throwing trace policy rejects the trace, a throwing span policy drops the span, a malformed or directionless redaction decision drops the span, and a throwing or malformed attribute policy drops the attribute. Missing, malformed, or conflicting audience evidence normalizes to unknown.

Workflow retention alignment

At session creation, the resolved process-wide trace decision also determines the default Workflow retention preference. Full input and output capture leaves the World's default unchanged; dropped traces, metadata-only capture, and directional capture request experimental_retention: 0. Workflow cannot purge directions independently. The audience-aware default applies even without an installed OTel destination.

An explicit experimental.workflow.retention overrides this derivation: "default" preserves completed-session reads independently of tracing, and 0 always requests deletion. The resolved value travels in session state and owner checkpoints, so handoff does not recompute it under a later deployment's policy. Subagents derive their own value from their resolved inherited trace decision unless they author an override. Destination export policies and lifecycle providers remain independent.

This requests World-enforced deletion at the terminal run boundary, not redaction while running. It removes durable session payloads and streams, so completed transcripts can return 410 session_expired. Records and attributes (including session titles), external telemetry, and tool-owned storage remain. Worlds older than spec version 4 reject 0; version 4 Worlds without retention support keep the data.

Before serving a session stream, eve checks the run's payload-free expiry metadata alongside its stream tail. A World can retain chunk records after purging their contents, so a nonempty tail alone cannot establish readability. Expired metadata produces 410 session_expired before response headers are sent.

Compatibility

Instrumentation providers deprecate the experimental capture field in favor of tracePolicy; "content" and "metadata" are mapped to equivalent fixed policies while integrations migrate. EVE_TRACES_CONTENT=off prepends a full-content redaction policy for local traces.

Filtering remains a span-processor responsibility because local trace persistence and authored processors are processors rather than uniform exporters. Keeping the filtering boundary immediately above each destination prevents one destination's policy from mutating what another destination receives.