Skip to content

[BUG] Claude Opus 4.6 / Sonnet 4.6: "This model does not support assistant message prefill" error #1585

Description

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title.
  • I searched existing issues and didn't find this.
  • I can reproduce this with the latest released version.
  • I included a minimal reproducible example and steps to reproduce.

Area (Required)

  • deepagents (SDK)
  • cli

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_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:

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](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_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 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:

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 messages

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:

Workarounds

Until 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

Reproduction Steps / Example Code (Python)

# [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 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:


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 messages


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:

- **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)

## Workarounds

Until 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

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 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:


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 messages


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:

- **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)

## Workarounds

Until 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

Checked other resources

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:

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](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_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 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:

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 messages

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:

Workarounds

Until 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

Checked other resources

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:

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](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_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 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:

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 messages

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:

Workarounds

Until 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

Environment / System Info

No response

Metadata

Metadata

Labels

bugSomething isn't workingdeepagentsRelated to the `deepagents` SDK / agent harnessexternalUser is not a member of the `langchain-ai` GitHub organization

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions