The Open Framework for Building Agents
fix: resolve a compaction.model instance to itself (#4965) (#4970)
roboeve[bot]7a908f57c8e7
diff --git a/.changeset/own-compaction-model-instance.md b/.changeset/own-compaction-model-instance.mdnew file mode 100644index 000000000..f0c4e5600--- /dev/null+++ b/.changeset/own-compaction-model-instance.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Compaction summaries now run on the AI SDK model instance set as `compaction.model`. Before, a direct model instance there was ignored and summaries ran on the agent's top-level `model`.diff --git a/packages/eve/src/compiler/manifest.ts b/packages/eve/src/compiler/manifest.tsindex e0fe7c85b..47fb44205 100644--- a/packages/eve/src/compiler/manifest.ts+++ b/packages/eve/src/compiler/manifest.ts@@ -578,6 +578,7 @@ const compiledRuntimeModelReferenceSchema: z.ZodType<CompiledRuntimeModelReferenid: z.string(),maxOutputTokens: z.number().int().positive().optional(),source: moduleSourceRefSchema.optional(),+ sourceField: z.literal("compaction.model").optional(),promptCache: z.object({anthropic: z@@ -1368,6 +1369,9 @@ function cloneCompiledRuntimeModelReference(if (model.source !== undefined) {clone.source = { ...model.source };}+ if (model.sourceField !== undefined) {+ clone.sourceField = model.sourceField;+ }return clone;}diff --git a/packages/eve/src/compiler/normalize-agent-config.ts b/packages/eve/src/compiler/normalize-agent-config.tsindex e3b6a2184..f33f49c2b 100644--- a/packages/eve/src/compiler/normalize-agent-config.ts+++ b/packages/eve/src/compiler/normalize-agent-config.ts@@ -156,6 +156,7 @@ export async function compileAgentConfig(contextWindowTokens: definition.compaction.modelContextWindowTokens,providerOptions: definition.modelOptions?.providerOptions,source: configModule,+ sourceField: "compaction.model",sourcePath: configModulePath,value: definition.compaction.model,});@@ -203,6 +204,7 @@ async function normalizeAuthoredModelReference(input: {readonly promptCache?: AgentPromptCacheDefinition;readonly providerOptions?: Record<string, JsonObject>;readonly source?: ModuleSourceRef;+ readonly sourceField?: CompiledRuntimeModelReference["sourceField"];readonly sourcePath?: string;readonly value: PublicAgentStaticModelDefinition;}): Promise<CompiledRuntimeModelReference> {@@ -265,6 +267,7 @@ async function normalizeAuthoredModelReference(input: {providerOptions: parseProviderOptionsRecord(input.providerOptions),routing,};+ if (input.sourceField !== undefined) sourceBackedModel.sourceField = input.sourceField;if (input.promptCache !== undefined) sourceBackedModel.promptCache = input.promptCache;if (input.contextWindowTokens === undefined) {diff --git a/packages/eve/src/compiler/normalize-manifest.test.ts b/packages/eve/src/compiler/normalize-manifest.test.tsindex 115a92c89..a14d0e6bb 100644--- a/packages/eve/src/compiler/normalize-manifest.test.ts+++ b/packages/eve/src/compiler/normalize-manifest.test.ts@@ -744,8 +744,7 @@ describe("compileAgentManifest source graph", () => {expect(resolved.config?.model?.promptCache).toEqual({ anthropic: { ttl: "1h" } });});- // Issue #4965: both references point at the same agent config export.- it.fails("resolves a direct compaction model to its own instance", async () => {+ it("resolves a direct compaction model to its own instance", async () => {vi.stubEnv("NODE_ENV", "production");vi.stubEnv("EVE_MOCK_AUTHORED_MODELS", "");const directModel = (modelId: string) =>diff --git a/packages/eve/src/runtime/agent/resolve-model.ts b/packages/eve/src/runtime/agent/resolve-model.tsindex cd7b03843..25c988463 100644--- a/packages/eve/src/runtime/agent/resolve-model.ts+++ b/packages/eve/src/runtime/agent/resolve-model.ts@@ -107,11 +107,14 @@ async function loadSourceBackedRuntimeModelReference(definition,`Expected the authored agent config export "${reference.source.exportName ?? "default"}" from "${reference.source.logicalPath}" to match the public eve shape.`,);- const model = normalizedDefinition.model;+ const model =+ reference.sourceField === "compaction.model"+ ? normalizedDefinition.compaction?.model+ : normalizedDefinition.model;if (model === undefined) {throw new Error(- `Expected the authored agent config export "${reference.source.exportName ?? "default"}" from "${reference.source.logicalPath}" to provide a runtime model.`,+ `Expected the authored agent config export "${reference.source.exportName ?? "default"}" from "${reference.source.logicalPath}" to provide a runtime model at "${reference.sourceField ?? "model"}".`,);}diff --git a/packages/eve/src/runtime/resolve-agent.ts b/packages/eve/src/runtime/resolve-agent.tsindex c2b545a11..ba4647403 100644--- a/packages/eve/src/runtime/resolve-agent.ts+++ b/packages/eve/src/runtime/resolve-agent.ts@@ -254,6 +254,7 @@ function createResolvedAgentConfig(logicalPath: manifest.config.compaction.model.source.logicalPath,sourceId: manifest.config.compaction.model.source.sourceId,},+ sourceField: manifest.config.compaction.model.sourceField,};}diff --git a/packages/eve/src/shared/agent-definition.ts b/packages/eve/src/shared/agent-definition.tsindex 27d16a03f..22b45ad73 100644--- a/packages/eve/src/shared/agent-definition.ts+++ b/packages/eve/src/shared/agent-definition.ts@@ -77,6 +77,8 @@ export type InternalAgentModelDefinition = {contextWindowTokens?: number;maxOutputTokens?: number;source?: ModuleSourceRef;+ /** Field of the `source` agent config export that holds this model; absent means `model`. */+ sourceField?: "compaction.model";providerOptions?: Record<string, JsonObject>;promptCache?: AgentPromptCacheDefinition;};