Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): keep memory tools replayable when history holds non-JSON values (#4309)

e0-gh-vercel-connect[bot]de6b7e1c5ee9
diff --git a/.changeset/memory-tool-replay-history.md b/.changeset/memory-tool-replay-history.md
new file mode 100644
index 000000000..100482f43
--- /dev/null
+++ b/.changeset/memory-tool-replay-history.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Memory provider tools now survive a mid-turn restart when the turn's history holds non-JSON tool results, such as dates. eve no longer snapshots history into each tool's replay state, so a replayed `tools()` call receives empty `messages`.
diff --git a/docs/memory/custom-provider.md b/docs/memory/custom-provider.md
index 3eb281ec1..0dd16a95a 100644
--- a/docs/memory/custom-provider.md
+++ b/docs/memory/custom-provider.md
@@ -143,7 +143,9 @@ authored tools.
A tool closes over the locked scope for the current turn, so it cannot be
redirected to another tenant or caller by the model. eve keeps each tool
-callback replayable after a process restart or redeployment.
+callback replayable after a process restart or redeployment. On replay, eve
+calls `tools()` again with the captured `memory`, `turn`, and session context,
+but with empty `messages`, so a tool's identity must not depend on history.
## Lifecycle
diff --git a/packages/eve/src/context/memory-tools.test.ts b/packages/eve/src/context/memory-tools.test.ts
index dfe294f0f..f7b4bebbd 100644
--- a/packages/eve/src/context/memory-tools.test.ts
+++ b/packages/eve/src/context/memory-tools.test.ts
@@ -147,6 +147,51 @@ describe("memory provider tools", () => {
});
});
+ it("rebinds after a restart when mid-turn history holds non-JSON values", async () => {
+ const ctx = createContext("user_1");
+ const compiledResolver = resolver(() => 1);
+ await contextStorage.run(
+ ctx,
+ async () =>
+ await dispatchDynamicToolEvent({
+ ctx,
+ event,
+ messages: [{ content: "hello", role: "user" }],
+ resolvers: [compiledResolver],
+ }),
+ );
+ clearDurableDynamicCallbacks(ctx.require(SessionIdKey));
+
+ // A fresh process resumes mid-turn: history now carries this turn's tool
+ // results, which are durable values rather than plain JSON.
+ await rebindMissingCompiledDynamicToolCallbacks({
+ ctx,
+ event,
+ messages: [
+ { content: "hello", role: "user" },
+ {
+ content: [
+ {
+ output: { type: "json", value: { createdAt: new Date(0) } as never },
+ toolCallId: "call_0",
+ toolName: "lookup",
+ type: "tool-result",
+ },
+ ],
+ role: "tool",
+ },
+ ],
+ resolvers: [compiledResolver],
+ });
+
+ const [replayed] = buildDynamicTools(ctx);
+ const output = await contextStorage.run(
+ ctx,
+ async () => await replayed?.execute?.({}, { messages: [], toolCallId: "call_1" }),
+ );
+ expect(output).toBe("1:user_1");
+ });
+
it("omits tools when the provider has no tool factory", async () => {
const ctx = createContext("user_1");
const definition = defineMemory({
diff --git a/packages/eve/src/context/memory-tools.ts b/packages/eve/src/context/memory-tools.ts
index 8650e687d..00693ae0b 100644
--- a/packages/eve/src/context/memory-tools.ts
+++ b/packages/eve/src/context/memory-tools.ts
@@ -67,7 +67,12 @@ function createProviderToolCallbacks(input: {
readonly key: string;
readonly tool: MemoryToolSet[string];
}) {
- const closure = parseJsonObject({ context: input.context, key: input.key });
+ // History is not part of a tool's identity and can hold durable non-JSON
+ // values (dates, bytes) once a turn has run tools, so replay omits it.
+ const closure = parseJsonObject({
+ context: { ...input.context, messages: [] },
+ key: input.key,
+ });
const loadTool = async (rawClosure: JsonObject) => {
const key = rawClosure.key;
const context = rawClosure.context;