AnthropicPauseTurnMiddleware(
self,
max_continuations: int = 5,
)| Name | Type | Description |
|---|---|---|
max_continuations | int | Default: 5The most continuation requests to send for one paused turn. |
| Name | Type |
|---|---|
| max_continuations | int |
Continue model turns that Anthropic pauses with stop_reason: "pause_turn".
Anthropic runs server tools such as web search and web fetch in a loop of its
own and can pause a long turn before it finishes. The response then ends with
stop_reason: "pause_turn", sometimes with a server tool call that has not
run yet, and carries no client tool calls, so the agent loop would end the run
on the unfinished turn.
This middleware sends a paused response back unchanged, with the same tools
and no added user message, until the turn ends. Every response, paused or
final, is kept in the conversation in order. Each continuation is a separate
request, and a turn still paused after max_continuations of them raises
PauseTurnLimitExceededError, which carries the responses of the turn.
Responses from models other than Anthropic's never pause, so they pass through unchanged.
Tools that run in a code execution container, including the _20260209 and
later versions of web search and web fetch, need
ChatAnthropic(reuse_last_container=True) so continuations run in the same
container as the paused turn.
Example:
from langchain.agents import create_agent
from langchain_anthropic import ChatAnthropic
from langchain_anthropic.middleware import AnthropicPauseTurnMiddleware
agent = create_agent(
model=ChatAnthropic(model="claude-sonnet-5-5", reuse_last_container=True),
tools=[{"type": "web_search_20260209", "name": "web_search"}],
middleware=[AnthropicPauseTurnMiddleware()],
)
Learn more about paused turns here.