The Open Framework for Building Agents
fix(eve): accept empty model responses that stop successfully (#4917)
Chad Hietalaa5e33ecabcfb
diff --git a/.changeset/accept-empty-stop-responses.md b/.changeset/accept-empty-stop-responses.mdnew file mode 100644index 000000000..0f3f66220--- /dev/null+++ b/.changeset/accept-empty-stop-responses.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Root sessions now accept empty model responses with `finishReason: "stop"` without retrying them or reporting a model-call failure. Recovery for delegated sessions, incomplete streams, and empty non-`stop` responses is unchanged.diff --git a/docs/concepts/built-in-tools.md b/docs/concepts/built-in-tools.mdindex a211383d0..9c7383c08 100644--- a/docs/concepts/built-in-tools.md+++ b/docs/concepts/built-in-tools.md@@ -422,6 +422,8 @@ export default noReply();`no_reply` is a `defineTool` tool with [`endsTurn: true`](/docs/tools#end-the-turn-after-a-tool-call), so the turn ends only when no other tool runs in the same step. Only root sessions receive it. Slack clears the thread status when the turn completes. Remove the file to remove the tool.+A root session also accepts a successful model call that returns no text with `finishReason: "stop"`, without retrying or reporting a model-call failure. A turn that settles with no text completes without a final message. Use `no_reply` when the agent should record an explicit choice to stay quiet, including an optional reason. Delegated sessions still retry an empty reply once and report a failure if it remains empty, so the caller can act on the failure.+### `sleep``sleep` pauses and durably resumes the current turn. The model calls it with `{ seconds }`; the wait does not hold an application runtime open. Concurrent calls run in parallel, and the turn resumes after the longest wait. A steering message, the default for a new message, ends the wait early: `sleep` returns `{ interrupted: true }`, which the model reads as `Stopped early because a new message arrived.`, followed by the message. Add it:diff --git a/packages/eve/src/harness/model-call/call.ts b/packages/eve/src/harness/model-call/call.tsindex 19278c9dc..ef4d67a62 100644--- a/packages/eve/src/harness/model-call/call.ts+++ b/packages/eve/src/harness/model-call/call.ts@@ -450,11 +450,11 @@ export class ModelCaller {...(await Promise.all([stepResultPromise, streamResult.responseMessages])),catalog.resolve,);- assertUsableResponse(- stepResult,- accumulatedResponseMessages,- inlineAuthorizationResults.length > 0 || trailingInlineToolResultParts.length > 0,- );+ assertUsableResponse(stepResult, accumulatedResponseMessages, {+ allowEmptyStop: !step.hasDelegatedCaller,+ hasInlineResults:+ inlineAuthorizationResults.length > 0 || trailingInlineToolResultParts.length > 0,+ });const skipped = answerSkippedToolCalls(stepResult, catalog);await emitStepActions(step.publish,@@ -498,23 +498,24 @@ export class ModelCaller {}/**- * A filtered response fails the step, and an empty one, without output or any tool result, is- * retried by the empty-response recovery.+ * A filtered response fails the step. A successful empty `stop` is usable only+ * when no delegated caller needs a reply.*/function assertUsableResponse(stepResult: HarnessStepResult,responseMessages: Parameters<typeof extractToolResultCallIds>[0],- hasInlineResults: boolean,+ options: { readonly allowEmptyStop: boolean; readonly hasInlineResults: boolean },): void {if (stepResult.finishReason === "content-filter") {throw new ContentFilteredModelResponseError(readGatewayGenerationId(stepResult.providerMetadata),);}+ if (options.allowEmptyStop && stepResult.finishReason === "stop") return;if (isEmptyModelResponse(stepResult) &&extractToolResultCallIds(responseMessages).size === 0 &&- !hasInlineResults+ !options.hasInlineResults) {throw new EmptyModelResponseError();}diff --git a/packages/eve/src/harness/model-call/errors.ts b/packages/eve/src/harness/model-call/errors.tsindex 7fc9477f5..9082bf8e5 100644--- a/packages/eve/src/harness/model-call/errors.ts+++ b/packages/eve/src/harness/model-call/errors.ts@@ -214,8 +214,8 @@ function readErrorMessage(error: unknown): string {/*** A model call that produced no content. Raised by the model caller from* either of its two triggers: `isEmptyModelResponse` (a completed step- * with finishReason 'other' and no output — AI Gateway HTTP 200 whose- * stream carries no content, no usage, and no error) or+ * with no usable output — e.g. AI Gateway HTTP 200 whose stream carries no+ * content, no usage, and no error, or a delegated session's empty reply) or* {@link isNoOutputGeneratedError} (the AI SDK rejecting a stream that* closed after metadata without output, normalized via the model call's* rethrow so both shapes funnel into one recovery).diff --git a/packages/eve/src/harness/model-call/recovery.ts b/packages/eve/src/harness/model-call/recovery.tsindex d4c898c26..49c947a1d 100644--- a/packages/eve/src/harness/model-call/recovery.ts+++ b/packages/eve/src/harness/model-call/recovery.ts@@ -100,9 +100,8 @@ function buildDisabledToolNote(toolNames: readonly string[]): string {}/**- * True when a step produced no assistant text and no tool calls. A blank- * response is ambiguous and must be retried instead of silently dropping a- * HITL reply.+ * Whether a step produced no assistant text or tool work. The caller decides+ * whether a successful empty `stop` is usable for the session.*/export function isEmptyModelResponse(step: HarnessStepResult): boolean {return (diff --git a/packages/eve/src/harness/tool-loop-request-envelope.integration.test.ts b/packages/eve/src/harness/tool-loop-request-envelope.integration.test.tsindex 1551bfbd3..c412b23f8 100644--- a/packages/eve/src/harness/tool-loop-request-envelope.integration.test.ts+++ b/packages/eve/src/harness/tool-loop-request-envelope.integration.test.ts@@ -1,5 +1,5 @@import { getRequestEnvelopeTokens } from "#harness/request-envelope.js";-import type { LanguageModel } from "ai";+import { type LanguageModel, NoOutputGeneratedError } from "ai";import { describe, expect, it, vi } from "vitest";import { ContextContainer, contextStorage } from "#context/container.js";@@ -147,7 +147,9 @@ describe("model request envelope accounting", () => {requests.push(request);if (requests.length === 1) {setInstructions(ctx, 1_400);- return "";+ throw new NoOutputGeneratedError({+ message: "The model stream ended without a finish chunk.",+ });}return "Recovered after compaction.";},diff --git a/packages/eve/src/harness/tool-loop.test.ts b/packages/eve/src/harness/tool-loop.test.tsindex 7fc48567c..7f0f035c4 100644--- a/packages/eve/src/harness/tool-loop.test.ts+++ b/packages/eve/src/harness/tool-loop.test.ts@@ -5441,8 +5441,6 @@ describe("createToolLoopHarness", () => {const emptyStopResult: Record<string, unknown> = {...emptyResult,finishReason: "stop",- response: { messages: [{ content: " \n", role: "assistant" }] },- text: " \n",};/**@@ -5718,23 +5716,54 @@ describe("createToolLoopHarness", () => {}});- it("reissues a blank 'stop' response instead of treating it as intentional silence", async () => {- setupFirstThenAgent(emptyStopResult, successResult);- const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});- const runStep = createToolLoopHarness(createTestConfig());+ it("accepts an empty 'stop' response in a root session without retrying or failing the turn", async () => {+ setupMockAgent(emptyStopResult);+ const { emit, events } = createEventCollector();+ const runStep = createToolLoopHarness(createTestConfig(emit));- try {- const result = await runStep(createTestSession(), { message: "Hi" });+ const result = await runStep(createTestSession(), { message: "Hi" });- expect(result.next).toBeNull();- expect(vi.mocked(ToolLoopAgent)).toHaveBeenCalledTimes(2);- expect(result.session.history).toContainEqual({- content: "Here is your answer.",- role: "assistant",- });- } finally {- warnSpy.mockRestore();- }+ expect(result.next).toBeNull();+ expect(result.settledTurn).toEqual({ output: "" });+ expect(events.map((event) => event.type)).toEqual([+ "session.started",+ "turn.started",+ "message.received",+ "step.started",+ "step.completed",+ "turn.completed",+ "session.waiting",+ ]);+ expect(vi.mocked(ToolLoopAgent)).toHaveBeenCalledTimes(1);+ });++ it("retries an empty 'stop' response in a delegated session and reports failure if still empty", async () => {+ captureLogRecords();+ setupMockAgent(emptyStopResult);+ const { emit, events } = createEventCollector();+ const runStep = createToolLoopHarness(createTestConfig(emit));+ const ctx = new ContextContainer();+ setDelegatedParent(ctx);++ const result = await contextStorage.run(ctx, () =>+ runStep(createTestSession(), { message: "Summarize Alice's report for Bob." }),+ );++ expect(result.next).toBeNull();+ expect(result.settledTurn).toEqual({+ isError: true,+ output: expect.stringContaining("did not return a response"),+ });+ expect(events.map((event) => event.type)).toEqual([+ "session.started",+ "turn.started",+ "message.received",+ "step.started",+ "step.failed",+ "turn.failed",+ "session.waiting",+ ]);+ expect(vi.mocked(ToolLoopAgent)).toHaveBeenCalledTimes(2);});it("reissues once and recovers when the stream rejects with NoOutputGeneratedError", async () => {diff --git a/packages/eve/src/tools/provided/no-reply.ts b/packages/eve/src/tools/provided/no-reply.tsindex dc32d1c41..edcdbf08b 100644--- a/packages/eve/src/tools/provided/no-reply.ts+++ b/packages/eve/src/tools/provided/no-reply.ts@@ -20,6 +20,11 @@ export interface NoReplyToolInput {** A turn that ends with `no_reply` completes without a final message, so* channels and schedules post nothing. Only root sessions receive it.+ * A root session also accepts a model call returning no text with+ * `finishReason: "stop"` without retry. Delegated sessions still retry empty+ * replies and report a failure if recovery is exhausted.+ * This tool records an explicit choice to stay quiet and an optional reason+ * instead of relying on blank model output.*/export function noReply(): ToolDefinition<NoReplyToolInput, string> {return frameworkTool(