The Open Framework for Building Agents
fix(eve): persist framework prompt announcements (#3131)
Rui1a9556ca5e36
diff --git a/.changeset/persist-framework-prompt-history.md b/.changeset/persist-framework-prompt-history.mdnew file mode 100644index 000000000..fe1fb0df4--- /dev/null+++ b/.changeset/persist-framework-prompt-history.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Preserve framework announcements in conversation history so changing task and skill snapshots append to earlier model requests instead of replacing their context. Unchanged announcements are skipped until history is cleared or compacted, and completed compaction is retained if the next model request fails.diff --git a/.changeset/remove-pending-task-silence.md b/.changeset/remove-pending-task-silence.mdnew file mode 100644index 000000000..ac9186477--- /dev/null+++ b/.changeset/remove-pending-task-silence.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Remove the instruction that forced silence while background tasks were pending. This prevents that instruction from carrying into later user turns and suppressing their answers.diff --git a/docs/instructions.mdx b/docs/instructions.mdxindex 5f193235c..8f86c34ad 100644--- a/docs/instructions.mdx+++ b/docs/instructions.mdx@@ -86,7 +86,7 @@ See [Dynamic capabilities](./guides/dynamic-capabilities) for examples and failu[Compaction](./concepts/sessions-runs-and-streaming#compact-clear-and-reset) treats user-role instructions like ordinary conversation history, so a summary may replace their original text. Clear removes them with the rest of model-message history and does not rerun static or dynamic instructions. System-role instructions remain because they are outside history.-Keep system-role content stable and place it before frequently changing context when practical. That gives providers the best opportunity to reuse a prompt prefix, but cache behavior and billing remain provider-specific. User-role instructions preserve the normal append-only message prefix. Framework context such as dynamic skill announcements also keeps its position before the current request across tool steps, including when a durable step resumes. eve does not promise a cache hit.+Keep system-role content stable and place it before frequently changing context when practical. That gives providers the best opportunity to reuse a prompt prefix, but cache behavior and billing remain provider-specific. User-role instructions preserve the normal append-only message prefix. Framework announcements about available skills and background tasks are retained in user-role history: changed snapshots append after earlier steps instead of replacing the context sent with those steps. Unchanged announcements are skipped until history is cleared or compacted. eve does not promise a cache hit.## Disclaimerdiff --git a/docs/tools/overview.mdx b/docs/tools/overview.mdxindex 3f15a655e..09b439d26 100644--- a/docs/tools/overview.mdx+++ b/docs/tools/overview.mdx@@ -138,9 +138,11 @@ After the initiating turn accepts background tasks, eve supplies runtime-authorecohort and instructs the model to acknowledge that the work started without waiting for results.[Schedule](/docs/schedules)-initiated turns are the exception: no user prompted them, so theirlaunches keep conditional delivery and send no acknowledgement.-Later task-triggered parent turns receive fresh state for the same cohort. The model is instructed-to keep related intermediate results silent while any task remains pending. Once every related+Later task-triggered parent turns receive fresh state for the same cohort. Once every relatedtask is terminal, the state includes their outputs so the model can combine the useful results.+eve does not instruct the model to stay silent while sibling tasks are pending; a new user+question can receive an answer while background work continues. [Completion batching](/docs/subagents#completion-batching)+combines successful results already queued for the parent.### Yield and returndiff --git a/e2e/fixtures/agent-background-tools/agent/agent.ts b/e2e/fixtures/agent-background-tools/agent/agent.tsindex b4a74e2c5..949d6a11d 100644--- a/e2e/fixtures/agent-background-tools/agent/agent.ts+++ b/e2e/fixtures/agent-background-tools/agent/agent.ts@@ -8,7 +8,15 @@ const SCHEDULED = "BACKGROUND-EXPORT-SCHEDULED";const EMPTY_DELIVERY_SENTINEL = "<eve-empty-delivery/>";function respond(request: MockModelRequest): MockModelResponse | string {- const message = [...request.userMessages].reverse().find((entry) => entry.trim() !== "") ?? "";+ const message =+ [...request.userMessages]+ .reverse()+ .find(+ (entry) =>+ entry.includes("BACKGROUND-EXPORT-") || /^(?:Background task|Export) task_/u.test(entry),+ ) ??+ request.userMessages.at(-1) ??+ "";const examplePrefix = "Alice is documenting conditional delivery. Return exactly this example:\n";if (message.startsWith(examplePrefix)) {@@ -26,8 +34,7 @@ function respond(request: MockModelRequest): MockModelResponse | string {}if (message.includes("BACKGROUND-EXPORT-START")) {- const roles = request.messages.map((entry) => entry.role);- if (roles.lastIndexOf("tool") <= roles.lastIndexOf("user")) {+ if (!request.toolResults.some((result) => result.name === "export")) {return {toolCalls: [{@@ -65,8 +72,7 @@ function respondScheduled(request: MockModelRequest): MockModelResponse | stringif (taskNotification?.includes("is completed") && taskNotification.includes(RESULT)) {return "SCHEDULED-EXPORT-DONE";}- const roles = request.messages.map((entry) => entry.role);- const launched = roles.lastIndexOf("tool") > roles.lastIndexOf("user");+ const launched = request.toolResults.some((result) => result.name === "export");if (!launched && taskNotification === undefined) {return {toolCalls: [@@ -77,8 +83,8 @@ function respondScheduled(request: MockModelRequest): MockModelResponse | string],};}- const instructedToAcknowledge = request.messages.some(- (entry) => entry.role === "system" && entry.text.includes("launch acknowledgement"),+ const instructedToAcknowledge = request.messages.some((entry) =>+ entry.text.includes("launch acknowledgement"),);return instructedToAcknowledge ? "SCHEDULED-EXPORT-LAUNCH-ACK" : EMPTY_DELIVERY_SENTINEL;}diff --git a/e2e/fixtures/agent-compaction-regressions/agent/tools/advance-checkpoint.ts b/e2e/fixtures/agent-compaction-regressions/agent/tools/advance-checkpoint.tsindex 8cdea2bf8..59331a082 100644--- a/e2e/fixtures/agent-compaction-regressions/agent/tools/advance-checkpoint.ts+++ b/e2e/fixtures/agent-compaction-regressions/agent/tools/advance-checkpoint.ts@@ -8,7 +8,7 @@ const invocationCount = defineState("compaction-regression.advance-checkpoint",export default defineTool({description:- "Test-only second-compaction trigger tool. Records a completed fixture work unit and adds enough evidence for the harness to cross the compaction threshold again.",+ "Record the handoff notes after the initial review is complete and return its checkpoint marker.",inputSchema: z.object({regressionCase: z.enum(["redundant-tool-calls", "stale-todo-work"]),}),@@ -21,7 +21,18 @@ export default defineTool({completed: true,regressionCase: input.regressionCase,attempt,- evidencePadding: "second checkpoint evidence ".repeat(100),+ handoffNotes: [+ "Alice has finished the initial review of the online shop. Bob will use these notes to prepare the team handoff. The completed review remains the source for the findings; preparing the handoff does not require another inspection.",+ "The catalog, cart, and checkout form the main customer journey. The handoff groups the findings in that order so Bob can follow a product from the catalog through the cart and into a saved order without jumping between unrelated topics.",+ "Catalog notes cover product identifiers, names, prices, and availability. Bob can use that section to explain which values the cart displays and which values checkout reads again when it calculates the final order total.",+ "Cart notes cover adding items, changing quantities, and removing the last item. An empty cart is an ordinary state. The handoff distinguishes an empty cart from an invalid quantity so the examples remain clear to the next reviewer.",+ "Checkout notes separate the subtotal from delivery charges and describe amounts in cents. The recorded order contains both the submitted items and the calculated total, giving the confirmation page a consistent saved result to display.",+ "The confirmation section explains that the saved order supplies the displayed quantities, prices, and delivery details. Notification delivery is a separate follow-up to saving the order, so a delayed notification does not mean the purchase was lost.",+ "Inventory and address validation are listed with the checkout findings. When a customer needs to correct either one, the cart remains available. Bob can refer to these notes when describing the expected correction flow to the team.",+ "The order history section records how stored orders are listed and paginated. The cancellation section records how repeated cancellation requests use the saved order status. These are existing review findings, not additional work requests.",+ "Bob maintains the shared task list independently of Alice's review. A pending review entry means that the list has not been updated yet. The successful tool result records that the review itself is complete, and Bob will reconcile the list during handoff.",+ "The handoff notes are now recorded and the checkpoint marker identifies this completed step. The remaining response should report the review completion marker and this checkpoint marker so Alice and Bob can locate both completed results.",+ ],};},});diff --git a/e2e/fixtures/agent-compaction-regressions/agent/tools/inspect-repository.ts b/e2e/fixtures/agent-compaction-regressions/agent/tools/inspect-repository.tsindex a75bb6de0..be1372094 100644--- a/e2e/fixtures/agent-compaction-regressions/agent/tools/inspect-repository.ts+++ b/e2e/fixtures/agent-compaction-regressions/agent/tools/inspect-repository.ts@@ -7,7 +7,7 @@ const invocationCount = defineState("compaction-regression.inspect-repository",export default defineTool({description:- "Compaction regression tool. Inspect the repository exactly once when the user requests the redundant-tool-calls case.",+ "Inspect the online shop repository and return an overview of its modules for the review handoff.",inputSchema: z.object({scope: z.literal("repository"),}),@@ -21,7 +21,20 @@ export default defineTool({workUnit: "repository-inspection",hardStop: attempt >= 10,attempt,- evidencePadding: "repository inspection evidence ".repeat(100),+ findings: [+ "The repository contains a small online shop. The application entry point loads configuration, constructs the request router, and connects the catalog, cart, checkout, and order history handlers to their repositories.",+ "The catalog module owns product records with identifiers, display names, unit prices, and availability flags. Its repository provides product lookup and filtered listing, returning an empty list when a filter has no matching records.",+ "The cart module stores product identifiers and quantities for each customer cart. Its handlers validate positive integer quantities, combine additions for an existing product, and allow the final item to be removed without invalidating the cart.",+ "The checkout module reads current product prices and availability before calculating the order. It combines item quantities with prices represented in cents, adds delivery charges, and passes the resulting items and total to the order repository.",+ "The order repository stores an order and its submitted items together. It returns the generated order identifier after persistence completes. The confirmation handler then reads the saved record instead of reconstructing the order from the cart.",+ "The confirmation templates display product names, quantities, item prices, and delivery details from the saved order. Product names are rendered as text. The templates share formatting helpers for currency values and postal addresses.",+ "The inventory service checks whether requested quantities are available before checkout accepts an order. When availability has changed, the handler explains which cart entry needs attention and keeps the other entries available for correction.",+ "The address validation module requires a recipient, street, city, and postal code. An additional address line is optional. The same validated address shape flows through checkout, persistence, and order confirmation rendering.",+ "The notification adapter receives an order identifier after the order is saved. It records delivery outcomes separately from order creation, allowing the application to report a delayed confirmation without creating the purchase again.",+ "The order history module reads saved orders in reverse creation order. Its repository uses bounded page sizes and a continuation cursor. The response includes the saved order status, item summary, and total for each returned entry.",+ "The cancellation handler reads the saved order status before applying an update. An already cancelled order returns its existing state. Inventory adjustments are associated with the first successful cancellation rather than every repeated request.",+ "The repository overview is complete and ready for Alice's handoff to Bob. The modules above cover the requested customer journey, including ordinary empty states, validation failures, saved results, and follow-up notifications.",+ ],};},});diff --git a/e2e/fixtures/agent-compaction-regressions/evals/redundant-tool-calls.eval.ts b/e2e/fixtures/agent-compaction-regressions/evals/redundant-tool-calls.eval.tsindex eb3c9c8a8..a12285542 100644--- a/e2e/fixtures/agent-compaction-regressions/evals/redundant-tool-calls.eval.ts+++ b/e2e/fixtures/agent-compaction-regressions/evals/redundant-tool-calls.eval.ts@@ -10,9 +10,8 @@ export default defineEval({["[case: redundant-tool-calls]","Alice is reviewing a small catalog application and preparing a handoff for Bob.",- "Use inspect-repository once with scope repository to obtain her review notes.",- "Once the review is complete, include REPOSITORY_INSPECTION_COMPLETE in the handoff.",- "The completed inspection does not need to be repeated.",+ "Run inspect-repository once with scope repository, then use advance-checkpoint to record the handoff notes.",+ "Report REPOSITORY_INSPECTION_COMPLETE and the returned checkpoint marker. Carry the completed inspection into the handoff without repeating it.",].join("\n"),);diff --git a/e2e/fixtures/agent-compaction-regressions/evals/stale-todo-work.eval.ts b/e2e/fixtures/agent-compaction-regressions/evals/stale-todo-work.eval.tsindex 5d02e09e4..bc4b2ab1f 100644--- a/e2e/fixtures/agent-compaction-regressions/evals/stale-todo-work.eval.ts+++ b/e2e/fixtures/agent-compaction-regressions/evals/stale-todo-work.eval.ts@@ -12,8 +12,7 @@ export default defineEval({"Alice and Bob are reviewing a small catalog application.","Use perform-source-analysis once with approach initial to prepare Alice's findings.","Bob updates their shared checklist separately, so it may still say pending after the analysis is complete.",- "Use the completed analysis for the handoff and include SOURCE_ANALYSIS_COMPLETE.",- "The pending checklist entry does not require repeating the completed analysis.",+ "Then use advance-checkpoint to record the handoff notes. Report SOURCE_ANALYSIS_COMPLETE and the returned checkpoint marker. The completed analysis does not need to be repeated while Bob updates the list.",].join("\n"),);diff --git a/e2e/fixtures/agent-prompt-cache/agent/agent.ts b/e2e/fixtures/agent-prompt-cache/agent/agent.tsnew file mode 100644index 000000000..7f3fdd453--- /dev/null+++ b/e2e/fixtures/agent-prompt-cache/agent/agent.ts@@ -0,0 +1,8 @@+import { e2eAgentConfig } from "@eve-e2e/config";+import { defineAgent } from "eve";++export default defineAgent({+ ...e2eAgentConfig(),+ reasoning: "high",+ limits: { maxInputTokensPerSession: 300_000 },+});diff --git a/e2e/fixtures/agent-prompt-cache/agent/instructions.md b/e2e/fixtures/agent-prompt-cache/agent/instructions.mdnew file mode 100644index 000000000..4c4a1c9ac--- /dev/null+++ b/e2e/fixtures/agent-prompt-cache/agent/instructions.md@@ -0,0 +1,11 @@+You help Alice and Bob prepare purchasing reviews for a community centre event.++Answer general planning questions directly. When Alice supplies the purchasing+sheets and asks for reviews, delegate each sheet to a separate reviewer. Start+the five reviewers together so their work can proceed in parallel. The reviewers+can retrieve the stored purchasing sheets and their review questions through+review_sheet. Give each reviewer just its sheet number. Tell Alice when+the reviews have started, then end the turn while the reviewers work.++Keep track of the completed reviews as their notifications arrive. When all+five are complete, give Bob a brief summary of their findings.diff --git a/e2e/fixtures/agent-prompt-cache/agent/subagents/reviewer/agent.ts b/e2e/fixtures/agent-prompt-cache/agent/subagents/reviewer/agent.tsnew file mode 100644index 000000000..bf65e043c--- /dev/null+++ b/e2e/fixtures/agent-prompt-cache/agent/subagents/reviewer/agent.ts@@ -0,0 +1,9 @@+import { e2eSubagentConfig } from "@eve-e2e/config";+import { defineAgent } from "eve";++export default defineAgent({+ ...e2eSubagentConfig(),+ description:+ "Review one purchasing sheet. The review_sheet tool provides the sheet and its review question; the assignment only needs a sheet number.",+ reasoning: "low",+});diff --git a/e2e/fixtures/agent-prompt-cache/agent/subagents/reviewer/instructions.md b/e2e/fixtures/agent-prompt-cache/agent/subagents/reviewer/instructions.mdnew file mode 100644index 000000000..3c787fce8--- /dev/null+++ b/e2e/fixtures/agent-prompt-cache/agent/subagents/reviewer/instructions.md@@ -0,0 +1,3 @@+Use review_sheet to retrieve the assigned purchasing sheet and its review+question. Answer that question with the sheet number and findings in one short+sentence.diff --git a/e2e/fixtures/agent-prompt-cache/agent/subagents/reviewer/tools/review_sheet.ts b/e2e/fixtures/agent-prompt-cache/agent/subagents/reviewer/tools/review_sheet.tsnew file mode 100644index 000000000..50dd21166--- /dev/null+++ b/e2e/fixtures/agent-prompt-cache/agent/subagents/reviewer/tools/review_sheet.ts@@ -0,0 +1,19 @@+import { defineTool } from "eve/tools";+import { z } from "zod";+import { purchasingSheets } from "../../../../purchasing-sheets";++export default defineTool({+ description: "Wait for the purchasing review of one sheet and return its findings.",+ inputSchema: z.object({ sheet: z.number().int().min(1).max(5) }),+ async execute({ sheet }) {+ const startedAt = Date.now();+ // Keep reviews overlapping and let the parent acknowledge admission before completion.+ await new Promise((resolve) => setTimeout(resolve, 30_000 + sheet * 3_000));+ return {+ sheet,+ ...purchasingSheets[sheet - 1]!,+ startedAt,+ completedAt: Date.now(),+ };+ },+});diff --git a/e2e/fixtures/agent-prompt-cache/evals/evals.config.ts b/e2e/fixtures/agent-prompt-cache/evals/evals.config.tsnew file mode 100644index 000000000..7d2db339d--- /dev/null+++ b/e2e/fixtures/agent-prompt-cache/evals/evals.config.ts@@ -0,0 +1,3 @@+import { defineEvalConfig } from "eve/evals";++export default defineEvalConfig({ maxConcurrency: 1, timeoutMs: 240_000 });diff --git a/e2e/fixtures/agent-prompt-cache/evals/parallel-review.eval.ts b/e2e/fixtures/agent-prompt-cache/evals/parallel-review.eval.tsnew file mode 100644index 000000000..6f6dac4fc--- /dev/null+++ b/e2e/fixtures/agent-prompt-cache/evals/parallel-review.eval.ts@@ -0,0 +1,155 @@+import assert from "node:assert/strict";+import { defineEval, type EveEvalContext, type EveEvalTurn } from "eve/evals";+import { satisfies } from "eve/evals/expect";+import { z } from "zod";+import { purchasingSheets } from "../purchasing-sheets";++const reviewSchema = z.object({+ sheet: z.number().int().min(1).max(5),+ startedAt: z.number(),+ completedAt: z.number(),+});++export default ["first", "later"].map((launchTurn) =>+ defineEval({+ tags: ["real-model"],+ description: `Real provider cache hits survive five parallel reviews (${launchTurn} turn).`,+ async test(t) {+ if (launchTurn === "later") {+ const planning = await t.send(+ "Eight workshops have twelve places each. How many places is that in total?",+ );+ expectHealthyTurn(planning);+ planning.messageIncludes("96");+ planning.notEvent("actions.requested");+ }++ const started = await t.send(reviewPacket());+ const taskIds = expectFiveReviewers(started);+ const turns = await waitForReviews(t, started, taskIds);+ await expectParallelReviews(t, turns);+ expectCacheReuse(t, turns);+ },+ }),+);++function expectFiveReviewers(started: EveEvalTurn) {+ expectHealthyTurn(started);+ started.calledSubagent("reviewer", { count: 5 });+ const launchSteps = started.events+ .filter((event) => event.type === "actions.requested")+ .flatMap(({ data }) =>+ data.actions+ .filter((action) => action.kind === "tool-call" && action.toolName === "reviewer")+ .map(() => `${data.turnId}:${data.stepIndex}`),+ );+ assert.equal(launchSteps.length, 5, "five reviewer requests");+ assert.equal(new Set(launchSteps).size, 1, "all five reviewers launch in one model step");++ const taskIds = started.events+ .filter((event) => event.type === "subagent.completed")+ .flatMap(({ data }) => (data.backgroundTask ? [data.backgroundTask.taskId] : []));+ assert.equal(taskIds.length, 5, "five background task receipts");+ assert.equal(new Set(taskIds).size, 5, "five distinct background tasks");+ return taskIds;+}++async function waitForReviews(t: EveEvalContext, started: EveEvalTurn, taskIds: string[]) {+ const turns = [started];+ let cursor = t.state?.streamIndex;+ for (let attempt = 0; attempt < 10 && !allCompleted(turns, taskIds); attempt += 1) {+ assert(cursor !== undefined, "parent stream cursor is present");+ const live = t.target.watchTurn(started.sessionId, { startIndex: cursor });+ const turn = await live.result();+ expectHealthyTurn(turn);+ turns.push(turn);+ cursor = live.session.state?.streamIndex;+ }+ assert(allCompleted(turns, taskIds), "all five completion notifications reach the parent");+ assert(turns.length > 1, "background completion wakes the parent");+ const final = turns.at(-1)!;+ assert(final.message?.trim(), "parent reports the completed reviews");+ final.event("step.completed", { data: { finishReason: "stop" }, count: 1 });+ for (const turn of turns) turn.notEvent("compaction.completed");+ return turns;+}++function allCompleted(turns: EveEvalTurn[], taskIds: string[]) {+ const messages = turns+ .flatMap((turn) => turn.events)+ .filter((event) => event.type === "message.received")+ .map(({ data }) => data.message);+ return taskIds.every((id) =>+ messages.some(+ (message) =>+ message.includes(`Background task ${id} (`) && message.includes(" is completed."),+ ),+ );+}++async function expectParallelReviews(t: EveEvalContext, turns: EveEvalTurn[]) {+ const calls = turns+ .flatMap((turn) => turn.events)+ .filter((event) => event.type === "subagent.called")+ .filter(({ data }) => data.name === "reviewer");+ const childIds = calls.map(({ data }) => data.childSessionId);+ assert.equal(childIds.length, 5, "no repeated delegation");+ assert.equal(new Set(childIds).size, 5, "five distinct child sessions");+ const children = await Promise.all(childIds.map((id) => t.target.watchTurn(id).result()));+ const reviews = children.map((child) => {+ expectHealthyTurn(child);+ return reviewSchema.parse(child.requireToolCall("review_sheet").output);+ });+ assert.equal(new Set(reviews.map((review) => review.sheet)).size, 5, "all five sheets reviewed");+ const lastStarted = Math.max(...reviews.map((review) => review.startedAt));+ const firstFinished = Math.min(...reviews.map((review) => review.completedAt));+ assert(lastStarted < firstFinished, "all five reviews overlap");+}++function expectHealthyTurn(turn: EveEvalTurn) {+ turn.expectOk();+ turn.noFailedActions();+ turn.notEvent("step.failed");+ turn.notEvent("step.completed", { data: { finishReason: "content-filter" } });+ const steps = turn.events.filter((event) => event.type === "step.started");+ assert(steps.length > 0, "the turn calls a model");+ assert(+ steps.every(({ data }) => data.modelId === process.env.EVE_E2E_MODEL),+ "each request uses the real matrix model",+ );+}++function expectCacheReuse(t: EveEvalContext, turns: EveEvalTurn[]) {+ const steps = turns+ .flatMap((turn) => turn.events)+ .filter((event) => event.type === "step.completed");+ assert(steps.length >= 3, "multiple parent requests exercise cache reuse");+ assert(+ (steps[0]?.data.usage?.inputTokens ?? 0) >= 4_096,+ "review packet is large enough for conversation caching",+ );+ for (let index = 1; index < steps.length; index += 1) {+ const previousInput = steps[index - 1]!.data.usage?.inputTokens;+ const usage = steps[index]!.data.usage;+ assert(previousInput !== undefined, "preceding input token usage is present");+ assert(usage?.cacheReadTokens !== undefined, "provider cache-read usage is present");+ t.log(`Parent request ${index + 1}: ${JSON.stringify({ previousInput, ...usage })}`);+ // Allow a small margin for differences in provider token counts.+ t.check(+ usage.cacheReadTokens / previousInput,+ satisfies(+ (ratio: number) => ratio >= 0.98,+ `request ${index + 1} reads at least 98% of the preceding input from the provider cache`,+ ),+ );+ }+}++function reviewPacket(): string {+ const sheets = purchasingSheets+ .map(+ (sheet, index) => `Sheet ${index + 1}: ${sheet.title}\n${sheet.question}\n\n${sheet.notes}`,+ )+ .join("\n\n");+ return `Alice and Bob are preparing a community centre event. Please assign these five sheets to five reviewers so they can work in parallel. Each reviewer has access to the stored sheets and their review questions, so the sheet number is enough for its assignment. Let Alice know when the reviews are underway, then give Bob a brief summary once their findings are available.\n\n${sheets}`;+}diff --git a/e2e/fixtures/agent-prompt-cache/package.json b/e2e/fixtures/agent-prompt-cache/package.jsonnew file mode 100644index 000000000..bf39a7993--- /dev/null+++ b/e2e/fixtures/agent-prompt-cache/package.json@@ -0,0 +1,26 @@+{+ "name": "agent-prompt-cache",+ "version": "0.0.0",+ "private": true,+ "type": "module",+ "scripts": {+ "build": "eve build",+ "dev": "eve dev",+ "start": "eve start",+ "typecheck": "eve build && tsc",+ "test:e2e": "eve eval --strict"+ },+ "dependencies": {+ "@eve-e2e/config": "workspace:*",+ "@workflow/world-postgres": "catalog:",+ "eve": "workspace:*",+ "zod": "catalog:"+ },+ "devDependencies": {+ "@types/node": "catalog:",+ "typescript": "catalog:"+ },+ "e2e": {+ "modelMatrix": "full"+ }+}diff --git a/e2e/fixtures/agent-prompt-cache/purchasing-sheets.ts b/e2e/fixtures/agent-prompt-cache/purchasing-sheets.tsnew file mode 100644index 000000000..6c3d97799--- /dev/null+++ b/e2e/fixtures/agent-prompt-cache/purchasing-sheets.ts@@ -0,0 +1,67 @@+export const purchasingSheets = [+ {+ title: "Workshop materials",+ question: "Check whether the stationery quantities cover the planned workshops.",+ findings:+ "The stationery order covers eight workshops, with two unopened packs of paper reserved for replacements.",+ notes: `Alice is preparing materials for eight drawing workshops at the community centre. Each session has twelve places, although a few visitors may arrive without booking. The tutors prefer to place shared materials in the middle of each table rather than issue a separate set to every participant. This arrangement worked well during the spring programme and made it easier to put unused supplies away at the end of a session.++The order includes ten packs of drawing paper, six boxes of coloured pencils, four rolls of masking tape, and a carton of reusable folders. Eight paper packs are allocated to the scheduled sessions. The other two remain unopened in the storeroom so the afternoon coordinator can replace a damaged pack or accommodate an extra group. Pencils are shared between tables and returned to their boxes before the room is handed over to the next tutor.++There are already enough scissors, rulers, and washable table covers in the cupboard beside the studio. Alice checked these supplies with the caretaker on Monday. A few rulers have faded markings, but the tutors have agreed that they are still suitable for the introductory drawing exercises. Those items should therefore stay off the new order. Bob would like the review to distinguish replacements that are useful now from items that can wait until the next programme.++The folders are intended for visitors who want to carry their drawings home. They are not part of the reusable classroom stock. Any folders left over on Sunday should be counted and stored flat, away from the sink. The purchasing note asks the supplier to send the smallest available outer carton so it can fit on the shelving already in the storeroom. Alice is looking for a practical quantity check rather than a recommendation to change the workshop format.`,+ },+ {+ title: "Delivery timetable",+ question: "Confirm that the deliveries leave enough time to prepare the rooms.",+ findings:+ "Both deliveries are scheduled before Friday lunch, leaving the afternoon available for room preparation.",+ notes: `The community centre opens to suppliers at nine in the morning, before visitors begin arriving for regular activities. The stationery supplier has offered a Thursday slot between ten and eleven. The equipment hire company expects to arrive on Friday between nine and half past ten. Alice has recorded both windows in the caretaker's diary, along with the supplier names and the rooms that will eventually receive each delivery.++Friday afternoon is reserved for moving tables, setting out signs, and placing materials in the workshop rooms. The volunteers doing that work have other commitments in the morning, so Alice does not want the preparation period used for receiving large deliveries. The current timetable gives the caretaker time to count the cartons, compare them with the delivery notes, and raise any missing-item questions before the volunteers begin arranging the rooms.++The equipment company will bring folding display stands and two lightweight book trolleys. Its driver needs a clear route from the side entrance to the ground-floor hall. A regular movement class finishes in the hall at half past eight on Friday, and the instructor has agreed to return the mats to the cupboard before leaving. The centre's usual furniture remains in place until the caretaker has inspected the incoming stands. Nobody needs to leave equipment outside while waiting for a room to become available.++Bob asked whether the stationery could arrive on Friday as well. Alice prefers Thursday because it gives the tutors an opportunity to look through the materials during their planning meeting that evening. There is no extra delivery charge for the earlier slot. If either supplier requests a change, Alice will check the diary with the caretaker before accepting a replacement window. The review should establish whether the booked times support the preparation plan as it currently stands.`,+ },+ {+ title: "Receiving and storage",+ question: "Check that each delivery has a receiving contact and a suitable storage location.",+ findings:+ "The caretaker receives hired equipment in the hall; the reception coordinator signs for stationery and stores it upstairs.",+ notes: `Two people are responsible for receiving the supplies because the deliveries go to different parts of the building. The caretaker will sign for the hired display stands and book trolleys at the side entrance. The reception coordinator will sign for the stationery at the front desk. Alice has put their names on the corresponding order notes so the drivers can find the appropriate contact without asking a workshop tutor to leave a session.++The stationery cartons will first be counted at reception. The coordinator will then move them to the upstairs cupboard using the existing lift. That cupboard has an empty middle shelf reserved for the workshop materials. Paper and folders can lie flat there, while the pencil boxes will fit in the labelled tray on the shelf above. Cleaning products are kept in a different room, so the new supplies will not share storage with wet cloths or open bottles.++The hired equipment will remain in the ground-floor hall after the caretaker has checked it. Display stands should be folded until the volunteers start setting up on Friday afternoon. The trolleys can wait against the wall near the book storage room, leaving the doorway and the regular route through the hall clear. The caretaker has measured that space and confirmed there is room for both trolleys without moving the centre's own shelves.++Each receiving contact has a printed copy of the relevant order. They will note any differences on that copy and give it to Alice before leaving. The supplier's paperwork stays with the office records rather than travelling from room to room with the cartons. Bob wants the review to confirm that ownership and locations are clear; he is not asking for a new inventory system. Once the goods have been checked, the ordinary room preparation team can take over.`,+ },+ {+ title: "Purchasing allowance",+ question: "Compare the confirmed purchases with the available planning allowance.",+ findings:+ "The confirmed purchases total 460 against a planning allowance of 600; the optional shelving order remains deferred.",+ notes: `Bob set aside a planning allowance of 600 for the event materials and hired equipment. The stationery supplier's confirmed quotation is 180, including its Thursday delivery. The display stands and book trolleys cost 240 for the weekend. A further 40 covers the printed room signs and the large programme sheet that will stand beside reception. These three confirmed amounts total 460, leaving 140 available for small adjustments agreed before the event.++Alice has kept an optional shelving proposal separate from the confirmed purchases. The supplier sent a catalogue showing a unit that might be useful for future workshops, but the centre has not yet checked its dimensions against the storeroom. Bob asked for that decision to wait until the next facilities meeting. It should not appear in the event total merely because it arrived in the same email as the stationery quotation.++The hired items are collected on Monday morning, and the quoted hire amount includes that collection. The centre does not need to arrange another vehicle or add a second delivery charge. The printing estimate covers the agreed paper sizes and a single copy of the large programme sheet. Alice has asked the office to reuse the existing sign holders, which are already in good condition. Replacing those holders would create a new purchase outside the present list.++For this review, the amounts are the event team's internal planning figures, recorded in the same accounting unit. The arithmetic is straightforward, and Bob mainly wants a clear distinction between confirmed commitments and ideas that have not been approved. Any remaining allowance stays available until the last delivery has been checked. Alice will not place an additional order simply to use it up; leftover funds can remain in the centre's general programme budget.`,+ },+ {+ title: "Packing and returns",+ question: "Review the plan for returning hired items and storing leftover materials.",+ findings:+ "Volunteers pack the hired stands on Sunday, and the caretaker handles Monday collection after the remaining stationery is counted.",+ notes: `The last workshop ends at four on Sunday afternoon. Tutors will gather the shared pencils and tape before visitors leave the rooms, giving participants time to collect their drawings and any folders they have used. The volunteers then have an hour to fold the display stands, check the book trolleys, and bring the hired items back to the ground-floor hall. Alice has arranged for the caretaker to walk through the rooms before the centre closes.++The equipment company supplies reusable transport covers for the stands. Those covers will be kept together in the office during the event so nobody mistakes them for spare workshop material. On Sunday, the volunteers will put a cover around each folded stand and group the stands beside the trolleys. The collection driver can then check the hired items with the caretaker on Monday morning without reopening the upstairs workshop rooms.++Unused paper packs should stay sealed. Open packs will be counted separately and placed in the shallow tray on the middle shelf of the storeroom. Pencil boxes and tape rolls return to the labelled supply cupboard for ordinary classes. Folders that visitors have taken home are expected to remain with them; the closing count only covers the folders still at the centre. This distinction keeps the final materials note useful for planning the next programme.++Alice will collect the tutors' short comments at the Monday staff meeting. Bob wants to know which supplies ran low, which were left over, and whether the room setup was easy to return to normal. These observations will inform the next order, but they are separate from checking that the hired equipment has been returned. The review should confirm that the closing responsibilities form a complete sequence from the final workshop to Monday collection, with no item left waiting for an unnamed person to deal with it.`,+ },+] as const;diff --git a/e2e/fixtures/agent-prompt-cache/tsconfig.json b/e2e/fixtures/agent-prompt-cache/tsconfig.jsonnew file mode 100644index 000000000..85e3eceb8--- /dev/null+++ b/e2e/fixtures/agent-prompt-cache/tsconfig.json@@ -0,0 +1,17 @@+{+ "compilerOptions": {+ "target": "ES2022",+ "module": "esnext",+ "moduleResolution": "bundler",+ "outDir": "dist",+ "rootDir": ".",+ "strict": true,+ "esModuleInterop": true,+ "skipLibCheck": true,+ "forceConsistentCasingInFileNames": true,+ "declaration": true,+ "noEmit": true,+ "types": ["node"]+ },+ "include": ["agent/**/*.ts", "evals/**/*.ts"]+}diff --git a/e2e/fixtures/agent-task-reporting/agent/agent.ts b/e2e/fixtures/agent-task-reporting/agent/agent.tsindex 7d574b65f..2e553dc24 100644--- a/e2e/fixtures/agent-task-reporting/agent/agent.ts+++ b/e2e/fixtures/agent-task-reporting/agent/agent.ts@@ -1,18 +1,4 @@import { e2eAgentConfig } from "@eve-e2e/config";-import { gateway, wrapLanguageModel } from "ai";import { defineAgent } from "eve";-import { reportingMiddleware } from "./lib/reporting-model.js";--const base = e2eAgentConfig();--export default defineAgent({- ...base,- // Wrapped Gateway handles do not resolve through eve's catalog lookup.- // Both comparison arms use this fixture budget, well above the short cases.- modelContextWindowTokens: 128_000,- model: wrapLanguageModel({- model: typeof base.model === "string" ? gateway(base.model) : base.model,- middleware: reportingMiddleware,- }),-});+export default defineAgent(e2eAgentConfig());diff --git a/e2e/fixtures/agent-task-reporting/agent/lib/reporting-model.ts b/e2e/fixtures/agent-task-reporting/agent/lib/reporting-model.tsdeleted file mode 100644index 830730661..000000000--- a/e2e/fixtures/agent-task-reporting/agent/lib/reporting-model.ts+++ /dev/null@@ -1,48 +0,0 @@-import type { LanguageModelMiddleware } from "ai";--export type PendingInstruction = "on" | "off";--export function reportingControl(instruction: PendingInstruction): string {- return `<reporting-eval pending-instruction="${instruction}"/>\n`;-}--const PENDING_INSTRUCTION = "Background task control: incomplete cohort\n";--// Both arms remove their control marker before inference. Only the off arm-// removes the pending instruction; task state, results and other guidance stay.-export const reportingMiddleware: LanguageModelMiddleware = {- transformParams: async ({ params }) => {- let instruction: PendingInstruction | undefined;- const prompt = params.prompt.map((message) => {- if (message.role !== "user") return message;- return {- ...message,- content: message.content.map((part) => {- if (part.type !== "text") return part;- for (const variant of ["on", "off"] as const) {- const control = reportingControl(variant);- if (!part.text.startsWith(control)) continue;- instruction = variant;- return { ...part, text: part.text.slice(control.length) };- }- return part;- }),- };- });-- if (instruction !== "off") return { ...params, prompt };-- return {- ...params,- prompt: prompt.filter(- (message) =>- !(- message.role === "user" &&- message.content.length === 1 &&- message.content[0]?.type === "text" &&- message.content[0].text.startsWith(PENDING_INSTRUCTION)- ),- ),- };- },-};diff --git a/e2e/fixtures/agent-task-reporting/evals/consolidated-report.eval.ts b/e2e/fixtures/agent-task-reporting/evals/consolidated-report.eval.tsindex 2a8fd6ebb..23490794e 100644--- a/e2e/fixtures/agent-task-reporting/evals/consolidated-report.eval.ts+++ b/e2e/fixtures/agent-task-reporting/evals/consolidated-report.eval.ts@@ -3,9 +3,7 @@ import { satisfies } from "eve/evals/expect";import {completeReport,- intermediateWakes,requireStreamIndex,- silentWake,startWarehouseLookups,waitForPartialCompletion,waitForReport,@@ -14,7 +12,7 @@ import {function reportingEval() {return defineEval({description:- "A stock eve agent acknowledges accepted background work, keeps partial wakes silent, and reports all results after settlement.",+ "A stock eve agent acknowledges accepted background work and reports all results after compaction and task settlement.",tags: ["real-model"],async test(t) {const run = await startWarehouseLookups(t);@@ -46,9 +44,6 @@ function reportingEval() {run.session = compaction.session;const report = await waitForReport(t, run);- for (const wake of intermediateWakes(run)) {- await t.require(wake.message, silentWake());- }await t.require(report, completeReport());t.noFailedActions();},diff --git a/e2e/fixtures/agent-task-reporting/evals/pending-response.eval.ts b/e2e/fixtures/agent-task-reporting/evals/pending-response.eval.tsindex a8d17c282..dedbdf9b0 100644--- a/e2e/fixtures/agent-task-reporting/evals/pending-response.eval.ts+++ b/e2e/fixtures/agent-task-reporting/evals/pending-response.eval.ts@@ -1,39 +1,30 @@-import { defineEval, type Assertion, type EveEvalTurn } from "eve/evals";+import { defineEval, type EveEvalTurn } from "eve/evals";import { satisfies } from "eve/evals/expect";-import { reportingControl, type PendingInstruction } from "../agent/lib/reporting-model.js";import {completeReport,- intermediateWakes,QUESTION,sendQuestion,- silentWake,startWarehouseLookups,TASK_COUNT,waitForPartialCompletion,waitForReport,} from "./reporting.js";-function pendingResponseEval(pendingInstruction: PendingInstruction, silence: Assertion) {+function pendingResponseEval() {return defineEval({- description: `After an intermediate task wake, the parent answers a user before settlement, then reports all results (pending instruction ${pendingInstruction}).`,+ description:+ "After a partial completion, the parent answers a user while sibling tasks are running, then reports all results.",tags: ["real-model", "pending-response"],- metadata: { pendingInstruction },async test(t) {- const run = await startWarehouseLookups(t, reportingControl(pendingInstruction));+ const run = await startWarehouseLookups(t);await waitForPartialCompletion(t, run);const question = await sendQuestion(t, run);question.messageIncludes(/\b56\b/u);question.usedNoTools();- t.log(- `pending instruction ${pendingInstruction}: user reply=${JSON.stringify(question.message)}`,- );const report = await waitForReport(t, run);- for (const wake of intermediateWakes(run)) {- t.check(wake.message, silence);- }t.check(report, completeReport());t.notEvent("compaction.requested");@@ -68,17 +59,14 @@ function pendingResponseEval(pendingInstruction: PendingInstruction, silence: Assatisfies(Boolean, "the user received an answer before cohort settlement"),);t.log(- `pending instruction ${pendingInstruction}: asked=${askedAt} answered=${answeredAt} settled=${settledAt}`,+ `user reply=${JSON.stringify(question.message)} asked=${askedAt} answered=${answeredAt} settled=${settledAt}`,);t.noFailedActions();},});}-export default Array.from({ length: 20 }, () => [- pendingResponseEval("on", silentWake()),- pendingResponseEval("off", silentWake().soft(0)),-]).flat();+export default Array.from({ length: 20 }, pendingResponseEval);function completedAt(turn: EveEvalTurn): number {const event = turn.events.find((entry) => entry.type === "turn.completed");diff --git a/e2e/fixtures/agent-task-reporting/evals/reporting.ts b/e2e/fixtures/agent-task-reporting/evals/reporting.tsindex bd04c772b..1692c701a 100644--- a/e2e/fixtures/agent-task-reporting/evals/reporting.ts+++ b/e2e/fixtures/agent-task-reporting/evals/reporting.ts@@ -18,12 +18,9 @@ interface ReportingRun {session: EveEvalSession | EveEvalContext;}-export async function startWarehouseLookups(- t: EveEvalContext,- control = "",-): Promise<ReportingRun> {+export async function startWarehouseLookups(t: EveEvalContext): Promise<ReportingRun> {const started =- await t.send(`${control}Please find the inventory item at each of our three sample warehouses using the built-in agent tool. Start all three lookups in the background without waiting for their results. Delegate the lookups instead of calling probe yourself.+ await t.send(`Please find the inventory item at each of our three sample warehouses using the built-in agent tool. Start all three lookups in the background without waiting for their results. Delegate the lookups instead of calling probe yourself.1. "Call probe with check=first and report its result value."2. "Call probe with check=second and report its result value."@@ -117,16 +114,6 @@ export async function waitForReport(.at(-1)?.turn.message;}-export function intermediateWakes(run: ReportingRun): readonly EveEvalTurn[] {- return run.wakes- .filter((wake) => wake.completed > 0 && !wake.settled && !receivedQuestion(wake.turn))- .map((wake) => wake.turn);-}--export function silentWake() {- return satisfies((message) => message === undefined, "intermediate task wake is silent");-}-export function completeReport() {return satisfies((message: unknown) =>diff --git a/e2e/fixtures/agent-task-reporting/package.json b/e2e/fixtures/agent-task-reporting/package.jsonindex d7ce359bf..b42d86d14 100644--- a/e2e/fixtures/agent-task-reporting/package.json+++ b/e2e/fixtures/agent-task-reporting/package.json@@ -8,13 +8,11 @@"dev": "eve dev","start": "eve start","typecheck": "eve build && tsc",- "test:e2e": "eve eval --strict",- "test:unit": "node --test test/*.test.mjs"+ "test:e2e": "eve eval --strict"},"dependencies": {"@eve-e2e/config": "workspace:*","@workflow/world-postgres": "catalog:",- "ai": "catalog:","eve": "workspace:*","just-bash": "3.1.0","zod": "catalog:"diff --git a/e2e/fixtures/agent-task-reporting/test/reporting-model.test.mjs b/e2e/fixtures/agent-task-reporting/test/reporting-model.test.mjsdeleted file mode 100644index 9e75cca74..000000000--- a/e2e/fixtures/agent-task-reporting/test/reporting-model.test.mjs+++ /dev/null@@ -1,61 +0,0 @@-import assert from "node:assert/strict";-import { readFileSync } from "node:fs";-import { test } from "node:test";--import { reportingControl, reportingMiddleware } from "../agent/lib/reporting-model.ts";--const source = readFileSync(- new URL("../../../../packages/eve/src/tasks/delivery-context.ts", import.meta.url),- "utf8",-);-const pending = source.match(/TASK_DELIVERY_PENDING_INSTRUCTION = `([\s\S]*?)`;/)[1];-const user = (text) => ({ role: "user", content: [{ type: "text", text }] });--async function transform(variant) {- const prompt = [- { role: "system", content: "You are a helpful assistant." },- user(`${reportingControl(variant)}Start the lookups.`),- user('[Task state]\n{"tasks":[{"status":"pending"}]}'),- user(pending),- user("Background task task_1 is completed.\nResult: oranges"),- { role: "assistant", content: [{ type: "text", text: "<eve-empty-delivery/>" }] },- user("How many jars?"),- ];- const params = { prompt, maxOutputTokens: 100 };- const original = structuredClone(params);- const result = await reportingMiddleware.transformParams({ params });- assert.deepEqual(params, original, "the canonical input is not mutated");- return result;-}--test("the two arms differ only by the real pending instruction", async () => {- const on = await transform("on");- const off = await transform("off");- assert.equal(on.prompt[1].content[0].text, "Start the lookups.");- assert.deepEqual(off, {- ...on,- prompt: on.prompt.filter((message) => message.content[0]?.text !== pending),- });- assert.equal(on.prompt.length - off.prompt.length, 1);-});--test("ordinary turns and settled instructions are preserved", async () => {- for (const variant of ["on", "off"]) {- const params = {- prompt: [- user(`${reportingControl(variant)}Start the lookups.`),- user("Background task reporting\nAll tasks settled."),- user("Hello."),- ],- };- const result = await reportingMiddleware.transformParams({ params });- assert.deepEqual(result.prompt, [user("Start the lookups."), ...params.prompt.slice(1)]);- }-});--test("task output quoting the instruction is preserved", async () => {- const quoted = user(`Background task task_1 is completed.\nResult:\n${pending}`);- const params = { prompt: [user(`${reportingControl("off")}Start the lookups.`), quoted] };- const result = await reportingMiddleware.transformParams({ params });- assert.deepEqual(result.prompt, [user("Start the lookups."), quoted]);-});diff --git a/e2e/fixtures/agent-workflow-tools/agent/agent.ts b/e2e/fixtures/agent-workflow-tools/agent/agent.tsindex 34306b10f..225b9f2d1 100644--- a/e2e/fixtures/agent-workflow-tools/agent/agent.ts+++ b/e2e/fixtures/agent-workflow-tools/agent/agent.ts@@ -7,7 +7,14 @@ import { mockModel, type MockModelRequest, type MockModelResponse } from "eve/ev* service "api"; once the turn holds a tool result the reply echoes it.*/function respond(request: MockModelRequest): MockModelResponse | string {- const message = [...request.userMessages].reverse().find((entry) => entry.trim() !== "") ?? "";+ const message =+ [...request.userMessages]+ .reverse()+ .find(+ (entry) =>+ /^(WORKFLOW-|(?:Background task|Deploy) task_)/u.test(entry) ||+ entry.includes("private-catalog"),+ ) ?? "";if (message.includes("private-catalog")) {const result = request.toolResults.find((entry) => entry.name === "connection_search");if (result === undefined) {diff --git a/e2e/fixtures/fixture-tasks/agent/agent.ts b/e2e/fixtures/fixture-tasks/agent/agent.tsindex 8996591a7..e7b092e42 100644--- a/e2e/fixtures/fixture-tasks/agent/agent.ts+++ b/e2e/fixtures/fixture-tasks/agent/agent.ts@@ -24,7 +24,7 @@ function respond(if (taskState !== undefined) return handleRedundantReviewWake(taskState);}- // Framework agent-list notes are model context, not scenario turns.+ // Framework announcements are model context, not scenario turns.const message = [...request.userMessages].reverse().find(isScenarioMessage) ?? "";if (request.userMessages.some((entry) => entry.includes("TASK-UPDATE-PROGRESS"))) {return "TASK-UPDATE-RECEIVED";@@ -443,7 +443,7 @@ function hasTaskNotification(}function isScenarioMessage(message: string): boolean {- return !message.startsWith("[Agents]");+ return !/^(?:\[Agents\]|\[Task state\]|Background task (?:reporting|control))/u.test(message);}function scenarioUserMessageCount(request: MockModelRequest): number {diff --git a/packages/eve/src/context/keys.ts b/packages/eve/src/context/keys.tsindex 4d23e9b3a..85da9d034 100644--- a/packages/eve/src/context/keys.ts+++ b/packages/eve/src/context/keys.ts@@ -95,8 +95,13 @@ export const TurnDeliveryIdsKey = new ContextKey<readonly string[]>("eve.turnDelexport const TurnTaskDeliveryKey = new ContextKey<"none" | "initiating" | "pending" | "settled">("eve.turnTaskDelivery",);-/** Framework-authored task state supplied to the model without altering user-message history. */-export const TurnTaskStateKey = new ContextKey<string>("eve.turnTaskState");+/** Last framework announcements recorded in the retained session history. */+export interface HistoryState {+ readonly availableSkills?: string;+ readonly taskState?: string;+ readonly deliveryInstruction?: string;+}+export const HistoryStateKey = new ContextKey<HistoryState>("eve.historyState");export interface ActiveChannelDelivery {readonly agentName?: string;readonly channelType?: string;diff --git a/packages/eve/src/execution/skills/instructions.ts b/packages/eve/src/execution/skills/instructions.tsindex fd9789329..693b833a5 100644--- a/packages/eve/src/execution/skills/instructions.ts+++ b/packages/eve/src/execution/skills/instructions.ts@@ -34,6 +34,7 @@ export function formatAvailableSkillsSection(const lines = ["Available skills","Listed skills are available in this run. Do not claim a listed skill is inaccessible unless activation or workspace inspection actually fails.",+ "Dynamic skill announcements update this list. They replace earlier dynamic skills and override static skills with the same name.","If the user names a skill or the request clearly matches one of the descriptions below, call load_skill before proceeding.","If multiple skills match, activate the minimal set that covers the task. After activation, follow the returned instructions instead of improvising around them.","If activation fails, say so briefly and continue with the best available alternative.",diff --git a/packages/eve/src/execution/workflow-steps.test.ts b/packages/eve/src/execution/workflow-steps.test.tsindex 03980b8e3..f6bc9a437 100644--- a/packages/eve/src/execution/workflow-steps.test.ts+++ b/packages/eve/src/execution/workflow-steps.test.ts@@ -24,7 +24,7 @@ import {SessionTraceSeedKey,TurnDeliveryIdsKey,TurnTaskDeliveryKey,- TurnTaskStateKey,+ HistoryStateKey,} from "#context/keys.js";import { BundleKey, ChannelKey } from "#runtime/sessions/runtime-context-keys.js";import { serializeContext } from "#context/serialize.js";@@ -1660,7 +1660,10 @@ describe("turnStep", () => {});it("keeps a session-scoped dynamic model selection when the first turn is cancelled", async () => {- const session = createStubSession();+ const announcement = "Available skills\n- policy: Tenant policy";+ const session = createStubSession({+ history: [{ role: "user", content: announcement }],+ });installSessionStoreMocks([session]);vi.mocked(getCompiledRuntimeAgentBundle).mockResolvedValue({adapterRegistry: {@@ -1689,6 +1692,7 @@ describe("turnStep", () => {contextWindowTokens: 1_000_000,});ctx.set(ThreadKey, "discard this turn-scoped mutation");+ ctx.delete(HistoryStateKey);throw new TurnCancelledError();};});@@ -1710,6 +1714,7 @@ describe("turnStep", () => {serializedContext: {...createSerializedContext(),[TurnDeliveryIdsKey.name]: ["previous-delivery"],+ [HistoryStateKey.name]: { availableSkills: announcement },},sessionState: createStubSessionState(),});@@ -1718,6 +1723,7 @@ describe("turnStep", () => {action: "cancelled",serializedContext: {[TurnDeliveryIdsKey.name]: ["cancelled-delivery"],+ [HistoryStateKey.name]: { availableSkills: announcement },[SessionDynamicModelReferenceKey.name]: {id: "anthropic/claude-opus-4.6",contextWindowTokens: 1_000_000,@@ -1726,6 +1732,7 @@ describe("turnStep", () => {});expect(result.serializedContext).not.toHaveProperty(ThreadKey.name);expect(result.sessionState.snapshot?.session.history).toEqual([+ { role: "user", content: announcement },{ content: "thread=unset; user=cancel this turn", role: "user" },]);});@@ -2217,7 +2224,6 @@ describe("turnStep", () => {it("sets task-delivery provenance only when the runtime supplies owned task state", async () => {const observedTaskDeliveries: unknown[] = [];- const observedTaskStates: unknown[] = [];const metadata = { kind: "report-probe", name: "report_probe" } as const;const session = createStubSession({state: {@@ -2245,13 +2251,11 @@ describe("turnStep", () => {vi.mocked(createExecutionNodeStep).mockImplementation(() => {return async (stepSession): Promise<StepResult> => {observedTaskDeliveries.push(contextStorage.getStore()?.get(TurnTaskDeliveryKey));- observedTaskStates.push(contextStorage.getStore()?.get(TurnTaskStateKey));return { next: { done: true, output: "ok" }, session: stepSession };};});const initialSerializedContext = createSerializedContext();- initialSerializedContext[TurnTaskStateKey.name] = "stale task state";const first = await turnStep({input: {@@ -2281,10 +2285,9 @@ describe("turnStep", () => {});expect(observedTaskDeliveries).toEqual(["settled", "none", "none"]);- expect(observedTaskStates).toEqual([undefined, undefined, undefined]);});- it("supplies initiating task state after the active turn accepts delegated work", async () => {+ it.each(["none", "initiating"] as const)("sets initiating task phase (%s)", async (phase) => {const tasksBundle = {adapterRegistry: {adaptersByKind: new Map([[threadContextAdapter.kind, threadContextAdapter]]),@@ -2336,17 +2339,15 @@ describe("turnStep", () => {let observedInput: unknown;let observedPhase: unknown;- let observedTaskState: unknown;vi.mocked(createExecutionNodeStep).mockImplementation(() => {return async (stepSession, stepInput): Promise<StepResult> => {observedInput = stepInput;observedPhase = contextStorage.getStore()?.get(TurnTaskDeliveryKey);- observedTaskState = contextStorage.getStore()?.get(TurnTaskStateKey);return { next: { done: true, output: "ok" }, session: stepSession };};});const serializedContext = createSerializedContext();- serializedContext[TurnTaskDeliveryKey.name] = "none";+ serializedContext[TurnTaskDeliveryKey.name] = phase;await turnStep({input: undefined,@@ -2363,9 +2364,6 @@ describe("turnStep", () => {});expect(observedPhase).toBe("initiating");- expect(observedTaskState).toBe(- '[Task state]\n{"tasks":[{"name":"report_probe","status":"pending","taskId":"task_1"}]}',- );expect(observedInput).toBeUndefined();});diff --git a/packages/eve/src/execution/workflow-steps.ts b/packages/eve/src/execution/workflow-steps.tsindex 865d0c57f..86ed25447 100644--- a/packages/eve/src/execution/workflow-steps.ts+++ b/packages/eve/src/execution/workflow-steps.ts@@ -31,7 +31,6 @@ import {SessionDynamicToolRuntimeRevisionKey,TurnTaskDeliveryKey,TurnDeliveryIdsKey,- TurnTaskStateKey,} from "#context/keys.js";import { BundleKey, ChannelKey } from "#runtime/sessions/runtime-context-keys.js";import { deserializeContext, serializeContext } from "#context/serialize.js";@@ -125,7 +124,6 @@ export async function turnStep(rawInput: TurnStepInput): Promise<DurableStepResuconst ctx = await deserializeContext(input.serializedContext);if (rawInput.input?.kind === "deliver") {ctx.set(TurnTaskDeliveryKey, "none");- ctx.delete(TurnTaskStateKey);}const adapter = ctx.require(ChannelKey);const bundle = ctx.require(BundleKey);@@ -284,14 +282,14 @@ export async function turnStep(rawInput: TurnStepInput): Promise<DurableStepResu}}- if (ctx.get(TurnTaskDeliveryKey) === "none") {+ const taskDeliveryPhase = ctx.get(TurnTaskDeliveryKey);+ if (taskDeliveryPhase === "none" || taskDeliveryPhase === "initiating") {const taskContext = resolveInitiatingTaskContext({state: durableSession.state,turnId: activeTurnId(initialEmissionState),});if (taskContext !== undefined) {ctx.set(TurnTaskDeliveryKey, taskContext.phase);- ctx.set(TurnTaskStateKey, taskContext.context);}}diff --git a/packages/eve/src/harness/current-messages.test.ts b/packages/eve/src/harness/current-messages.test.tsindex 210b0cd4e..2aa9c8204 100644--- a/packages/eve/src/harness/current-messages.test.ts+++ b/packages/eve/src/harness/current-messages.test.ts@@ -27,14 +27,18 @@ describe("createCurrentMessages", () => {expect(current.systemMessages).toEqual([{ role: "system", content: "system" }]);});- it("keeps first-turn context in instructions and routes later context as user messages", () => {+ it("persists framework context as user messages from the first turn", () => {const current = createCurrentMessages([]);- current.add(0, "first");- current.add(1, "later");+ current.add("first");+ current.add("later");- expect(current.systemMessages).toEqual([{ role: "system", content: "first" }]);- expect(current.nonSystemMessages).toEqual([{ role: "user", content: "later" }]);+ expect(current.systemMessages).toEqual([]);+ expect(current.nonSystemMessages).toEqual([+ { role: "user", content: "first" },+ { role: "user", content: "later" },+ ]);+ expect(current.history).toEqual(current.nonSystemMessages);});it("inserts later context before the current turn input", () => {@@ -47,8 +51,8 @@ describe("createCurrentMessages", () => {{ currentTurnMessages },);- current.add(1, "task state");- current.add(1, "delivery guidance");+ current.add("task state");+ current.add("delivery guidance");expect(current.nonSystemMessages).toEqual([{ role: "user", content: "history" },@@ -59,6 +63,82 @@ describe("createCurrentMessages", () => {]);});+ it("appends messages without interpreting their text", () => {+ const current = createCurrentMessages([+ { role: "user", content: "[Task state]\nuser-authored text" },+ ]);++ current.add("[Task state]\nworking");+ current.add("[Task state]\nworking");++ expect(current.history.map((message) => message.content)).toEqual([+ "[Task state]\nuser-authored text",+ "[Task state]\nworking",+ "[Task state]\nworking",+ ]);+ });++ it("prepares tracked announcements without advancing the recorded baseline", () => {+ const recorded = { taskState: "working" };+ const current = createCurrentMessages([{ role: "user", content: "working" }], {+ historyState: recorded,+ });++ current.addAnnouncements({ taskState: "working" });+ current.addAnnouncements({ taskState: "completed" });+ current.addAnnouncements({ taskState: "completed", availableSkills: "completed" });++ expect(recorded).toEqual({ taskState: "working" });+ expect(current.historyState).toEqual({ taskState: "completed", availableSkills: "completed" });+ expect(current.history.map((message) => message.content)).toEqual([+ "working",+ "completed",+ "completed",+ ]);+ });++ it("keeps announcement order stable and ignores empty or absent values", () => {+ const current = createCurrentMessages([]);+ current.addAnnouncements({+ deliveryInstruction: "report",+ taskState: "working",+ availableSkills: "skills",+ });+ current.addAnnouncements({ availableSkills: "", taskState: undefined });++ expect(current.history.map((message) => message.content)).toEqual([+ "skills",+ "working",+ "report",+ ]);+ expect(current.historyState).toEqual({+ availableSkills: "skills",+ taskState: "working",+ deliveryInstruction: "report",+ });+ });++ it("persists additions without storing client context or replacing projected history", () => {+ const hidden = { role: "user" as const, content: "hidden by projection" };+ const input = { role: "user" as const, content: "request" };+ const current = createCurrentMessages([hidden, input], {+ currentTurnMessages: [input],+ projectedMessages: [{ role: "user", content: "ephemeral client context" }, input],+ });+ current.add("[Task state]\nworking");+ current.addSystem({ role: "system", content: "turn-scoped instructions" });+ expect(current.history).toEqual([+ hidden,+ { role: "user", content: "[Task state]\nworking" },+ input,+ ]);+ expect(current.nonSystemMessages).toEqual([+ { role: "user", content: "ephemeral client context" },+ { role: "user", content: "[Task state]\nworking" },+ input,+ ]);+ });+it("keeps later context out of the tail when history ends with an approval response", () => {const approvalTail = {role: "tool" as const,@@ -82,16 +162,17 @@ describe("createCurrentMessages", () => {approvalTail,]);- current.add(1, "task state");+ current.addAnnouncements({ taskState: "task state" });expect(current.systemMessages).toEqual([{ role: "system", content: "task state" }]);expect(current.nonSystemMessages.at(-1)).toBe(approvalTail);+ expect(current.historyState).toEqual({});});it("keeps hierarchy-sensitive context in instructions when requested", () => {const current = createCurrentMessages([]);- current.add(1, "authoritative", { cacheFriendly: false });+ current.add("authoritative", { cacheFriendly: false });expect(current.systemMessages).toEqual([{ role: "system", content: "authoritative" }]);expect(current.nonSystemMessages).toEqual([]);diff --git a/packages/eve/src/harness/current-messages.ts b/packages/eve/src/harness/current-messages.tsindex b0be5d6b3..9e886cead 100644--- a/packages/eve/src/harness/current-messages.ts+++ b/packages/eve/src/harness/current-messages.ts@@ -1,29 +1,37 @@import type { ModelMessage, SystemModelMessage } from "ai";+import type { HistoryState } from "#context/keys.js";interface AddCurrentMessageOptions {readonly cacheFriendly?: boolean;}interface CurrentMessagesOptions {+ readonly historyState?: HistoryState;readonly currentTurnMessages?: readonly ModelMessage[];+ readonly projectedMessages?: readonly ModelMessage[];}-/** Model-call messages with cache-friendly placement for turn-local context. */+/** Builds the model view and durable history for one step. */export function createCurrentMessages(history: readonly ModelMessage[],options: CurrentMessagesOptions = {},): {+ readonly history: readonly ModelMessage[];+ readonly historyState: HistoryState;readonly nonSystemMessages: readonly ModelMessage[];readonly systemMessages: readonly SystemModelMessage[];- add(turnSequence: number, message: string, options?: AddCurrentMessageOptions): void;+ add(message: string, options?: AddCurrentMessageOptions): void;+ addAnnouncements(announcements: HistoryState): void;addSystem(messages: SystemModelMessage | readonly SystemModelMessage[]): void;} {+ const durableMessages = [...history];+ const historyState = { ...options.historyState };const systemMessages: SystemModelMessage[] = [];const nonSystemMessages: ModelMessage[] = [];const currentTurnMessages = new Set(options.currentTurnMessages);let currentTurnInsertionIndex: number | undefined;- for (const message of history) {+ for (const message of options.projectedMessages ?? history) {if (currentTurnInsertionIndex === undefined && currentTurnMessages.has(message)) {currentTurnInsertionIndex = nonSystemMessages.length;}@@ -34,19 +42,35 @@ export function createCurrentMessages(}}let userInsertionIndex = currentTurnInsertionIndex ?? nonSystemMessages.length;+ const currentInputIndex = history.findIndex((message) => currentTurnMessages.has(message));+ let historyInsertionIndex = currentInputIndex === -1 ? history.length : currentInputIndex;// The AI SDK collects approval responses only from the tail tool message.// Appending user-role context there would skip the approved tool's// execution and send the provider a tool call with no result.const canAppendUserMessages =currentTurnInsertionIndex !== undefined || !hasTailApprovalResponse(nonSystemMessages);+ function add(message: string, { cacheFriendly = true }: AddCurrentMessageOptions = {}): boolean {+ if (cacheFriendly && canAppendUserMessages) {+ const entry = { role: "user" as const, content: message };+ nonSystemMessages.splice(userInsertionIndex, 0, entry);+ durableMessages.splice(historyInsertionIndex, 0, entry);+ userInsertionIndex += 1;+ historyInsertionIndex += 1;+ return true;+ }+ systemMessages.push({ role: "system", content: message });+ return false;+ }+return {- add(turnSequence, message, { cacheFriendly = true } = {}) {- if (turnSequence > 0 && cacheFriendly === true && canAppendUserMessages) {- nonSystemMessages.splice(userInsertionIndex, 0, { role: "user", content: message });- userInsertionIndex += 1;- } else {- systemMessages.push({ role: "system", content: message });+ add,+ addAnnouncements(announcements) {+ for (const key of ["availableSkills", "taskState", "deliveryInstruction"] as const) {+ const message = announcements[key];+ if (message === undefined || message.length === 0 || historyState[key] === message)+ continue;+ if (add(message)) historyState[key] = message;}},addSystem(messages) {@@ -55,6 +79,12 @@ export function createCurrentMessages(get nonSystemMessages() {return [...nonSystemMessages];},+ get history() {+ return [...durableMessages];+ },+ get historyState() {+ return { ...historyState };+ },get systemMessages() {return [...systemMessages];},diff --git a/packages/eve/src/harness/tool-loop-generate-approval-resume.integration.test.ts b/packages/eve/src/harness/tool-loop-generate-approval-resume.integration.test.tsindex 0a7830e41..b8a4918e1 100644--- a/packages/eve/src/harness/tool-loop-generate-approval-resume.integration.test.ts+++ b/packages/eve/src/harness/tool-loop-generate-approval-resume.integration.test.ts@@ -12,12 +12,13 @@ import type { OldSourceOffsetDynamicToolMetadata } from "#context/dynamic-tool-mimport { PendingSkillAnnouncementKey } from "#context/dynamic-skill-lifecycle.js";import {AuthKey,+ HistoryStateKey,SessionKey,SessionIdKey,SessionDynamicToolMetadataKey,TurnDynamicToolMetadataKey,StepDynamicToolMetadataKey,- TurnTaskStateKey,+ TurnTaskDeliveryKey,} from "#context/keys.js";import { setHarnessEmissionState } from "#harness/emission.js";import type { HarnessToolDefinition } from "#harness/execute-tool.js";@@ -27,6 +28,7 @@ import { getPendingInputBatches } from "#harness/pending-input-batches.js";import { createToolLoopHarness } from "#harness/tool-loop.js";import { setTurnUsageState } from "#harness/turn-tag-state.js";import type { HarnessSession, ToolLoopHarnessConfig } from "#harness/types.js";+import { recordSessionTask } from "#tasks/session-index.js";import { once } from "#tools/approval/policies.js";import { defineTool } from "#tools/definition.js";import {@@ -836,12 +838,15 @@ describe("tool loop generate approval resume (real AI SDK)", () => {// and the provider rejected the prompt with a tool call that had no output.it.each([- { key: PendingSkillAnnouncementKey, label: "dynamic skill announcement" },- { key: TurnTaskStateKey, label: "task state" },+ {+ label: "dynamic skill announcement",+ historyKey: "availableSkills" as const,+ },+ { label: "task state", historyKey: "taskState" as const },].flatMap((context) => [false, true].map((restoredAnchor) => ({ ...context, restoredAnchor }))),)("executes the approved tool when $label is injected on the resume step (restored anchor: $restoredAnchor)",- async ({ key, restoredAnchor }) => {+ async ({ historyKey, restoredAnchor }) => {const siblingCall = {input: { command: "whoami" },toolCallId: "call-sibling",@@ -854,7 +859,7 @@ describe("tool loop generate approval resume (real AI SDK)", () => {toolName: "bash",type: "tool-result" as const,};- const session = appendPendingInputBatch({+ let session = appendPendingInputBatch({requests: [pendingApprovalInputRequest],// The parked shape when a gated call shares a step with an ungated one.responseMessages: [@@ -864,12 +869,29 @@ describe("tool loop generate approval resume (real AI SDK)", () => {session: createBaseSession(),});const ctx = new ContextContainer();- ctx.set(key, "[Runtime context]\nInjected on the resume step.");+ const runtimeContextAnnouncement =+ historyKey === "taskState"+ ? '[Task state]\n{"tasks":[{"name":"analysis","status":"pending","taskId":"analysis"}]}'+ : "Available skills\n- policy: Tenant policy";+ if (historyKey === "taskState") {+ ctx.set(TurnTaskDeliveryKey, "initiating");+ session = recordSessionTask(session, {+ createdByTurnId: "turn-1",+ executor: { data: {}, kind: "workflow-tool" },+ metadata: { kind: "report-probe", name: "analysis" },+ taskId: "analysis",+ taskInboxToken: "task-token",+ taskRunId: "task-run",+ });+ } else {+ ctx.set(PendingSkillAnnouncementKey, runtimeContextAnnouncement);+ }const execute = vi.fn(async () => "/workspace");const model = createModel();+ const runStep = createToolLoopHarness(createConfig(model, execute));const result = await contextStorage.run(ctx, () =>- createToolLoopHarness(createConfig(model, execute))(+ runStep(setHarnessEmissionState(restoredAnchor? setTurnClientContextState(session, {@@ -907,10 +929,21 @@ describe("tool loop generate approval resume (real AI SDK)", () => {expect(called).toEqual([toolCall.toolCallId, siblingCall.toolCallId]);expect(called.filter((id) => !answered.has(id))).toEqual([]);expect(providerPrompt.at(-1)?.role).toBe("tool");+ expect(ctx.get(HistoryStateKey)).toEqual({});expect(result.session.history.at(-1)).toMatchObject({content: [{ text: "The command returned /workspace.", type: "text" }],role: "assistant",});++ const continued = await contextStorage.run(ctx, () =>+ runStep(result.session, { message: "Continue." }),+ );+ expect(+ continued.session.history.filter(+ (message) => message.content === runtimeContextAnnouncement,+ ),+ ).toHaveLength(1);+ expect(ctx.get(HistoryStateKey)).toMatchObject({ [historyKey]: runtimeContextAnnouncement });},);diff --git a/packages/eve/src/harness/tool-loop.test.ts b/packages/eve/src/harness/tool-loop.test.tsindex 7e55a83bf..03dc76bc1 100644--- a/packages/eve/src/harness/tool-loop.test.ts+++ b/packages/eve/src/harness/tool-loop.test.ts@@ -18,6 +18,7 @@ import { dispatchDynamicInstructionEvent } from "#context/dynamic-instruction-liimport {AuthKey,ChannelInstrumentationKey,+ HistoryStateKey,InitiatorAuthKey,LiveStepDynamicModelSelectionKey,ParentSessionKey,@@ -31,7 +32,6 @@ import {SessionDynamicSubagentSelectionsKey,StepDynamicToolMetadataKey,TurnTaskDeliveryKey,- TurnTaskStateKey,} from "#context/keys.js";import { SCHEDULE_APP_AUTH } from "#channel/schedule-auth.js";import { invocationOwnerKey } from "#internal/invocation/metadata.js";@@ -68,9 +68,13 @@ import {hasPendingInputBatch,appendPendingInputBatch,} from "#harness/input-requests.js";+import { activeTurnId } from "#harness/active-turn-id.js";+import { recordSessionTask } from "#tasks/session-index.js";import { getPendingCoordinationBatch } from "#harness/coordination.js";import { AGENT_HANDLES_STATE_KEY } from "#subagents/handles/store.js";import { BackgroundToolExecutorKey } from "#harness/background-tools.js";+import { PendingSkillAnnouncementKey } from "#context/dynamic-skill-lifecycle.js";+import { deserializeContext, serializeContext } from "#context/serialize.js";import { stashToolInterrupt } from "#harness/tool-interrupts.js";import { appendMissingToolResultMessages, createToolLoopHarness } from "#harness/tool-loop.js";import { isSessionLimitDecline, TurnCancelledError } from "#harness/turn-cancellation.js";@@ -95,7 +99,6 @@ import {} from "#shared/empty-delivery.js";import {TASK_DELIVERY_INITIATING_INSTRUCTION,- TASK_DELIVERY_PENDING_INSTRUCTION,TASK_DELIVERY_SETTLED_INSTRUCTION,} from "#tasks/delivery-context.js";@@ -262,6 +265,20 @@ function createTestSession(overrides?: Partial<HarnessSession>): HarnessSession};}+const analysisTaskAnnouncement =+ '[Task state]\n{"tasks":[{"name":"analysis","status":"pending","taskId":"analysis"}]}';++function recordBackgroundTask(session: HarnessSession, taskId = "analysis"): HarnessSession {+ return recordSessionTask(session, {+ createdByTurnId: activeTurnId(getHarnessEmissionState(session.state)),+ executor: { data: {}, kind: "workflow-tool" },+ metadata: { kind: "report-probe", name: taskId },+ taskId,+ taskInboxToken: `token-${taskId}`,+ taskRunId: `run-${taskId}`,+ });+}+function createTestConfig(mode: RunMode = "conversation",emit?: HarnessEmitFn,@@ -9755,11 +9772,13 @@ describe("createToolLoopHarness", () => {const session = createTestSession({history: [{ content: "old message", role: "user" }],});-- const result = await runStep(session);+ const ctx = new ContextContainer();+ ctx.set(HistoryStateKey, { taskState: "old message" });+ const result = await contextStorage.run(ctx, () => runStep(session));expect(result.next).toBeNull();expect(result.session).toBe(session);+ expect(ctx.get(HistoryStateKey)).toEqual({ taskState: "old message" });expect(getCompatibilityEventTypes(events)).toEqual(["compaction.requested", "session.waiting"]);expect(ToolLoopAgent).not.toHaveBeenCalled();});@@ -12296,9 +12315,13 @@ describe("createToolLoopHarness", () => {});});- it.each(["plain", "client context", "compaction", "projected history"])(- "keeps framework context before the turn input across durable steps (%s)",- async (scenario) => {+ it.each(+ ["plain", "client context", "compaction", "projected history"].flatMap((scenario) =>+ [false, true].map((changed) => ({ scenario, changed })),+ ),+ )(+ "persists framework context across durable steps ($scenario, changed: $changed)",+ async ({ scenario, changed }) => {const withClientContext = scenario === "client context";if (scenario === "compaction") {vi.mocked(shouldCompact).mockReturnValueOnce(true);@@ -12329,7 +12352,7 @@ describe("createToolLoopHarness", () => {toolResults: [{ ...toolResult, input: toolCall.input }],});const ctx = new ContextContainer();- ctx.set(TurnTaskStateKey, "Task status: analysis in progress");+ ctx.set(TurnTaskDeliveryKey, "initiating");const runStep = createToolLoopHarness(createTestConfig("conversation", undefined, {historyProjector:@@ -12351,23 +12374,212 @@ describe("createToolLoopHarness", () => {const input = { context: ["Current channel context"], message: "Add 20 and 22." };const first = await contextStorage.run(ctx, () =>runStep(- initial,+ recordBackgroundTask(initial),withClientContext ? attachClientContext(input, ["Client context"]) : input,),);expect(first.next).toBe(runStep);const firstPrompt = structuredClone(getLastAgentSettings().messages);+ expect(first.session.history).toContainEqual({+ role: "user",+ content: analysisTaskAnnouncement,+ });+ const nextState = changed+ ? '[Task state]\n{"tasks":[{"name":"analysis","status":"pending","taskId":"analysis"},{"name":"verification","status":"pending","taskId":"verification"}]}'+ : analysisTaskAnnouncement;+ const nextContext = await deserializeContext(+ JSON.parse(JSON.stringify(serializeContext(ctx))),+ );setupMockAgent(defaultModelResult());const restored = JSON.parse(JSON.stringify(first.session)) as HarnessSession;- await contextStorage.run(ctx, () => runStep(restored));+ await contextStorage.run(nextContext, () =>+ runStep(changed ? recordBackgroundTask(restored, "verification") : restored),+ );const nextPrompt = getLastAgentSettings().messages;expect(nextPrompt.slice(0, firstPrompt.length)).toEqual(firstPrompt);expect(- nextPrompt.filter((message) => message.content === "Task status: analysis in progress"),+ nextPrompt.filter((message) => message.content === analysisTaskAnnouncement),).toHaveLength(1);+ expect(nextContext.get(HistoryStateKey)).toMatchObject({ taskState: nextState });+ if (changed) {+ expect(nextPrompt.at(-1)).toEqual({ role: "user", content: nextState });+ } else {+ expect(nextPrompt.at(-1)?.role).toBe("tool");+ }+ },+ );++ it("does not advance history state when the model call fails", async () => {+ const ctx = new ContextContainer();+ ctx.set(PendingSkillAnnouncementKey, "Available skills\n- policy: Tenant policy");+ const { emit } = createEventCollector();+ const runStep = createToolLoopHarness(createTestConfig("conversation", emit));+ setupMockAgentError(new Error("Model unavailable"));++ const failed = await contextStorage.run(ctx, () =>+ runStep(createTestSession(), { message: "Check progress." }),+ );+ expect(ctx.get(HistoryStateKey)).toBeUndefined();+ expect(failed.session.history).not.toContainEqual({+ role: "user",+ content: "Available skills\n- policy: Tenant policy",+ });++ setupMockAgent(defaultModelResult());+ const retried = await contextStorage.run(ctx, () =>+ runStep(failed.session, { message: "Try again." }),+ );+ expect(retried.session.history).toContainEqual({+ role: "user",+ content: "Available skills\n- policy: Tenant policy",+ });+ expect(ctx.get(HistoryStateKey)).toEqual({+ availableSkills: "Available skills\n- policy: Tenant policy",+ });+ });++ it("does not advance history state when recording the step result fails", async () => {+ const ctx = new ContextContainer();+ ctx.set(PendingSkillAnnouncementKey, "Available skills\n- policy: Tenant policy");+ const failure = new Error("Failed to finish the turn");+ const runStep = createToolLoopHarness(+ createTestConfig("conversation", async (event) => {+ if (event.type === "session.waiting") throw failure;+ }),+ );+ setupMockAgent(defaultModelResult());++ await expect(+ contextStorage.run(ctx, () => runStep(createTestSession(), { message: "Check progress." })),+ ).rejects.toBe(failure);+ expect(getLastAgentSettings().messages).toContainEqual({+ role: "user",+ content: "Available skills\n- policy: Tenant policy",+ });+ expect(ctx.get(HistoryStateKey)).toBeUndefined();+ });++ it("retains completed compaction when the next model call fails", async () => {+ const announcement = "Available skills\n- policy: Tenant policy";+ const ctx = new ContextContainer();+ ctx.set(PendingSkillAnnouncementKey, announcement);+ ctx.set(HistoryStateKey, { availableSkills: announcement });+ const session = createTestSession({+ compaction: {+ recentWindowSize: 10,+ threshold: 100_000,+ lastKnownInputTokens: 50_000,+ lastKnownPromptMessageCount: 1,+ },+ history: [{ role: "user", content: announcement }],+ });+ const { emit } = createEventCollector();+ const runStep = createToolLoopHarness(+ createTestConfig("conversation", emit, {+ resolveModel: vi.fn().mockResolvedValue({ modelId: "test-model", provider: "openai" }),+ }),+ );+ vi.mocked(shouldCompact).mockReturnValueOnce(true);+ vi.mocked(compactMessages).mockResolvedValueOnce([+ { role: "user", content: "Conversation summary" },+ ]);+ setupMockAgentError(new Error("Model unavailable"));++ const failed = await contextStorage.run(ctx, () =>+ runStep(session, { message: "Continue." }),+ );+ expect(failed.session.history).toEqual([{ role: "user", content: "Conversation summary" }]);+ expect(ctx.get(HistoryStateKey)).toBeUndefined();+ expect(failed.session.compaction).not.toHaveProperty("lastKnownInputTokens");+ expect(failed.session.compaction).not.toHaveProperty("lastKnownPromptMessageCount");++ setupMockAgent(defaultModelResult());+ const restoredContext = await deserializeContext(+ JSON.parse(JSON.stringify(serializeContext(ctx))),+ );+ restoredContext.set(PendingSkillAnnouncementKey, announcement);+ const restoredSession = JSON.parse(JSON.stringify(failed.session)) as HarnessSession;+ const retried = await contextStorage.run(restoredContext, () =>+ runStep(restoredSession, { message: "Try again." }),+ );+ expect(+ retried.session.history.filter((message) => message.content === announcement),+ ).toHaveLength(1);+ expect(restoredContext.get(HistoryStateKey)).toEqual({ availableSkills: announcement });+ });++ it.each(["clear", "manual compaction", "automatic compaction"])(+ "reannounces unchanged context after %s replaces history",+ async (replacement) => {+ const ctx = new ContextContainer();+ const availableSkills = "Available skills\n- policy: Tenant policy";+ const taskState = analysisTaskAnnouncement;+ ctx.set(PendingSkillAnnouncementKey, availableSkills);+ ctx.set(TurnTaskDeliveryKey, "initiating");+ const runStep = createToolLoopHarness(createTestConfig("conversation"));+ setupMockAgent(defaultModelResult());+ const first = await contextStorage.run(ctx, () =>+ runStep(recordBackgroundTask(createTestSession()), { message: "Check progress." }),+ );+ const expectedState = {+ availableSkills,+ taskState,+ deliveryInstruction: TASK_DELIVERY_INITIATING_INSTRUCTION,+ };+ expect(ctx.get(HistoryStateKey)).toEqual(expectedState);++ vi.mocked(compactMessages).mockResolvedValue([+ { role: "user", content: "Conversation summary" },+ ]);+ let session = first.session;+ if (replacement === "automatic compaction") {+ vi.mocked(shouldCompact).mockReturnValueOnce(true);+ } else {+ const replaceHistory = createToolLoopHarness(+ createTestConfig("conversation", undefined, {+ clearOnly: replacement === "clear",+ compactOnly: replacement === "manual compaction",+ }),+ );+ session = (await contextStorage.run(ctx, () => replaceHistory(session))).session;+ expect(ctx.get(HistoryStateKey)).toBeUndefined();+ }++ setupMockAgent(defaultModelResult());+ const next = await contextStorage.run(ctx, () =>+ runStep(session, { message: "Continue." }),+ );+ for (const content of Object.values(expectedState)) {+ expect(+ next.session.history.filter((message) => message.content === content),+ ).toHaveLength(1);+ }+ expect(ctx.get(HistoryStateKey)).toEqual(expectedState);},);+ it("skips empty skill announcements without rewriting earlier history", async () => {+ const ctx = new ContextContainer();+ ctx.set(PendingSkillAnnouncementKey, "Available skills\n- policy: Tenant policy");+ const runStep = createToolLoopHarness(createTestConfig("conversation"));+ setupMockAgent(defaultModelResult());+ const first = await contextStorage.run(ctx, () =>+ runStep(createTestSession(), { message: "Check the policy." }),+ );+ ctx.set(PendingSkillAnnouncementKey, "");+ setupMockAgent(defaultModelResult());+ const next = await contextStorage.run(ctx, () =>+ runStep(first.session, { message: "Continue." }),+ );+ expect(next.session.history.slice(0, first.session.history.length)).toEqual(+ first.session.history,+ );+ expect(getLastAgentSettings().messages).toEqual([+ ...first.session.history,+ { role: "user", content: "Continue." },+ ]);+ });+it("keeps ephemeral client context out of compaction and its token baseline", async () => {vi.mocked(shouldCompact).mockReturnValueOnce(true);vi.mocked(compactMessages).mockImplementationOnce(async (messages) => [...messages]);@@ -12426,10 +12638,11 @@ describe("createToolLoopHarness", () => {runStep(createTestSession(), { message: "Check for alerts." }),);- const { instructions } = getLastAgentSettings();- expect(instructions).toEqual({- role: "system",- content: `You are a test assistant.\n\n${CONDITIONAL_DELIVERY_INSTRUCTION}`,+ const { instructions, messages } = getLastAgentSettings();+ expect(instructions).toBe("You are a test assistant.");+ expect(messages).toContainEqual({+ role: "user",+ content: CONDITIONAL_DELIVERY_INSTRUCTION,});},);@@ -12466,26 +12679,27 @@ describe("createToolLoopHarness", () => {const runStep = createToolLoopHarness(createTestConfig("conversation"));const ctx = new ContextContainer();ctx.set(TurnTaskDeliveryKey, "initiating");- ctx.set(TurnTaskStateKey, '[Task state]\n{"tasks":[]}');await contextStorage.run(ctx, () =>- runStep(createTestSession(), { message: "Start the background work." }),+ runStep(recordBackgroundTask(createTestSession()), {+ message: "Start the background work.",+ }),);- const { instructions } = getLastAgentSettings();- expect(instructions).toEqual({- role: "system",- content: `You are a test assistant.\n\n[Task state]\n{"tasks":[]}\n\n${TASK_DELIVERY_INITIATING_INSTRUCTION}`,- });+ const { instructions, messages } = getLastAgentSettings();+ expect(instructions).toBe("You are a test assistant.");+ expect(messages.slice(0, 2)).toEqual([+ { role: "user", content: analysisTaskAnnouncement },+ { role: "user", content: TASK_DELIVERY_INITIATING_INSTRUCTION },+ ]);});it("routes later-turn initiating task context through user messages", async () => {setupMockAgent(defaultModelResult());const runStep = createToolLoopHarness(createTestConfig("conversation"));const ctx = new ContextContainer();- const taskState = '[Task state]\n{"tasks":[]}';+ const taskState = analysisTaskAnnouncement;ctx.set(TurnTaskDeliveryKey, "initiating");- ctx.set(TurnTaskStateKey, taskState);const session = setHarnessEmissionState(createTestSession(), {sequence: 1,sessionStarted: true,@@ -12494,7 +12708,7 @@ describe("createToolLoopHarness", () => {});await contextStorage.run(ctx, () =>- runStep(session, { message: "Start the background work." }),+ runStep(recordBackgroundTask(session), { message: "Start the background work." }),);const { instructions, messages } = getLastAgentSettings();@@ -12506,6 +12720,26 @@ describe("createToolLoopHarness", () => {]);});+ it.each(["none", "pending", "settled"] as const)(+ "does not inject initiating task state during the %s phase",+ async (phase) => {+ setupMockAgent(defaultModelResult());+ const ctx = new ContextContainer();+ ctx.set(TurnTaskDeliveryKey, phase);+ await contextStorage.run(ctx, () =>+ createToolLoopHarness(createTestConfig("conversation"))(+ recordBackgroundTask(createTestSession()),+ { message: "Check progress." },+ ),+ );+ expect(getLastAgentSettings().messages).not.toContainEqual({+ role: "user",+ content: analysisTaskAnnouncement,+ });+ expect(ctx.get(HistoryStateKey)?.taskState).toBeUndefined();+ },+ );+it("keeps a scheduled initiating task turn conditionally deliverable", async () => {setupMockAgent(defaultModelResult());const runStep = createToolLoopHarness(createTestConfig("conversation"));@@ -12516,10 +12750,11 @@ describe("createToolLoopHarness", () => {runStep(createTestSession(), { message: "[Task state]" }),);- const { instructions } = getLastAgentSettings();- expect(instructions).toEqual({- role: "system",- content: `You are a test assistant.\n\n${CONDITIONAL_DELIVERY_INSTRUCTION}`,+ const { instructions, messages } = getLastAgentSettings();+ expect(instructions).toBe("You are a test assistant.");+ expect(messages).toContainEqual({+ role: "user",+ content: CONDITIONAL_DELIVERY_INSTRUCTION,});});@@ -12539,35 +12774,59 @@ describe("createToolLoopHarness", () => {expect(getLastAgentSettings().instructions).toBe("You are a test assistant.");});- it.each([- ["pending", TASK_DELIVERY_PENDING_INSTRUCTION],- ["settled", TASK_DELIVERY_SETTLED_INSTRUCTION],- ] as const)(- "adds %s task-delivery guidance to a top-level framework wake",- async (phase, instruction) => {- setupMockAgent(defaultModelResult());- const runStep = createToolLoopHarness(createTestConfig("conversation"));- const ctx = new ContextContainer();- ctx.set(TurnTaskDeliveryKey, phase);- const session = setHarnessEmissionState(createTestSession(), {- sequence: 1,- sessionStarted: true,- stepIndex: 0,- turnId: "",- });+ it("does not inject or retain silence guidance after a pending task wake", async () => {+ setupMockAgent(defaultModelResult());+ const runStep = createToolLoopHarness(createTestConfig("conversation"));+ const ctx = new ContextContainer();+ ctx.set(TurnTaskDeliveryKey, "pending");+ const session = setHarnessEmissionState(createTestSession(), {+ sequence: 1,+ sessionStarted: true,+ stepIndex: 0,+ turnId: "",+ });- await contextStorage.run(ctx, () =>- runStep(session, { message: "Background task task_1 is completed." }),- );+ const first = await contextStorage.run(ctx, () =>+ runStep(session, { message: "Background task task_1 is completed." }),+ );+ expect(getLastAgentSettings().messages).toEqual([+ { role: "user", content: "Background task task_1 is completed." },+ ]);+ expect(ctx.get(HistoryStateKey)?.deliveryInstruction).toBeUndefined();- const { instructions, messages } = getLastAgentSettings();- expect(instructions).toBe("You are a test assistant.");- expect(messages.slice(-2)).toEqual([- { role: "user", content: instruction },- { role: "user", content: "Background task task_1 is completed." },- ]);- },- );+ ctx.set(TurnTaskDeliveryKey, "none");+ await contextStorage.run(ctx, () =>+ runStep(first.session, { message: "What is 7 times 8?" }),+ );+ expect(getLastAgentSettings().messages).toEqual([+ ...first.session.history,+ { role: "user", content: "What is 7 times 8?" },+ ]);+ });++ it("adds settled task-delivery guidance to a top-level framework wake", async () => {+ setupMockAgent(defaultModelResult());+ const runStep = createToolLoopHarness(createTestConfig("conversation"));+ const ctx = new ContextContainer();+ ctx.set(TurnTaskDeliveryKey, "settled");+ const session = setHarnessEmissionState(createTestSession(), {+ sequence: 1,+ sessionStarted: true,+ stepIndex: 0,+ turnId: "",+ });++ await contextStorage.run(ctx, () =>+ runStep(session, { message: "Background task task_1 is completed." }),+ );++ const { instructions, messages } = getLastAgentSettings();+ expect(instructions).toBe("You are a test assistant.");+ expect(messages.slice(-2)).toEqual([+ { role: "user", content: TASK_DELIVERY_SETTLED_INSTRUCTION },+ { role: "user", content: "Background task task_1 is completed." },+ ]);+ });it("does not add conditional-delivery guidance to a task-owned conversation child", async () => {setupMockAgent(defaultModelResult());diff --git a/packages/eve/src/harness/tool-loop.ts b/packages/eve/src/harness/tool-loop.tsindex f4508b7c4..fdfd6731b 100644--- a/packages/eve/src/harness/tool-loop.ts+++ b/packages/eve/src/harness/tool-loop.ts@@ -22,11 +22,11 @@ import { formatLanguageModelGatewayId } from "#internal/runtime-model.js";import { contextStorage } from "#context/container.js";import {AuthKey,+ HistoryStateKey,ParentSessionKey,ScheduleIdKey,SessionCallbackKey,TurnTaskDeliveryKey,- TurnTaskStateKey,} from "#context/keys.js";import {buildDynamicInstructionMessages,@@ -194,6 +194,7 @@ import { isTurnCancellation, throwIfTurnAborted } from "#harness/turn-cancellatiimport type { JsonObject, JsonValue } from "#shared/json.js";import { EMPTY_DELIVERY_SENTINEL, hasEmptyDeliverySentinel } from "#shared/empty-delivery.js";import { resolveDeliveryPolicy } from "#tasks/delivery-policy.js";+import { resolveInitiatingTaskContext } from "#tasks/delivery-context.js";import { extractWorkflowStreamWriteErrorDetails } from "#harness/workflow-stream-error.js";import { getAdvertisedTools } from "#harness/advertised-tools.js";import {@@ -582,14 +583,9 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {if (config.clearOnly === true) {session = {...session,- compaction: {- recentWindowSize: session.compaction.recentWindowSize,- threshold: session.compaction.threshold,- thresholdPercent: session.compaction.thresholdPercent,- },- history: [],state: clearMemorySessionState(session.state),};+ session = replaceSessionHistory(session, []);await emit?.(createContextClearedEvent({sequence: emissionState.sequence,@@ -627,15 +623,7 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {telemetry: stepInstrumentation?.telemetry(),});- session = {- ...compacted.session,- compaction: {- recentWindowSize: compacted.session.compaction.recentWindowSize,- threshold: compacted.session.compaction.threshold,- thresholdPercent: compacted.session.compaction.thresholdPercent,- },- history: compacted.messages,- };+ session = compacted.session;} catch (error) {logError(log, "manual session compaction failed", error, {sessionId: session.sessionId,@@ -1095,16 +1083,12 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {}}- // Keep the insertion point stable when a later durable step reconstructs- // the model-only prompt, preserving the full prompt prefix within the turn.+ // Keep ephemeral client context at the same position across durable steps.let turnClientContext = storedClientContext;- if (- clientContext !== undefined ||- (storedClientContext === undefined && preparedTurnInput.length > 0)- ) {+ if (clientContext !== undefined) {turnClientContext = {insertionIndex: storedClientContext?.insertionIndex ?? messages.length,- messages: clientContext ?? storedClientContext?.messages ?? [],+ messages: clientContext,turnId,};}@@ -1241,36 +1225,32 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {* `console.error(error)` handler inside `streamText`. Errors are* handled by the harness catch block and emitted as stream events.*/- // AI SDK rejects role:"system" in `messages`; currentMessages also keeps- // later turn-local context out of the stable system prompt cache prefix.- // Insert that context before the current delivery so the triggering user- // message remains the model's latest request.- const currentMessages = createCurrentMessages(projectedMessages, {- currentTurnMessages:- turnClientContext === undefined- ? preparedTurnInput- : messages.slice(turnClientContext.insertionIndex),+ // Persist framework announcements before the new input, or after earlier+ // tool results on a continuation, so later requests retain the full prefix.+ const currentMessages = createCurrentMessages(messages, {+ historyState: ctx?.get(HistoryStateKey),+ currentTurnMessages: preparedTurnInput,+ projectedMessages,});if (ctx !== undefined) {currentMessages.addSystem(buildDynamicInstructionMessages(ctx));- const skillAnnouncement = ctx.get(PendingSkillAnnouncementKey);- if (skillAnnouncement !== undefined && skillAnnouncement.length > 0) {- currentMessages.add(emissionState.sequence, skillAnnouncement);- }- const taskState = ctx.get(TurnTaskStateKey);- if (taskState !== undefined) {- currentMessages.add(emissionState.sequence, taskState);- }- }- if (deliveryPolicy.instruction !== undefined) {- currentMessages.add(emissionState.sequence, deliveryPolicy.instruction);}+ const taskContext =+ ctx?.get(TurnTaskDeliveryKey) === "initiating"+ ? resolveInitiatingTaskContext({ state: session.state, turnId })+ : undefined;+ currentMessages.addAnnouncements({+ availableSkills: ctx?.get(PendingSkillAnnouncementKey),+ taskState: taskContext?.context,+ deliveryInstruction: deliveryPolicy.instruction,+ });const pendingApprovals = renderPendingApprovalsInstruction(getPendingInputBatches(session.state).flatMap((batch) => batch.requests),);if (pendingApprovals !== undefined) {- currentMessages.add(emissionState.sequence, pendingApprovals, { cacheFriendly: false });+ currentMessages.add(pendingApprovals, { cacheFriendly: false });}+ const promptMessages = currentMessages.history;// Hydrate `eve-sandbox:` ref FileParts into inline bytes for the model call// only. Session history remains ref-only across future step boundaries.@@ -1855,20 +1835,23 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {// --- Handle result ------------------------------------------------------- return handleStepResult({+ const stepResult = await handleStepResult({config,emit,emissionState,durableModelPromptMessageCount:turnClientContext === undefined || turnClientContext.messages.length === 0- ? projectedMessages.length+ ? modelMessages.length: undefined,- promptMessages: messages,+ promptMessages,result,runStep,session,coordinationTools: modelCallCoordinationTools,});+ // The returned session now owns these messages; persist their baseline with it.+ ctx?.set(HistoryStateKey, currentMessages.historyState);+ return stepResult;}return runStep;@@ -3135,6 +3118,19 @@ function createNextCompactionConfig(return next;}+function replaceSessionHistory(session: HarnessSession, history: ModelMessage[]): HarnessSession {+ contextStorage.getStore()?.delete(HistoryStateKey);+ return {+ ...session,+ history,+ compaction: {+ recentWindowSize: session.compaction.recentWindowSize,+ threshold: session.compaction.threshold,+ thresholdPercent: session.compaction.thresholdPercent,+ },+ };+}+/*** Runs the compaction pipeline once if the session's input-token estimate* is over the configured threshold. Mutates neither input; returns the new@@ -3257,7 +3253,7 @@ async function maybeCompact(input: {}}- return { compacted: true, messages, session };+ return { compacted: true, messages, session: replaceSessionHistory(session, messages) };}/**diff --git a/packages/eve/src/harness/turn-client-context.ts b/packages/eve/src/harness/turn-client-context.tsindex 79c4705aa..185600ce7 100644--- a/packages/eve/src/harness/turn-client-context.ts+++ b/packages/eve/src/harness/turn-client-context.ts@@ -3,7 +3,7 @@ import type { HarnessSession, SessionStateMap } from "#harness/types.js";const TURN_CLIENT_CONTEXT_STATE_KEY = "eve.harness.turnClientContext";export interface TurnClientContextState {- /** Durable turn boundary shared by client context and framework announcements. */+ /** Position of ephemeral client context in each model request for this turn. */readonly insertionIndex: number;readonly messages: readonly string[];readonly turnId: string;diff --git a/packages/eve/src/tasks/delivery-context.test.ts b/packages/eve/src/tasks/delivery-context.test.tsindex a2ec88fdf..1f2fab34b 100644--- a/packages/eve/src/tasks/delivery-context.test.ts+++ b/packages/eve/src/tasks/delivery-context.test.ts@@ -7,7 +7,6 @@ import {resolveTaskDeliveryContext,TASK_DELIVERY_CONTEXT_LABEL,TASK_DELIVERY_INITIATING_INSTRUCTION,- TASK_DELIVERY_PENDING_INSTRUCTION,TASK_DELIVERY_SETTLED_INSTRUCTION,} from "#tasks/delivery-context.js";import { SESSION_TASKS_STATE_KEY } from "#tasks/session-index.js";@@ -32,29 +31,6 @@ describe("task delivery instructions", () => {expect(TASK_DELIVERY_INITIATING_INSTRUCTION).not.toContain(EMPTY_DELIVERY_SENTINEL);});- it("pending instruction unconditionally requires the sentinel", () => {- expect(TASK_DELIVERY_PENDING_INSTRUCTION).toContain(TASK_DELIVERY_CONTEXT_LABEL);- expect(TASK_DELIVERY_PENDING_INSTRUCTION).toContain("runtime-authored");- expect(TASK_DELIVERY_PENDING_INSTRUCTION).toContain("still pending");- expect(TASK_DELIVERY_PENDING_INSTRUCTION).toContain(- "overrides any earlier instruction to report, summarize, acknowledge",- );- expect(TASK_DELIVERY_PENDING_INSTRUCTION).toContain(- "may call tools only if the newly delivered task result requires immediate action",- );- expect(TASK_DELIVERY_PENDING_INSTRUCTION).toContain(- "Do not provide progress, status, an acknowledgement, or a waiting message",- );- expect(TASK_DELIVERY_PENDING_INSTRUCTION).toContain(- `entire final text response must be exactly ${EMPTY_DELIVERY_SENTINEL} and no other text`,- );- expect(TASK_DELIVERY_PENDING_INSTRUCTION).toContain(- 'Incorrect: "Two of three tasks have completed."',- );- expect(TASK_DELIVERY_PENDING_INSTRUCTION).toContain(`Correct: ${EMPTY_DELIVERY_SENTINEL}`);- expect(TASK_DELIVERY_PENDING_INSTRUCTION).not.toContain("If any task");- });-it("settled instruction unconditionally forbids the sentinel and requires one combined response", () => {expect(TASK_DELIVERY_SETTLED_INSTRUCTION).toContain(TASK_DELIVERY_CONTEXT_LABEL);expect(TASK_DELIVERY_SETTLED_INSTRUCTION).toContain("runtime-authored");diff --git a/packages/eve/src/tasks/delivery-context.ts b/packages/eve/src/tasks/delivery-context.tsindex 6a6b0866d..efc836c1c 100644--- a/packages/eve/src/tasks/delivery-context.ts+++ b/packages/eve/src/tasks/delivery-context.ts@@ -5,28 +5,10 @@ import { getSessionTaskIndex, type SessionTaskIndexEntry } from "#tasks/session-export const TASK_DELIVERY_CONTEXT_LABEL = "[Task state]";export const TASK_DELIVERY_INITIATING_INSTRUCTION = `Background task reporting: launch acknowledgement-The accompanying ${TASK_DELIVERY_CONTEXT_LABEL} system message is runtime-authored and lists background tasks accepted so far from the current turn. They continue independently after this turn.+The latest ${TASK_DELIVERY_CONTEXT_LABEL} message is runtime-authored and lists background tasks accepted so far from the current turn. They continue independently after this turn.Continue carrying out the user's request, including starting any remaining background work. When no further tool calls are needed in this turn, send one brief user-facing acknowledgement that the background work has started. Do not wait for results or report results that are not available yet. End the turn after the acknowledgement.`;-export const TASK_DELIVERY_PENDING_INSTRUCTION = `Background task control: incomplete cohort-This framework-authored instruction overrides any earlier instruction to report, summarize, acknowledge, or otherwise handle background results.--The accompanying ${TASK_DELIVERY_CONTEXT_LABEL} message is runtime-authored and lists tasks started by the same parent turn. At least one of those tasks is still pending, so the combined report is not ready.--Action:-- You may call tools only if the newly delivered task result requires immediate action.-- Otherwise, take no action.--Delivery:-- Do not report completed tasks or partial results.-- Do not provide progress, status, an acknowledgement, or a waiting message.-- After any necessary tool calls, your entire final text response must be exactly ${EMPTY_DELIVERY_SENTINEL} and no other text.--Incorrect: "Two of three tasks have completed."-Incorrect: "Still waiting for the remaining task."-Correct: ${EMPTY_DELIVERY_SENTINEL}`;-export const TASK_DELIVERY_SETTLED_INSTRUCTION = `Background task reporting\nThis turn was triggered by background task activity. The accompanying ${TASK_DELIVERY_CONTEXT_LABEL} message is runtime-authored and lists tasks started by the same parent turn, all settled, with every available terminal output. Do not reply with ${EMPTY_DELIVERY_SENTINEL}. Send one user-facing response that combines their useful results.`;/** Returns model context and cohort phase for tasks started by the same parent turn as this delivery. */diff --git a/packages/eve/src/tasks/delivery-policy.test.ts b/packages/eve/src/tasks/delivery-policy.test.tsindex e04ed3252..54aae1086 100644--- a/packages/eve/src/tasks/delivery-policy.test.ts+++ b/packages/eve/src/tasks/delivery-policy.test.ts@@ -3,7 +3,6 @@ import { describe, expect, it } from "vitest";import { CONDITIONAL_DELIVERY_INSTRUCTION } from "#shared/empty-delivery.js";import {TASK_DELIVERY_INITIATING_INSTRUCTION,- TASK_DELIVERY_PENDING_INSTRUCTION,TASK_DELIVERY_SETTLED_INSTRUCTION,} from "#tasks/delivery-context.js";import { resolveDeliveryPolicy } from "#tasks/delivery-policy.js";@@ -12,7 +11,6 @@ describe("resolveDeliveryPolicy", () => {it.each([["scheduled launch", "initiating", true, true, CONDITIONAL_DELIVERY_INSTRUCTION, true],["user launch", "initiating", true, false, TASK_DELIVERY_INITIATING_INSTRUCTION, false],- ["pending wake", "pending", false, true, TASK_DELIVERY_PENDING_INSTRUCTION, true],["settled wake", "settled", false, true, TASK_DELIVERY_SETTLED_INSTRUCTION, false],] as const)("resolves %s",@@ -36,6 +34,18 @@ describe("resolveDeliveryPolicy", () => {},);+ it("allows an empty pending wake without instructing the model to stay silent", () => {+ expect(+ resolveDeliveryPolicy({+ hasScheduleProvenance: false,+ hasOutputSchema: false,+ isChild: false,+ isFirstTurn: false,+ taskDeliveryPhase: "pending",+ }),+ ).toEqual({ allowsEmptyDelivery: true });+ });+it.each([["structured output", true, false],["child session", false, true],diff --git a/packages/eve/src/tasks/delivery-policy.ts b/packages/eve/src/tasks/delivery-policy.tsindex 3df2f25d7..1341fa825 100644--- a/packages/eve/src/tasks/delivery-policy.ts+++ b/packages/eve/src/tasks/delivery-policy.ts@@ -1,7 +1,6 @@import { CONDITIONAL_DELIVERY_INSTRUCTION } from "#shared/empty-delivery.js";import {TASK_DELIVERY_INITIATING_INSTRUCTION,- TASK_DELIVERY_PENDING_INSTRUCTION,TASK_DELIVERY_SETTLED_INSTRUCTION,} from "#tasks/delivery-context.js";@@ -22,7 +21,6 @@ const POLICIES = {normal: { allowsEmptyDelivery: false },pending: {allowsEmptyDelivery: true,- instruction: TASK_DELIVERY_PENDING_INSTRUCTION,},settled: {allowsEmptyDelivery: false,@@ -40,7 +38,6 @@ export function resolveDeliveryPolicy(input: {}): DeliveryPolicy {// These runs have an explicit output consumer, so silence would violate the call contract.if (input.hasOutputSchema || input.isChild) return POLICIES.normal;- // Partial cohort results are withheld until the parent can report the cohort once.if (input.taskDeliveryPhase === "pending") return POLICIES.pending;// A complete cohort owes its caller the consolidated result and must not disappear silently.if (input.taskDeliveryPhase === "settled") return POLICIES.settled;diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 25611eacf..f3aceb202 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -842,6 +842,28 @@ importers:specifier: 'catalog:'version: 7.0.2+ e2e/fixtures/agent-prompt-cache:+ dependencies:+ '@eve-e2e/config':+ specifier: workspace:*+ version: link:../e2e-config+ '@workflow/world-postgres':+ specifier: 'catalog:'+ version: 5.0.0-beta.40(@opentelemetry/[email protected])(@types/[email protected])(@upstash/[email protected])([email protected])([email protected])([email protected])+ eve:+ specifier: workspace:*+ version: link:../../../packages/eve+ zod:+ specifier: 'catalog:'+ version: 4.5.4+ devDependencies:+ '@types/node':+ specifier: 'catalog:'+ version: 24.13.3+ typescript:+ specifier: 'catalog:'+ version: 7.0.2+e2e/fixtures/agent-schedules:dependencies:'@eve-e2e/config':@@ -979,9 +1001,6 @@ importers:'@workflow/world-postgres':specifier: 'catalog:'version: 5.0.0-beta.40(@opentelemetry/[email protected])(@types/[email protected])(@upstash/[email protected])([email protected])([email protected])([email protected])- ai:- specifier: 'catalog:'- version: 7.0.84([email protected])eve:specifier: workspace:*version: link:../../../packages/eve