Conversation
… ending empty
The embedded translation agent (search_events, search_issues,
search_issue_events) runs the AI SDK's multi-step tool loop. Its top
no-output failure is the model spending every step calling tools (fetch
attributes, validate, …) and never committing to the structured output —
it isn't "aware" it's about to run out of turns. That surfaces to users as
a UserInputError ("could not construct a valid query").
Use the SDK-native prepareStep to make the agent's last step answer-only:
disable tools (toolChoice: "none") and tell it to emit the output now, so
it answers with what it already gathered within the same run — no full
retry, no lost context. If that final turn still yields nothing, the
existing UserInputError stands.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
betegon
force-pushed
the
feat/embedded-agent-final-output-step
branch
from
September 14, 2026 19:43
1b21667 to
ad054b4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The embedded translation agent (
search_events,search_issues,search_issue_events) runs the AI SDK's own multi-step tool loop (stepCountIs(5)). Its most common failure is spending that whole budget calling tools (fetch attributes, validate, …) and never committing to the structured output — it isn't "aware" it's about to run out of turns. The run ends empty, which surfaces to users asUserInputError("could not construct a valid query"). Seen live in prod (e.g. acount_unique per hourquery that failed once, then worked on an identical rerun).What this does
Make the agent's last step answer-only, using the SDK-native
prepareStepcallback:prepareStepis a first-classgenerateTextoption the SDK calls before each step of its loop; it lets you override that step's settings (toolChoice,messages, …).stepNumber === AGENT_STEP_LIMIT - 1) we returntoolChoice: "none"and append a short "this is your final step, respond now" message.With tools disabled, answering is the model's only move — so instead of ending empty it responds with what it already gathered, within the same run, keeping all its context. No blind full retry, no doubled latency. If the forced turn still yields nothing, the existing
UserInputErrorstands.Why not a retry
An earlier cut (#1308, closed) retried the whole
generateTextcall. That throws away the context the agent built and doesn't address the root cause — the model never committing before the budget runs out. Forcing the final turn is the framework-native way to fix it.Notes on the trade-off
The last of the 5 steps becomes answer-only, so the agent gets up to 4 tool-calling steps + 1 guaranteed answer, instead of 5 tool steps that could end without an answer. In practice a translation uses ~2–3 tool calls, so this only ever converts a would-be-wasted final tool call into an answer. Happy path is unaffected — the forced step is only reached if every prior step was a tool call.
Test plan
pnpm --filter @sentry/mcp-core tsc/biome lint/format— clean; full mcp-core suite — 1420 passed.generateTextnever runs the real step loop). The existingcallEmbeddedAgenttests still pass, confirming the wiring and the unchanged error paths.🤖 Generated with Claude Code