You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Max-steps wrap-up appends MAX_STEPS_PROMPT as an assistant message → Anthropic 400 "does not support assistant message prefill" #37685
When an agent reaches its configured steps limit, the final request fails with an Anthropic API 400 instead of producing the intended text-only wrap-up:
AI_APICallError: This model does not support assistant message prefill. The conversation must end with a user message.
Cause: packages/opencode/src/session/prompt.ts (~line 1281) appends the max-steps instruction as an assistant message when isLastStep is true:
Ending the request with an assistant message (a prefill) is rejected by the Anthropic API when thinking/effort is enabled (e.g. variant: max/xhigh on claude-sonnet-5 / claude-opus-4-8). So any agent that exhausts its steps budget on a thinking-enabled Anthropic model deterministically errors on its final step instead of returning the MAX_STEPS summary.
Reproduced twice on 1.18.3, each at exactly the agent's configured ceiling, with all prior steps succeeding:
steps: 40 subagent (claude-sonnet-5, thinking variant): 39 successful tool-call steps, then the 400 on step 40.
steps: 200 subagent (claude-opus-4-8, thinking variant): same 400 on step 200.
The line is unchanged on dev as of 2026-07-18.
Suggested fix: send MAX_STEPS_PROMPT as a user-role message, or only use the assistant prefill when the request does not have thinking enabled and the provider supports prefill.
Define a subagent on an Anthropic model with a thinking-enabling variant, e.g. model: anthropic/claude-sonnet-5, variant: max, and a low step cap, e.g. steps: 2.
Dispatch it (task tool) a task that needs more tool-call turns than the cap.
On the final permitted step the API call fails with This model does not support assistant message prefill. The conversation must end with a user message. instead of returning the max-steps text wrap-up.
Activity
github-actions commentedon Jul 18, 2026
This issue might be a duplicate of an existing issue. Please check:
MAX_STEPS_PROMPTappended as an assistant-role message inprompt.tscauses a 400 on Anthropic models with thinking enabled, identical error message and reproduction steps.If this is indeed the same issue, please consider closing this one in favor of #32548 where it is already being tracked.
fernanDOTdo commentedon Jul 18, 2026
Duplicate of #32548 — same root cause (MAX_STEPS_PROMPT sent as assistant prefill), same 400. Tracking there; fix PR #34276 already open.