The Open Framework for Building Agents
[2/3] fix(eve): delegate confirmed self-mod repairs (#3375)
Ben Pankowba0b866fb635
diff --git a/.changeset/offer-confirmed-self-mod-repairs.md b/.changeset/offer-confirmed-self-mod-repairs.mdnew file mode 100644index 000000000..298b476b9--- /dev/null+++ b/.changeset/offer-confirmed-self-mod-repairs.md@@ -0,0 +1,5 @@+---+"eve": patch+---++When a self-modified tool or capability later fails or behaves incorrectly, the agent now offers to delegate a repair. It waits for your confirmation before sending the observed and expected behavior back to self-modification.diff --git a/e2e/fixtures/agent-self-modification/README.md b/e2e/fixtures/agent-self-modification/README.mdindex a44e3ae65..44d6e7aa5 100644--- a/e2e/fixtures/agent-self-modification/README.md+++ b/e2e/fixtures/agent-self-modification/README.md@@ -18,6 +18,7 @@ This exercises the current standard scaffold without duplicating it in the fixtu- `create-incident-triage.eval.ts` creates an incident-triage tool and checks precedence and threshold rules across typed inputs.- `create-shipping-quote.eval.ts` creates a quote calculator and checks destination, started-kilogram, free-shipping, and expedited pricing boundaries.+- `offer-repair.eval.ts` reproduces an incorrect reorder recommendation, checks that the parent offers but does not start a repair, confirms it, and verifies the repaired tool.- `repair-order-total.eval.ts` first reproduces quantity and discount errors in the fixture's existing tool, asks self-mod to investigate the incorrect invoice, and verifies the fix, cent rounding, and single-item/empty-order regressions.Each case checks actual tool inputs and outputs, not the assistant's claim that the work succeeded. Cases also reject source changes outside their specified tool file. The arithmetic cases use synthetic data and do not require external services. These checks cover the specified behavior; they are not a general security audit of generated code.diff --git a/e2e/fixtures/agent-self-modification/evals/self-modification/harness.ts b/e2e/fixtures/agent-self-modification/evals/self-modification/harness.tsindex 0769648ef..43bb3b8a7 100644--- a/e2e/fixtures/agent-self-modification/evals/self-modification/harness.ts+++ b/e2e/fixtures/agent-self-modification/evals/self-modification/harness.ts@@ -13,7 +13,7 @@ import {import { tmpdir } from "node:os";import { dirname, join } from "node:path";-import type { EveEvalContext, EveEvalLiveTurn, EveEvalTurn } from "eve/evals";+import type { EveEvalContext, EveEvalLiveTurn, EveEvalSession, EveEvalTurn } from "eve/evals";const SELF_MODIFICATION_AGENT = "self-modification";const CLEANUP_TIMEOUT_MS = 30_000;@@ -29,6 +29,7 @@ const isolation = (shared.__eveSelfModificationEvalIsolation ??= {export interface SelfModificationRun {readonly child: EveEvalTurn;readonly parent: EveEvalTurn;+ readonly session: EveEvalSession;}/** Serializes source mutation, including cleanup that outlives an eval timeout. */@@ -125,8 +126,11 @@ export class SelfModificationHarness {}}- async request(prompt: string): Promise<SelfModificationRun> {- const liveParent = await this.#t.start(prompt);+ async request(+ prompt: string,+ session: Pick<EveEvalSession, "start"> = this.#t,+ ): Promise<SelfModificationRun> {+ const liveParent = await session.start(prompt);this.#turns.add(liveParent);let continuation: EveEvalLiveTurn | undefined;const called = await liveParent@@ -156,16 +160,16 @@ export class SelfModificationHarness {parent.expectOk();this.#t.calledSubagent(SELF_MODIFICATION_AGENT);child.expectOk();- return { child, parent };+ return { child, parent, session: liveParent.session };+ }++ followUp(session: EveEvalSession, prompt: string): Promise<EveEvalTurn> {+ return this.#runTurn(session, prompt);}/** Uses a fresh conversation so the model cannot answer from the authoring exchange alone. */- async verify(prompt: string): Promise<EveEvalTurn> {- const live = await this.#t.newSession().start(prompt);- this.#turns.add(live);- const turn = await live.result();- turn.expectOk();- return turn;+ verify(prompt: string): Promise<EveEvalTurn> {+ return this.#runTurn(this.#t.newSession(), prompt);}async apply(): Promise<void> {@@ -251,6 +255,14 @@ export class SelfModificationHarness {await rm(this.#backupRoot, { recursive: true, force: true });}+ async #runTurn(session: EveEvalSession, prompt: string): Promise<EveEvalTurn> {+ const live = await session.start(prompt);+ this.#turns.add(live);+ const turn = await live.result();+ turn.expectOk();+ return turn;+ }+#resolve(sourcePath: string): string {if (!sourcePath || sourcePath.startsWith("/") || sourcePath.split(/[\\/]/u).includes("..")) {throw new Error(`Self-modification eval source paths must be relative: ${sourcePath}`);diff --git a/e2e/fixtures/agent-self-modification/evals/self-modification/offer-repair.eval.ts b/e2e/fixtures/agent-self-modification/evals/self-modification/offer-repair.eval.tsnew file mode 100644index 000000000..425799e0b--- /dev/null+++ b/e2e/fixtures/agent-self-modification/evals/self-modification/offer-repair.eval.ts@@ -0,0 +1,94 @@+import { defineEval } from "eve/evals";++import { withSelfModification } from "./harness";++const TOOL_NAME = "eval_reorder_plan";+const TOOL_PATH = `tools/${TOOL_NAME}.ts`;+const DEFECTIVE_SOURCE = `import { defineTool } from "eve/tools";+import { never } from "eve/tools/approval";+import { z } from "zod";++export default defineTool({+ description: "Calculate inventory reorder quantities without placing an order.",+ inputSchema: z.object({+ onHand: z.number().int().min(0).max(1000000),+ incoming: z.number().int().min(0).max(1000000),+ target: z.number().int().min(0).max(1000000),+ }),+ approval: never(),+ async execute({ onHand, target }) {+ return { reorderUnits: Math.max(0, target - onHand) };+ },+});+`;++export default defineEval({+ tags: ["real-model"],+ description:+ "A parent offers to repair a previously self-modified tool and waits for confirmation.",++ async test(t) {+ await withSelfModification(t, async (selfMod) => {+ const authored = await selfMod.request(+ [+ `Alice needs a reusable ${TOOL_NAME} action for inventory planning in future conversations.`,+ "Accept non-negative integer onHand, incoming, and target quantities, each no greater than 1000000.",+ "Return reorderUnits as the target minus both on-hand and incoming stock, floored at zero.",+ "This action only calculates a recommendation; it must not place an order or contact external services.",+ ].join(" "),+ );+ await selfMod.assertOnlyChanged([TOOL_PATH]);+ await selfMod.apply();+ const working = await selfMod.verify(+ `Call ${TOOL_NAME} once with ${JSON.stringify({ onHand: 20, incoming: 30, target: 100 })} and report the recommendation without placing an order.`,+ );+ working.requireToolCall(TOOL_NAME, {+ input: { onHand: 20, incoming: 30, target: 100 },+ output: { reorderUnits: 50 },+ });++ // Inject a deterministic regression after the real authoring flow so the repair behavior does+ // not depend on a model accidentally generating broken source.+ await selfMod.writeSource(TOOL_PATH, DEFECTIVE_SOURCE);+ await selfMod.apply();++ const incorrect = await selfMod.verify(+ `Call ${TOOL_NAME} once with ${JSON.stringify({ onHand: 20, incoming: 30, target: 100 })} and report the recommendation.`,+ );+ incorrect.requireToolCall(TOOL_NAME, {+ input: { onHand: 20, incoming: 30, target: 100 },+ output: { reorderUnits: 80 },+ });++ const offered = await selfMod.followUp(+ authored.session,+ "That recommendation is wrong. Incoming stock should count toward the target, so it should recommend 50 units, not 80. What should we do?",+ );+ offered.notEvent("subagent.called", { data: { name: "self-modification" } });+ t.judge.autoevals.closedQA(+ "The response offers to delegate a repair of the incorrect tool and asks the user to confirm before starting it.",+ { on: offered.message },+ );++ await selfMod.request("Yes, please do.", authored.session);+ await selfMod.assertOnlyChanged([TOOL_PATH]);+ await selfMod.apply();++ await Promise.all(+ (+ [+ [{ onHand: 20, incoming: 30, target: 100 }, 50],+ [{ onHand: 100, incoming: 25, target: 100 }, 0],+ [{ onHand: 0, incoming: 0, target: 75 }, 75],+ ] as const+ ).map(async ([input, reorderUnits]) => {+ const turn = await selfMod.verify(+ `Call ${TOOL_NAME} once with ${JSON.stringify(input)} and report the recommendation without placing an order.`,+ );+ turn.requireToolCall(TOOL_NAME, { input, output: { reorderUnits } });+ }),+ );+ t.succeeded();+ });+ },+});diff --git a/packages/eve/src/self-modification/agent.test.ts b/packages/eve/src/self-modification/agent.test.tsindex 357967292..b142fdcac 100644--- a/packages/eve/src/self-modification/agent.test.ts+++ b/packages/eve/src/self-modification/agent.test.ts@@ -25,4 +25,29 @@ describe("self-modification agent", () => {expect(resolved).toMatchObject({ reasoning: "high" });});++ it("offers repairs and delegates only after confirmation", async () => {+ process.env.EVE_DEV = "1";+ const agent = defineSelfModificationAgent();+ const resolved = await agent.events["session.started"]?.(+ {},+ {+ channel: {},+ messages: [],+ model: null,+ session: { auth: { current: null, initiator: null }, id: "session" },+ },+ );++ expect(resolved).toMatchObject({+ description: expect.stringContaining(+ "If a tool or capability created or changed by this subagent later fails",+ ),+ });+ const description = (resolved as { description: string }).description;+ expect(description).toContain("Do not start the repair until the user confirms.");+ expect(description).toContain(+ "Treat that confirmation as a source-modification request and delegate it immediately",+ );+ });});diff --git a/packages/eve/src/self-modification/agent.ts b/packages/eve/src/self-modification/agent.tsindex 1c9413e52..4c12fd44e 100644--- a/packages/eve/src/self-modification/agent.ts+++ b/packages/eve/src/self-modification/agent.ts@@ -50,6 +50,10 @@ const followUpDelegation ="Resolve short follow-ups such as “yes” or “do it” against the preceding conversation. " +"If whether the requested change should persist is genuinely ambiguous, ask one concise clarifying question.";+const repairDelegation =+ "If a tool or capability created or changed by this subagent later fails or behaves incorrectly, explain the observed problem and offer to delegate a repair. " ++ "Do not start the repair until the user confirms. Treat that confirmation as a source-modification request and delegate it immediately, including the exact identifier, failing behavior, expected behavior, and existing constraints.";+const localIntegrationDelegation ="Delegate questions about which integrations, channels, connections, or capabilities are available to add: the subagent searches the eve registry and reports exact item addresses instead of guessing them.";@@ -80,6 +84,7 @@ export function defineSelfModificationAgent(options: SelfModificationAgentOptionmode === "local" ? localIntegrationDelegation : deployedIntegrationDelegation,mode === "local" ? localTraceDelegation : "",followUpDelegation,+ repairDelegation,mode === "local" ? localEffectiveEdits : deployedEffectiveEdits,]);if (mode === "local") return defineAgent({ description, model, reasoning });