Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): keep memory tools on a turn whose input carries an attachment (#4782)

roboeve[bot]9d046f89eb72
diff --git a/.changeset/memory-tools-with-attachments.md b/.changeset/memory-tools-with-attachments.md
new file mode 100644
index 000000000..5e9d1b44f
--- /dev/null
+++ b/.changeset/memory-tools-with-attachments.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Memory provider tools are now offered on a turn whose message carries a file attachment. Before, the agent lost its memory tools on exactly that turn.
diff --git a/packages/eve/src/context/memory-tools.test.ts b/packages/eve/src/context/memory-tools.test.ts
index 301f87683..e6fc7d18f 100644
--- a/packages/eve/src/context/memory-tools.test.ts
+++ b/packages/eve/src/context/memory-tools.test.ts
@@ -214,24 +214,26 @@ describe("memory provider tools", () => {
expect(JSON.stringify(metadata)).not.toContain("hello");
});
- // Repro for #4780: expected to fail until the fix lands, which flips this back to `it`.
- it.fails("offers provider tools on a turn whose input carries a staged attachment", async () => {
- const ctx = createContext("user_1", {
- ...turn,
- input: [
- {
- content: [
- { text: "remember this screenshot", type: "text" },
- {
- data: encodeSandboxRef({ mediaType: "image/png", path: "/tmp/pixel.png", size: 68 }),
- mediaType: "image/png",
- type: "file",
- },
- ],
- role: "user",
- },
- ],
- });
+ it("offers provider tools on a turn whose input carries a staged attachment", async () => {
+ const input: ModelMessage[] = [
+ {
+ content: [
+ { text: "remember this screenshot", type: "text" },
+ {
+ data: encodeSandboxRef({ mediaType: "image/png", path: "/tmp/pixel.png", size: 68 }),
+ mediaType: "image/png",
+ type: "file",
+ },
+ ],
+ role: "user",
+ },
+ ];
+ const ctx = createContext("user_1", { ...turn, input });
+ const seen: (readonly ModelMessage[])[] = [];
+ const compiledResolver = resolver(
+ () => 1,
+ (context) => seen.push(context.turn.input),
+ );
await contextStorage.run(
ctx,
@@ -240,11 +242,29 @@ describe("memory provider tools", () => {
ctx,
event,
messages: [{ content: "remember this screenshot", role: "user" }],
- resolvers: [resolver(() => 1)],
+ resolvers: [compiledResolver],
}),
);
expect(buildDynamicTools(ctx).map((tool) => tool.name)).toEqual(["profile__save"]);
+
+ clearDurableDynamicCallbacks(ctx.require(SessionIdKey));
+ await rebindMissingCompiledDynamicToolCallbacks({
+ ctx,
+ event,
+ messages: [{ content: "remember this screenshot", role: "user" }],
+ resolvers: [compiledResolver],
+ });
+ seen.length = 0;
+ const [replayed] = buildDynamicTools(ctx);
+ const output = await contextStorage.run(
+ ctx,
+ async () => await replayed?.execute?.({}, { messages: [], toolCallId: "call_1" }),
+ );
+ expect(output).toBe("1:user_1");
+ expect(seen).toEqual([input]);
+ const [metadata] = ctx.require(TurnDynamicToolMetadataKey);
+ expect(JSON.stringify(metadata)).not.toContain("eve-sandbox:");
});
it("omits tools when the provider has no tool factory", async () => {
diff --git a/packages/eve/src/context/memory-tools.ts b/packages/eve/src/context/memory-tools.ts
index cd48ad676..048d3b6eb 100644
--- a/packages/eve/src/context/memory-tools.ts
+++ b/packages/eve/src/context/memory-tools.ts
@@ -61,20 +61,26 @@ function createProviderToolCallbacks(input: {
readonly key: string;
readonly tool: MemoryToolSet[string];
}) {
- // History stays out of the durable closure: it is already durable session
- // state and can hold non-JSON values (dates, bytes) once a turn has run
- // tools. Replay reuses the messages this process resolved the tools with.
- const { messages, ...durableContext } = input.context;
- const closure = parseJsonObject({ context: durableContext, key: input.key });
+ // History and turn input stay out of the durable closure: both are already
+ // durable session state and can hold non-JSON values (dates, bytes, staged
+ // attachment URLs). Replay reuses the values this process resolved with.
+ const {
+ messages,
+ turn: { input: turnInput, ...turn },
+ ...durableContext
+ } = input.context;
+ const closure = parseJsonObject({ context: { ...durableContext, turn }, key: input.key });
const loadTool = async (rawClosure: JsonObject) => {
const key = rawClosure.key;
const context = rawClosure.context;
if (typeof key !== "string" || typeof context !== "object" || context === null) {
throw new Error("Memory provider tool callback has an invalid durable closure.");
}
- const tools = await input.definition.provider.tools?.(
- readMemoryToolsContext({ ...context, messages }),
- );
+ const durable = readMemoryToolsContext({ ...context, messages });
+ const tools = await input.definition.provider.tools?.({
+ ...durable,
+ turn: { ...durable.turn, input: turnInput },
+ });
const tool = tools?.[key];
if (tool === undefined || !isBrandedToolEntry(tool)) {
throw new Error(`Memory provider tool "${key}" was removed or renamed.`);