The Open Framework for Building Agents
fix(eve): classify recalled memory as input (#3281)
Chad Hietala15e18d6d6b81
diff --git a/.changeset/memory-record-input-policy.md b/.changeset/memory-record-input-policy.mdnew file mode 100644index 000000000..534104f6b--- /dev/null+++ b/.changeset/memory-record-input-policy.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Treat recalled memory records as model input content when applying instrumentation trace policies.diff --git a/docs/guides/instrumentation.md b/docs/guides/instrumentation.mdindex d9d497f62..d8a0da99c 100644--- a/docs/guides/instrumentation.md+++ b/docs/guides/instrumentation.md@@ -50,8 +50,8 @@ Any OTel-compatible backend works (Braintrust, PostHog, Sentry, Raindrop, Arize,Three more fields control what eve and the AI SDK record inside those spans (see the AI SDK's [telemetry reference](https://ai-sdk.dev/docs/ai-sdk-core/telemetry)):-- `recordInputs` records full message history on each step span. It defaults to `false`; set it to `true` to include input content.-- `recordOutputs` records model outputs and recalled memory records. It defaults to `false`; set it to `true` to include output content.+- `recordInputs` records full message history on each step span and recalled records on memory spans. It defaults to `false`; set it to `true` to include input content.+- `recordOutputs` records model outputs. It defaults to `false`; set it to `true` to include output content.- `functionId` overrides the function name on spans (defaults to the agent name).eve records metadata without model, tool, or memory-record content by default. Enable either content category only after reviewing the exporter and its data-retention path.@@ -152,7 +152,7 @@ eve records [OpenTelemetry GenAI memory spans](https://opentelemetry.io/docs/speEvery memory span includes `gen_ai.operation.name` and `gen_ai.memory.store.id`. The store ID is eve's opaque `memory.scope.key`, which identifies the resolved scope without exposing the namespace or scope values. Recall spans set `gen_ai.memory.record.count` to their result count.-`gen_ai.memory.records` contains recalled record content only when `recordOutputs` is enabled. eve does not set `gen_ai.memory.query.text` because a memory provider receives structured conversation messages, not a standalone search-query string. The `agent.memory.slot` and `agent.memory.phase` attributes identify the eve slot and lifecycle boundary without adding either to the span name.+`gen_ai.memory.records` contains recalled record content only when `recordInputs` is enabled. eve classifies recalled records as input content because they become part of the model context. eve does not set `gen_ai.memory.query.text` because a memory provider receives structured conversation messages, not a standalone search-query string. The `agent.memory.slot` and `agent.memory.phase` attributes identify the eve slot and lifecycle boundary without adding either to the span name.## Agent trace contractdiff --git a/packages/eve/src/instrumentation/content.test.ts b/packages/eve/src/instrumentation/content.test.tsindex 5e6975ebe..a96a54b17 100644--- a/packages/eve/src/instrumentation/content.test.ts+++ b/packages/eve/src/instrumentation/content.test.ts@@ -77,6 +77,37 @@ describe("withInstrumentationDecision", () => {);});+ it("treats recalled memory records as inputs", () => {+ const completed = {+ idempotencyKey: "memory-1",+ operationName: "search_memory",+ outputRecords: [{ content: "The user prefers dark mode.", id: "preference" }],+ phase: "turn.started",+ recordCount: 1,+ rootSessionId: "session-1",+ sessionId: "session-1",+ slot: "profile",+ storeId: "memscope1_scope",+ turnId: "turn-1",+ type: "memory.operation.completed",+ } as const;++ expect(+ withInstrumentationDecision(completed, {+ action: "record",+ recordInputs: true,+ recordOutputs: false,+ }),+ ).toBe(completed);+ expect(+ withInstrumentationDecision(completed, {+ action: "record",+ recordInputs: false,+ recordOutputs: true,+ }),+ ).toEqual(expect.objectContaining({ outputRecords: undefined }));+ });+it("reduces provider metadata to structural output when outputs are disabled", () => {const projected = withInstrumentationDecision({diff --git a/packages/eve/src/instrumentation/content.ts b/packages/eve/src/instrumentation/content.tsindex e94fb0ca5..9fe7b8545 100644--- a/packages/eve/src/instrumentation/content.ts+++ b/packages/eve/src/instrumentation/content.ts@@ -51,7 +51,7 @@ export function withInstrumentationDecision(case "model.call.completed":return decision.recordOutputs ? event : Object.freeze({ ...event, content: undefined });case "memory.operation.completed":- return decision.recordOutputs ? event : Object.freeze({ ...event, outputRecords: undefined });+ return decision.recordInputs ? event : Object.freeze({ ...event, outputRecords: undefined });case "step.attempt.metadata":return decision.recordOutputs? eventdiff --git a/packages/eve/src/instrumentation/memory.ts b/packages/eve/src/instrumentation/memory.tsindex ca47cbf42..e6f5af31e 100644--- a/packages/eve/src/instrumentation/memory.ts+++ b/packages/eve/src/instrumentation/memory.ts@@ -44,7 +44,7 @@ export interface InstrumentationMemoryOperationCompletedEvent extends Instrumentreadonly type: "memory.operation.completed";/** The number of records the operation returned or changed, when known. */readonly recordCount?: number;- /** Content. Absent unless this provider's trace policy records outputs. */+ /** Content. Absent unless this provider's trace policy records inputs. */readonly outputRecords?: readonly InstrumentationMemoryRecord[];}diff --git a/packages/eve/src/tracing/content-attributes.test.ts b/packages/eve/src/tracing/content-attributes.test.tsindex 1a5c150c8..626590d6a 100644--- a/packages/eve/src/tracing/content-attributes.test.ts+++ b/packages/eve/src/tracing/content-attributes.test.ts@@ -73,17 +73,17 @@ describe("withoutDeclinedContent", () => {expect(attributes).toEqual(ATTRIBUTES);});- it("redacts recalled memory records as output content", () => {+ it("redacts recalled memory records as input content", () => {const searched = {"gen_ai.memory.records": '[{"content":"Private preference"}]',"gen_ai.operation.name": "search_memory",};- expect(- withoutDeclinedContent(searched, { recordInputs: false, recordOutputs: true }),- ).toBeUndefined();- expect(withoutDeclinedContent(searched, { recordInputs: true, recordOutputs: false })).toEqual({+ expect(withoutDeclinedContent(searched, { recordInputs: false, recordOutputs: true })).toEqual({"gen_ai.operation.name": "search_memory",});+ expect(+ withoutDeclinedContent(searched, { recordInputs: true, recordOutputs: false }),+ ).toBeUndefined();});});diff --git a/packages/eve/src/tracing/content-attributes.ts b/packages/eve/src/tracing/content-attributes.tsindex 244c12bfc..bd5044d4e 100644--- a/packages/eve/src/tracing/content-attributes.ts+++ b/packages/eve/src/tracing/content-attributes.ts@@ -25,6 +25,7 @@ const INPUT_CONTENT_ATTRIBUTES: ReadonlySet<string> = new Set(["ai.value","ai.values","gen_ai.input.messages",+ "gen_ai.memory.records","gen_ai.system_instructions","gen_ai.tool.call.arguments","gen_ai.tool.definitions",@@ -50,7 +51,6 @@ const OUTPUT_CONTENT_ATTRIBUTES: ReadonlySet<string> = new Set(["ai.response.tool_results","ai.toolCall.args","ai.toolCall.result",- "gen_ai.memory.records","gen_ai.output.messages","gen_ai.tool.call.result",]);