The Open Framework for Building Agents
fix(eve): scaffold the self-modification mount from subagent instructions (#4055)
prhacd8fb87ba42d
diff --git a/.changeset/selfmod-subagent-config-scaffold.md b/.changeset/selfmod-subagent-config-scaffold.mdnew file mode 100644index 000000000..cdc4ed51e--- /dev/null+++ b/.changeset/selfmod-subagent-config-scaffold.md@@ -0,0 +1,5 @@+---+"eve": patch+---++The self-modification subagent no longer tries to install `eve/self-modification` when asked to change the agent's own instructions. To change the subagent's own model or reasoning, it now creates or edits `agent/extensions/self-modification/extension.ts` directly.diff --git a/docs/guides/self-modification.md b/docs/guides/self-modification.mdindex df5cdf680..310897b6c 100644--- a/docs/guides/self-modification.md+++ b/docs/guides/self-modification.md@@ -19,6 +19,16 @@ Add a tool that converts temperatures between Celsius and Fahrenheit.The self-modification subagent changes the authored files in your project. Review the diff and test the new behavior as you would for any other source change. `eve dev` reloads changes while you work.+## Change the self-modification model++The subagent uses your agent's model by default. To give it a different model or reasoning level, ask for it directly:++```text+Switch the self-modification subagent to openai/gpt-6-sol with low reasoning.+```++The first time, this creates `agent/extensions/self-modification/extension.ts` with those settings. After that file exists, later changes edit it. You can also edit the file yourself: it accepts `model` and `reasoning` options.+## Run without self-modificationPass `--no-default-extensions` when you do not want `eve dev` to mount bundled development extensions:diff --git a/e2e/fixtures/agent-self-modification/evals/self-modification/update-identity.eval.ts b/e2e/fixtures/agent-self-modification/evals/self-modification/update-identity.eval.tsnew file mode 100644index 000000000..42b768019--- /dev/null+++ b/e2e/fixtures/agent-self-modification/evals/self-modification/update-identity.eval.ts@@ -0,0 +1,23 @@+import { defineEval } from "eve/evals";++import { withSelfModification } from "./harness";++export default defineEval({+ tags: ["real-model"],+ description:+ "Self-mod edits the agent's own instructions for an identity change instead of scaffolding itself.",+ async test(t) {+ await withSelfModification(t, async (selfMod) => {+ const run = await selfMod.request(+ "Alice is setting this agent up for a history class. Please update your instructions to say you're a historian.",+ );+ run.child.notCalledTool("registry_add");+ const instructions = await selfMod.readSource("instructions.md");+ if (!/historian/i.test(instructions)) {+ throw new Error("instructions.md does not describe the agent as a historian.");+ }+ await selfMod.assertOnlyChanged(["instructions.md"]);+ t.succeeded();+ });+ },+});diff --git a/e2e/fixtures/agent-self-modification/package.json b/e2e/fixtures/agent-self-modification/package.jsonindex c44ee35dd..9bb0b96a9 100644--- a/e2e/fixtures/agent-self-modification/package.json+++ b/e2e/fixtures/agent-self-modification/package.json@@ -31,7 +31,8 @@"name": "repair","evals": ["self-modification/offer-repair",- "self-modification/repair-order-total"+ "self-modification/repair-order-total",+ "self-modification/update-identity"]},{diff --git a/packages/eve/src/self-modification/extension/subagents/agent/agent.ts b/packages/eve/src/self-modification/extension/subagents/agent/agent.tsindex 08625d11d..faa3ac538 100644--- a/packages/eve/src/self-modification/extension/subagents/agent/agent.ts+++ b/packages/eve/src/self-modification/extension/subagents/agent/agent.ts@@ -85,7 +85,7 @@ export function defineSelfModificationAgent(const mode = resolveSelfModificationMode(config);const model = configuredModel ?? FALLBACK_SELF_MODIFICATION_MODEL;const description = renderDescription([- "Delegate here when the user asks to change this eve agent or its authored source.",+ "Delegate here immediately when the user asks to change the self-modification subagent's model, reasoning, or configuration. Also delegate when the user asks to change this eve agent or its authored source.",sourceDelegation,persistenceDelegation,namedInstallationDelegation,diff --git a/packages/eve/src/self-modification/extension/subagents/agent/instructions.ts b/packages/eve/src/self-modification/extension/subagents/agent/instructions.tsindex 070c0c60d..2d67ec3c6 100644--- a/packages/eve/src/self-modification/extension/subagents/agent/instructions.ts+++ b/packages/eve/src/self-modification/extension/subagents/agent/instructions.ts@@ -3,6 +3,7 @@ import { defineDynamic, defineInstructions } from "eve/instructions";import { resolveSelfModificationConfig } from "../../../config.js";import { resolveSelfModificationMode } from "../../../mode.js";import selfModification from "../../extension.js";+import { renderLocalSelfModificationExtension } from "../../../scaffold.js";const role = `## Role@@ -64,6 +65,12 @@ Local eve dev logs are mounted read-only at /logs. Local trace segments are mounThe application package.json is not mounted. Do not search outside /source for application files. You cannot run host binaries such as git, node, pnpm, or tsc. Use existing imports and registry_add for supported registry installations.`;+const selfModificationSubagentGuidance = `## Changing the self-modification subagent++Only when the requester explicitly names the self-modification subagent, edit whichever of /source/extensions/self-modification.ts or /source/extensions/self-modification/extension.ts exists. If neither exists, create /source/extensions/self-modification/extension.ts with write_file using this content, then make the requested model or reasoning change:+\`\`\`ts+${renderLocalSelfModificationExtension()}\`\`\``;+const deployedGuidance = `## Deployed environmentThe registry_add tool may return \`completed\`, \`input-required\`, \`external-action-required\`, \`cancelled\`, or \`failed\`. Supply only non-secret structured answers when continuing an \`input-required\` setup; set \`installed: true\` so the continuation does not reinstall source. Never request, accept, or repeat secret values. External authorization and secret binding are incomplete follow-up boundaries, not evidence that an integration is active.@@ -72,12 +79,6 @@ The configured target branch is checked out as a disposable workspace under /worComplete all edits and registry installations before publication, and call publish by itself. Before publication, review and summarize the complete intended scope. Call publish once with a concise title and summary. A successful result is only a draft pull request. Return its URL and changed paths, and state that merge and deployment have not occurred.`;-const packagedSubagentGuidance = `## Changing this subagent--When the user explicitly asks to change the self-modification subagent's model, reasoning, or policy, make edits only through its authored mount. For such requests, check /source/extensions/self-modification.ts and /source/extensions/self-modification/extension.ts; modify whichever exists. If neither file exists, this subagent is the bundled eve development default and is using the default settings: first call registry_add with the exact address eve/self-modification to scaffold the authored mount. This known scaffold does not require search_registry.--After registry_add reports successful installation, try to read /source/extensions/self-modification.ts and /source/extensions/self-modification/extension.ts. If either is available, modify it. If neither is yet available, you may need to wait for the next turn, by asking the requester to confirm.`;-function renderInstructions(sections: readonly string[]): string {return sections.filter((section) => section.length > 0).join("\n\n");}@@ -94,13 +95,13 @@ export default defineDynamic({markdown: renderInstructions([role,sourceWorkspace,- packagedSubagentGuidance,sourceEditing,toolAuthoring,registryWorkflow,documentationGuidance,mode === "local" ? localGuidance : deployedGuidance,workingGuidance,+ selfModificationSubagentGuidance,mode === "local" ? localReportingGuidance : deployedReportingGuidance,]),});diff --git a/packages/eve/src/self-modification/scaffold.ts b/packages/eve/src/self-modification/scaffold.tsnew file mode 100644index 000000000..adabbe6bd--- /dev/null+++ b/packages/eve/src/self-modification/scaffold.ts@@ -0,0 +1,4 @@+/** Default authored mount for locally configured self-modification. */+export function renderLocalSelfModificationExtension(): string {+ return `import selfModification from "eve/self-modification";\n\nexport default selfModification({\n // model: "provider/model",\n // reasoning: "high",\n});\n`;+}diff --git a/packages/eve/src/self-modification/setup.ts b/packages/eve/src/self-modification/setup.tsindex ac24663c6..8271ee178 100644--- a/packages/eve/src/self-modification/setup.ts+++ b/packages/eve/src/self-modification/setup.ts@@ -14,12 +14,13 @@ import {import type { VercelProjectReference } from "#setup/project-resolution.js";import { SELF_MODIFICATION_CONFIG_PATH } from "./git-workspace.js";+import { renderLocalSelfModificationExtension } from "./scaffold.js";const runFile = promisify(execFile);const GENERATED_MARKER = "// eve-self-modification: generated-v1";const LEGACY_LOCAL_CONFIG ='import { defineSelfModificationConfig } from "eve/self-modification/config";\n\nexport default defineSelfModificationConfig({});\n';-const DEFAULT_EXTENSION = `import selfModification from "eve/self-modification";\n\nexport default selfModification({\n // model: "provider/model",\n // reasoning: "high",\n});\n`;+const DEFAULT_EXTENSION = renderLocalSelfModificationExtension();export interface SelfModificationSetupValues {readonly branch: string;