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
I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.
Description
When using create_deep_agent with Claude Opus 4.6 (claude-opus-4-6) or Sonnet 4.6 (claude-sonnet-4-6), the agent fails with a 400 Bad Request error:
Error: This model does not support assistant message prefill.
The conversation must end with a user message.
This is a breaking change in Claude 4.6 models — Anthropic removed support for assistant message prefilling (last-assistant-turn prefills). Any request where the messages array ends with role: "assistant" now returns a 400 error.
The same code works perfectly with Claude Sonnet 4.5 (claude-sonnet-4-5-20250929).
Minimal Reproducible Example
fromdeepagentsimportcreate_deep_agentfromlangchain_anthropicimportChatAnthropic# Works fine with Sonnet 4.5# model = ChatAnthropic(model="claude-sonnet-4-5-20250929")# Fails with Opus 4.6model=ChatAnthropic(model="claude-opus-4-6")
agent=create_deep_agent(
model=model,
system_prompt="You are a helpful assistant.",
tools=[],
)
# This triggers the errorresult=agent.invoke({
"messages": [{"role": "user", "content": "Hello, what is 2 + 2?"}]
})
Error Output
anthropic.BadRequestError: Error code: 400 -
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "This model does not support assistant message prefill. The conversation must end with a user message."
}
}
Root Cause Analysis
The error occurs because somewhere in deepagents' internal pipeline, the messages array sent to the Anthropic API ends with a message with role: "assistant". Claude 4.6 interprets this as an attempt to prefill the assistant response and rejects it.
Likely sources of the trailing assistant message within deepagents:
SummarizationMiddleware — When summarizing conversation history, the summary may be appended as an assistant message at the end of the array.
Context management / message truncation — When trimming message history, an assistant message may end up as the last entry.
Subagent handoffs — When passing conversation context between agents, the last message in the array may be from the assistant role.
create_deep_agent should work with Claude 4.6 models without errors. The agent should either:
Strip trailing assistant messages before sending to the API when the model is Claude 4.6+, or
Convert trailing assistant messages into user-role context (as Anthropic recommends), or
Use output_config.format (Anthropic's recommended replacement for prefill-based structured output).
Suggested Fix
A middleware-level or pre-dispatch sanitization that detects Claude 4.6+ models and ensures the messages array never ends with role: "assistant". For example:
defsanitize_messages_for_claude_46(messages: list, model: str) ->list:
"""Ensure messages don't end with assistant role for Claude 4.6+ models."""ifnotmessages:
returnmessages# Check if model is Claude 4.6+is_claude_46="claude-opus-4-6"inmodelor"claude-sonnet-4-6"inmodelifis_claude_46andmessages[-1].get("role") =="assistant":
# Option A: Move trailing assistant content to a user messagelast_msg=messages.pop()
messages.append({
"role": "user",
"content": f"[Previous assistant context]: {last_msg['content']}"
})
returnmessages
Alternatively, a model-profile-based approach using LangChain 1.1+'s .profile attribute to check if the model supports prefill.
System Information
OS: Linux (WSL 2 on Windows 11)
Python Version: 3.12.x
deepagents: 0.4.4
langgraph: 1.0.5
langchain: 1.2.0
langchain-anthropic: 1.3.4
langchain-core: 1.2.13
anthropic: 0.75.0
Related Issues in Other Projects
This breaking change is affecting multiple projects across the ecosystem:
# [BUG] Claude Opus 4.6 / Sonnet 4.6: "This model does not support assistant message prefill" error## Checked other resources- [x] Thisisabug, notausagequestion. Forquestions, pleaseusethe [LangChainForum](https://forum.langchain.com/).
- [x] Iaddedaclearanddetailedtitlethatsummarizestheissue.
- [x] Ireadwhata [minimalreproducibleexample](https://stackoverflow.com/help/minimal-reproducible-example) is.
- [x] Iincludedaself-contained, minimalexamplethatdemonstratestheissueINCLUDINGalltherelevantimports. ThecoderunASIStoreproducetheissue.
## DescriptionWhenusing`create_deep_agent`withClaudeOpus4.6 (`claude-opus-4-6`) orSonnet4.6 (`claude-sonnet-4-6`), theagentfailswitha**400BadRequest**error:
Error: Thismodeldoesnotsupportassistantmessageprefill.
Theconversationmustendwithausermessage.
Thisisa**breakingchangeinClaude4.6models** — Anthropicremovedsupportforassistantmessageprefilling (last-assistant-turnprefills). Anyrequestwherethemessagesarrayendswith`role: "assistant"`nowreturnsa400error.
SeeAnthropic'sofficialdocumentation:
- [What'snewinClaude4.6](https://platform.claude.com/docs/en/about-claude/models/whats-new-claude-4-6) — *"Prefilling assistant messages (last-assistant-turn prefills) is not supported on Opus 4.6. Requests with prefilled assistant messages return a 400 error."*- [Migrationguide](https://docs.anthropic.com/en/docs/about-claude/models/migrating-to-claude-4) — *"Use structured outputs, system prompt instructions, or output_config.format instead."*ThesamecodeworksperfectlywithClaudeSonnet4.5 (`claude-sonnet-4-5-20250929`).
## Minimal Reproducible Examplefromdeepagentsimportcreate_deep_agentfromlangchain_anthropicimportChatAnthropic# Works fine with Sonnet 4.5# model = ChatAnthropic(model="claude-sonnet-4-5-20250929")# Fails with Opus 4.6model=ChatAnthropic(model="claude-opus-4-6")
agent=create_deep_agent(
model=model,
system_prompt="You are a helpful assistant.",
tools=[],
)
# This triggers the errorresult=agent.invoke({
"messages": [{"role": "user", "content": "Hello, what is 2 + 2?"}]
})
### Error Outputanthropic.BadRequestError: Errorcode: 400-
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "This model does not support assistant message prefill. The conversation must end with a user message."
}
}
## Root Cause AnalysisTheerroroccursbecausesomewhereindeepagents' internalpipeline, themessagesarraysenttotheAnthropicAPIendswithamessagewith`role: "assistant"`. Claude4.6interpretsthisasanattempttoprefilltheassistantresponseandrejectsit.
Likelysourcesofthetrailingassistantmessagewithindeepagents:
1.**SummarizationMiddleware** — Whensummarizingconversationhistory, thesummarymaybeappendedasanassistantmessageattheendofthearray.
2.**Contextmanagement/messagetruncation** — Whentrimmingmessagehistory, anassistantmessagemayendupasthelastentry.
3.**Subagenthandoffs** — Whenpassingconversationcontextbetweenagents, thelastmessageinthearraymaybefromtheassistantrole.
4.**`response_format`/structuredoutputnode** — AlthoughLangGraph's `create_react_agent` was refactored in PR [#5872](https://github.com/langchain-ai/langgraph/issues/5872) / [#5873](https://github.com/langchain-ai/langgraph/pull/5873) to use tool strategy instead of prefill, the deep agent'sownmiddlewarestackmaystillproducetrailingassistantmessages.
## Expected Behavior`create_deep_agent`shouldworkwithClaude4.6modelswithouterrors. Theagentshouldeither:
1.**Striptrailingassistantmessages**beforesendingtotheAPIwhenthemodelisClaude4.6+, or2.**Converttrailingassistantmessages**intouser-rolecontext (asAnthropicrecommends), or3.**Use`output_config.format`** (Anthropic'srecommendedreplacementforprefill-basedstructuredoutput).
## Suggested FixAmiddleware-levelorpre-dispatchsanitizationthatdetectsClaude4.6+modelsandensuresthemessagesarrayneverendswith`role: "assistant"`. Forexample:
defsanitize_messages_for_claude_46(messages: list, model: str) ->list:
"""Ensure messages don't end with assistant role for Claude 4.6+ models."""ifnotmessages:
returnmessages# Check if model is Claude 4.6+is_claude_46="claude-opus-4-6"inmodelor"claude-sonnet-4-6"inmodelifis_claude_46andmessages[-1].get("role") =="assistant":
# Option A: Move trailing assistant content to a user messagelast_msg=messages.pop()
messages.append({
"role": "user",
"content": f"[Previous assistant context]: {last_msg['content']}"
})
returnmessagesAlternatively, amodel-profile-basedapproachusingLangChain1.1+'s`.profile`attributetocheckifthemodelsupportsprefill.
## System InformationOS: Linux (WSL2onWindows11)
PythonVersion: 3.12.xdeepagents: 0.4.4langgraph: 1.0.5langchain: 1.2.0langchain-anthropic: 1.3.4langchain-core: 1.2.13anthropic: 0.75.0## Related Issues in Other ProjectsThisbreakingchangeisaffectingmultipleprojectsacrosstheecosystem:
-**livekit/agents** [#4907](https://github.com/livekit/agents/issues/4907) — *"Anthropic 400 Error on Claude 4.6 - Prefilling assistant messages is no longer supported"* (open, 2 weeks)-**strands-agents/sdk-python** [#1694](https://github.com/strands-agents/sdk-python/issues/1694) — *"Claude Opus 4.6 doesn't support assistant prefill messages"* (open, 3 weeks)-**snap-stanford/Biomni** [#284](https://github.com/snap-stanford/Biomni/issues/284) — *"Claude Sonnet 4.6 prefill error"* (open, 1 week)-**oh-my-opencode** [#1528](https://github.com/code-yeongyu/oh-my-opencode/issues/1528) — *"Vertex AI Claude Opus 4.6 model fail with assistant message prefill error"* (open, 1 month)-**LangGraph** [#4940](https://github.com/langchain-ai/langgraph/issues/4940) — *"When using tools, pre-filling the assistant response is not supported"* (partially addressed via #5872/#5873)## WorkaroundsUntilthisisfixed, userscan:
1.**UseClaudeSonnet4.5**whichstillsupportsprefill:
model=ChatAnthropic(model="claude-sonnet-4-5-20250929")
2.**Use`anthropic-compat`** — a [drop-inshim](https://github.com/ProAndMax/anthropic-compat) thatinterceptsprefilledassistantmessagesandconvertsthemtosystempromptinstructions:
pipinstallanthropic-compat
Error Message and Stack Trace (if applicable)
# [BUG] Claude Opus 4.6 / Sonnet 4.6: "This model does not support assistant message prefill" error## Checked other resources
- [x] This is a bug, not a usage question. For questions, please use the [LangChain Forum](https://forum.langchain.com/).
- [x] I added a clear and detailed title that summarizes the issue.
- [x] I read what a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) is.
- [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.
## Description
When using `create_deep_agent` with Claude Opus 4.6 (`claude-opus-4-6`) or Sonnet 4.6 (`claude-sonnet-4-6`), the agent fails with a **400 Bad Request** error:
Error: This model does not support assistant message prefill.
The conversation must end with a user message.
This is a **breaking change in Claude 4.6 models** — Anthropic removed support for assistant message prefilling (last-assistant-turn prefills). Any request where the messages array ends with `role: "assistant"` now returns a 400 error.
See Anthropic's official documentation:- [What's new in Claude 4.6](https://platform.claude.com/docs/en/about-claude/models/whats-new-claude-4-6) — *"Prefilling assistant messages (last-assistant-turn prefills) is not supported on Opus 4.6. Requests with prefilled assistant messages return a 400 error."*
- [Migration guide](https://docs.anthropic.com/en/docs/about-claude/models/migrating-to-claude-4) — *"Use structured outputs, system prompt instructions, or output_config.format instead."*
The same code works perfectly with Claude Sonnet 4.5 (`claude-sonnet-4-5-20250929`).
## Minimal Reproducible Example
from deepagents import create_deep_agent
from langchain_anthropic import ChatAnthropic
# Works fine with Sonnet 4.5# model = ChatAnthropic(model="claude-sonnet-4-5-20250929")# Fails with Opus 4.6
model = ChatAnthropic(model="claude-opus-4-6")
agent = create_deep_agent(
model=model,
system_prompt="You are a helpful assistant.",
tools=[],
)
# This triggers the error
result = agent.invoke({
"messages": [{"role": "user", "content": "Hello, what is 2 + 2?"}]
})
### Error Output
anthropic.BadRequestError: Error code: 400 -
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "This model does not support assistant message prefill. The conversation must end with a user message."
}
}
## Root Cause Analysis
The error occurs because somewhere in deepagents' internal pipeline, the messages array sent to the Anthropic API ends with a message with `role: "assistant"`. Claude 4.6 interprets this as an attempt to prefill the assistant response and rejects it.Likely sources of the trailing assistant message within deepagents:1. **SummarizationMiddleware** — When summarizing conversation history, the summary may be appended as an assistant message at the end of the array.2. **Context management / message truncation** — When trimming message history, an assistant message may end up as the last entry.3. **Subagent handoffs** — When passing conversation context between agents, the last message in the array may be from the assistant role.4. **`response_format` / structured output node** — Although LangGraph's `create_react_agent` was refactored in PR [#5872](https://github.com/langchain-ai/langgraph/issues/5872) / [#5873](https://github.com/langchain-ai/langgraph/pull/5873) to use tool strategy instead of prefill, the deep agent's own middleware stack may still produce trailing assistant messages.## Expected Behavior`create_deep_agent` should work with Claude 4.6 models without errors. The agent should either:
1. **Strip trailing assistant messages** before sending to the API when the model is Claude 4.6+, or
2. **Convert trailing assistant messages** into user-role context (as Anthropic recommends), or
3. **Use `output_config.format`** (Anthropic's recommended replacement for prefill-based structured output).## Suggested FixA middleware-level or pre-dispatch sanitization that detects Claude 4.6+ models and ensures the messages array never ends with `role: "assistant"`. For example:def sanitize_messages_for_claude_46(messages: list, model: str) -> list: """Ensure messages don't end with assistant role for Claude 4.6+ models.""" if not messages: return messages # Check if model is Claude 4.6+ is_claude_46 = "claude-opus-4-6" in model or "claude-sonnet-4-6" in model if is_claude_46 and messages[-1].get("role") == "assistant": # Option A: Move trailing assistant content to a user message last_msg = messages.pop() messages.append({"role": "user","content": f"[Previous assistant context]: {last_msg['content']}" }) return messagesAlternatively, a model-profile-based approach using LangChain 1.1+'s `.profile` attribute to check if the model supports prefill.## System InformationOS: Linux (WSL 2 on Windows 11)Python Version: 3.12.xdeepagents: 0.4.4langgraph: 1.0.5langchain: 1.2.0langchain-anthropic: 1.3.4langchain-core: 1.2.13anthropic: 0.75.0## Related Issues in Other ProjectsThis breaking change is affecting multiple projects across the ecosystem:- **livekit/agents** [#4907](https://github.com/livekit/agents/issues/4907) — *"Anthropic 400 Error on Claude 4.6 - Prefilling assistant messages is no longer supported"* (open, 2 weeks)- **strands-agents/sdk-python** [#1694](https://github.com/strands-agents/sdk-python/issues/1694) — *"Claude Opus 4.6 doesn't support assistant prefill messages"* (open, 3 weeks)- **snap-stanford/Biomni** [#284](https://github.com/snap-stanford/Biomni/issues/284) — *"Claude Sonnet 4.6 prefill error"* (open, 1 week)- **oh-my-opencode** [#1528](https://github.com/code-yeongyu/oh-my-opencode/issues/1528) — *"Vertex AI Claude Opus 4.6 model fail with assistant message prefill error"* (open, 1 month)- **LangGraph** [#4940](https://github.com/langchain-ai/langgraph/issues/4940) — *"When using tools, pre-filling the assistant response is not supported"* (partially addressed via #5872/#5873)## WorkaroundsUntil this is fixed, users can:1. **Use Claude Sonnet 4.5** which still supports prefill: model = ChatAnthropic(model="claude-sonnet-4-5-20250929")2. **Use `anthropic-compat`** — a [drop-in shim](https://github.com/ProAndMax/anthropic-compat) that intercepts prefilled assistant messages and converts them to system prompt instructions: pip install anthropic-compat
Description
[BUG] Claude Opus 4.6 / Sonnet 4.6: "This model does not support assistant message prefill" error
[BUG] Claude Opus 4.6 / Sonnet 4.6: "This model does not support assistant message prefill" error
I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.
Description
When using create_deep_agent with Claude Opus 4.6 (claude-opus-4-6) or Sonnet 4.6 (claude-sonnet-4-6), the agent fails with a 400 Bad Request error:
Error: This model does not support assistant message prefill.
The conversation must end with a user message.
This is a breaking change in Claude 4.6 models — Anthropic removed support for assistant message prefilling (last-assistant-turn prefills). Any request where the messages array ends with role: "assistant" now returns a 400 error.
The same code works perfectly with Claude Sonnet 4.5 (claude-sonnet-4-5-20250929).
Minimal Reproducible Example
fromdeepagentsimportcreate_deep_agentfromlangchain_anthropicimportChatAnthropic# Works fine with Sonnet 4.5# model = ChatAnthropic(model="claude-sonnet-4-5-20250929")# Fails with Opus 4.6model=ChatAnthropic(model="claude-opus-4-6")
agent=create_deep_agent(
model=model,
system_prompt="You are a helpful assistant.",
tools=[],
)
# This triggers the errorresult=agent.invoke({
"messages": [{"role": "user", "content": "Hello, what is 2 + 2?"}]
})
Error Output
anthropic.BadRequestError: Error code: 400 -
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "This model does not support assistant message prefill. The conversation must end with a user message."
}
}
Root Cause Analysis
The error occurs because somewhere in deepagents' internal pipeline, the messages array sent to the Anthropic API ends with a message with role: "assistant". Claude 4.6 interprets this as an attempt to prefill the assistant response and rejects it.
Likely sources of the trailing assistant message within deepagents:
SummarizationMiddleware — When summarizing conversation history, the summary may be appended as an assistant message at the end of the array.
Context management / message truncation — When trimming message history, an assistant message may end up as the last entry.
Subagent handoffs — When passing conversation context between agents, the last message in the array may be from the assistant role.
create_deep_agent should work with Claude 4.6 models without errors. The agent should either:
Strip trailing assistant messages before sending to the API when the model is Claude 4.6+, or
Convert trailing assistant messages into user-role context (as Anthropic recommends), or
Use output_config.format (Anthropic's recommended replacement for prefill-based structured output).
Suggested Fix
A middleware-level or pre-dispatch sanitization that detects Claude 4.6+ models and ensures the messages array never ends with role: "assistant". For example:
defsanitize_messages_for_claude_46(messages: list, model: str) ->list:
"""Ensure messages don't end with assistant role for Claude 4.6+ models."""ifnotmessages:
returnmessages# Check if model is Claude 4.6+is_claude_46="claude-opus-4-6"inmodelor"claude-sonnet-4-6"inmodelifis_claude_46andmessages[-1].get("role") =="assistant":
# Option A: Move trailing assistant content to a user messagelast_msg=messages.pop()
messages.append({
"role": "user",
"content": f"[Previous assistant context]: {last_msg['content']}"
})
returnmessages
Alternatively, a model-profile-based approach using LangChain 1.1+'s .profile attribute to check if the model supports prefill.
System Information
OS: Linux (WSL 2 on Windows 11)
Python Version: 3.12.x
deepagents: 0.4.4
langgraph: 1.0.5
langchain: 1.2.0
langchain-anthropic: 1.3.4
langchain-core: 1.2.13
anthropic: 0.75.0
Related Issues in Other Projects
This breaking change is affecting multiple projects across the ecosystem:
I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.
Description
When using create_deep_agent with Claude Opus 4.6 (claude-opus-4-6) or Sonnet 4.6 (claude-sonnet-4-6), the agent fails with a 400 Bad Request error:
Error: This model does not support assistant message prefill.
The conversation must end with a user message.
This is a breaking change in Claude 4.6 models — Anthropic removed support for assistant message prefilling (last-assistant-turn prefills). Any request where the messages array ends with role: "assistant" now returns a 400 error.
The same code works perfectly with Claude Sonnet 4.5 (claude-sonnet-4-5-20250929).
Minimal Reproducible Example
fromdeepagentsimportcreate_deep_agentfromlangchain_anthropicimportChatAnthropic# Works fine with Sonnet 4.5# model = ChatAnthropic(model="claude-sonnet-4-5-20250929")# Fails with Opus 4.6model=ChatAnthropic(model="claude-opus-4-6")
agent=create_deep_agent(
model=model,
system_prompt="You are a helpful assistant.",
tools=[],
)
# This triggers the errorresult=agent.invoke({
"messages": [{"role": "user", "content": "Hello, what is 2 + 2?"}]
})
Error Output
anthropic.BadRequestError: Error code: 400 -
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "This model does not support assistant message prefill. The conversation must end with a user message."
}
}
Root Cause Analysis
The error occurs because somewhere in deepagents' internal pipeline, the messages array sent to the Anthropic API ends with a message with role: "assistant". Claude 4.6 interprets this as an attempt to prefill the assistant response and rejects it.
Likely sources of the trailing assistant message within deepagents:
SummarizationMiddleware — When summarizing conversation history, the summary may be appended as an assistant message at the end of the array.
Context management / message truncation — When trimming message history, an assistant message may end up as the last entry.
Subagent handoffs — When passing conversation context between agents, the last message in the array may be from the assistant role.
create_deep_agent should work with Claude 4.6 models without errors. The agent should either:
Strip trailing assistant messages before sending to the API when the model is Claude 4.6+, or
Convert trailing assistant messages into user-role context (as Anthropic recommends), or
Use output_config.format (Anthropic's recommended replacement for prefill-based structured output).
Suggested Fix
A middleware-level or pre-dispatch sanitization that detects Claude 4.6+ models and ensures the messages array never ends with role: "assistant". For example:
defsanitize_messages_for_claude_46(messages: list, model: str) ->list:
"""Ensure messages don't end with assistant role for Claude 4.6+ models."""ifnotmessages:
returnmessages# Check if model is Claude 4.6+is_claude_46="claude-opus-4-6"inmodelor"claude-sonnet-4-6"inmodelifis_claude_46andmessages[-1].get("role") =="assistant":
# Option A: Move trailing assistant content to a user messagelast_msg=messages.pop()
messages.append({
"role": "user",
"content": f"[Previous assistant context]: {last_msg['content']}"
})
returnmessages
Alternatively, a model-profile-based approach using LangChain 1.1+'s .profile attribute to check if the model supports prefill.
System Information
OS: Linux (WSL 2 on Windows 11)
Python Version: 3.12.x
deepagents: 0.4.4
langgraph: 1.0.5
langchain: 1.2.0
langchain-anthropic: 1.3.4
langchain-core: 1.2.13
anthropic: 0.75.0
Related Issues in Other Projects
This breaking change is affecting multiple projects across the ecosystem:
Checked other resources
Area (Required)
Related Issues / PRs
[BUG] Claude Opus 4.6 / Sonnet 4.6: "This model does not support assistant message prefill" error
Checked other resources
Description
When using
create_deep_agentwith Claude Opus 4.6 (claude-opus-4-6) or Sonnet 4.6 (claude-sonnet-4-6), the agent fails with a 400 Bad Request error:This is a breaking change in Claude 4.6 models — Anthropic removed support for assistant message prefilling (last-assistant-turn prefills). Any request where the messages array ends with
role: "assistant"now returns a 400 error.See Anthropic's official documentation:
The same code works perfectly with Claude Sonnet 4.5 (
claude-sonnet-4-5-20250929).Minimal Reproducible Example
Error Output
Root Cause Analysis
The error occurs because somewhere in deepagents' internal pipeline, the messages array sent to the Anthropic API ends with a message with
role: "assistant". Claude 4.6 interprets this as an attempt to prefill the assistant response and rejects it.Likely sources of the trailing assistant message within deepagents:
response_format/ structured output node — Although LangGraph'screate_react_agentwas refactored in PR [#5872](Refactor create_react_agent to Enforce Structured Output in Agent Node langgraph#5872) / [#5873](feat: Implement Tool-Based Structured Output for React Agent langgraph#5873) to use tool strategy instead of prefill, the deep agent's own middleware stack may still produce trailing assistant messages.Expected Behavior
create_deep_agentshould work with Claude 4.6 models without errors. The agent should either:output_config.format(Anthropic's recommended replacement for prefill-based structured output).Suggested Fix
A middleware-level or pre-dispatch sanitization that detects Claude 4.6+ models and ensures the messages array never ends with
role: "assistant". For example:Alternatively, a model-profile-based approach using LangChain 1.1+'s
.profileattribute to check if the model supports prefill.System Information
Related Issues in Other Projects
This breaking change is affecting multiple projects across the ecosystem:
assistantresponse is not supported langgraph#4940) — "When using tools, pre-filling the assistant response is not supported" (partially addressed via #5872/#5873)Workarounds
Until this is fixed, users can:
Use Claude Sonnet 4.5 which still supports prefill:
Use
anthropic-compat— a [drop-in shim](https://github.com/ProAndMax/anthropic-compat) that intercepts prefilled assistant messages and converts them to system prompt instructions:Reproduction Steps / Example Code (Python)
Error Message and Stack Trace (if applicable)
Description
[BUG] Claude Opus 4.6 / Sonnet 4.6: "This model does not support assistant message prefill" error
[BUG] Claude Opus 4.6 / Sonnet 4.6: "This model does not support assistant message prefill" error
Checked other resources
Description
When using
create_deep_agentwith Claude Opus 4.6 (claude-opus-4-6) or Sonnet 4.6 (claude-sonnet-4-6), the agent fails with a 400 Bad Request error:This is a breaking change in Claude 4.6 models — Anthropic removed support for assistant message prefilling (last-assistant-turn prefills). Any request where the messages array ends with
role: "assistant"now returns a 400 error.See Anthropic's official documentation:
The same code works perfectly with Claude Sonnet 4.5 (
claude-sonnet-4-5-20250929).Minimal Reproducible Example
Error Output
Root Cause Analysis
The error occurs because somewhere in deepagents' internal pipeline, the messages array sent to the Anthropic API ends with a message with
role: "assistant". Claude 4.6 interprets this as an attempt to prefill the assistant response and rejects it.Likely sources of the trailing assistant message within deepagents:
response_format/ structured output node — Although LangGraph'screate_react_agentwas refactored in PR [#5872](Refactor create_react_agent to Enforce Structured Output in Agent Node langgraph#5872) / [#5873](feat: Implement Tool-Based Structured Output for React Agent langgraph#5873) to use tool strategy instead of prefill, the deep agent's own middleware stack may still produce trailing assistant messages.Expected Behavior
create_deep_agentshould work with Claude 4.6 models without errors. The agent should either:output_config.format(Anthropic's recommended replacement for prefill-based structured output).Suggested Fix
A middleware-level or pre-dispatch sanitization that detects Claude 4.6+ models and ensures the messages array never ends with
role: "assistant". For example:Alternatively, a model-profile-based approach using LangChain 1.1+'s
.profileattribute to check if the model supports prefill.System Information
Related Issues in Other Projects
This breaking change is affecting multiple projects across the ecosystem:
assistantresponse is not supported langgraph#4940) — "When using tools, pre-filling the assistant response is not supported" (partially addressed via #5872/#5873)Workarounds
Until this is fixed, users can:
Use Claude Sonnet 4.5 which still supports prefill:
Use
anthropic-compat— a [drop-in shim](https://github.com/ProAndMax/anthropic-compat) that intercepts prefilled assistant messages and converts them to system prompt instructions:Checked other resources
Description
When using
create_deep_agentwith Claude Opus 4.6 (claude-opus-4-6) or Sonnet 4.6 (claude-sonnet-4-6), the agent fails with a 400 Bad Request error:This is a breaking change in Claude 4.6 models — Anthropic removed support for assistant message prefilling (last-assistant-turn prefills). Any request where the messages array ends with
role: "assistant"now returns a 400 error.See Anthropic's official documentation:
The same code works perfectly with Claude Sonnet 4.5 (
claude-sonnet-4-5-20250929).Minimal Reproducible Example
Error Output
Root Cause Analysis
The error occurs because somewhere in deepagents' internal pipeline, the messages array sent to the Anthropic API ends with a message with
role: "assistant". Claude 4.6 interprets this as an attempt to prefill the assistant response and rejects it.Likely sources of the trailing assistant message within deepagents:
response_format/ structured output node — Although LangGraph'screate_react_agentwas refactored in PR [#5872](Refactor create_react_agent to Enforce Structured Output in Agent Node langgraph#5872) / [#5873](feat: Implement Tool-Based Structured Output for React Agent langgraph#5873) to use tool strategy instead of prefill, the deep agent's own middleware stack may still produce trailing assistant messages.Expected Behavior
create_deep_agentshould work with Claude 4.6 models without errors. The agent should either:output_config.format(Anthropic's recommended replacement for prefill-based structured output).Suggested Fix
A middleware-level or pre-dispatch sanitization that detects Claude 4.6+ models and ensures the messages array never ends with
role: "assistant". For example:Alternatively, a model-profile-based approach using LangChain 1.1+'s
.profileattribute to check if the model supports prefill.System Information
Related Issues in Other Projects
This breaking change is affecting multiple projects across the ecosystem:
assistantresponse is not supported langgraph#4940) — "When using tools, pre-filling the assistant response is not supported" (partially addressed via #5872/#5873)Workarounds
Until this is fixed, users can:
Use Claude Sonnet 4.5 which still supports prefill:
Use
anthropic-compat— a [drop-in shim](https://github.com/ProAndMax/anthropic-compat) that intercepts prefilled assistant messages and converts them to system prompt instructions:Environment / System Info
No response