LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Browser
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
  • Tools
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Decisions
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Compat
  • Event
  • Llms
  • Openai Completions Stream
  • Profile
  • Stream
  • Structured Output
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Testing
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Gateway
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Standard Schema
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Uuid
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

Chat LangChain

What can I help with?

Enter to sendĀ·Shift+Enter new line

Menu

LangChain
BrowserUniversalHubNodeLoadSerializableEncoder BackedFile SystemIn MemoryTools
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextDecisionsBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsCompatEventLlmsOpenai Completions StreamProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingGatewayHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScriptlangchainindexanthropicPauseTurnMiddleware
Functionā—Since v1.6

anthropicPauseTurnMiddleware

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. Each continuation is a separate request, and a turn still paused after maxContinuations of them throws PauseTurnLimitExceededError, which carries the responses of the turn.

The responses of a continued turn are returned as one AIMessage whose content is every response's content in order, so the paused content stays in the history that later requests send back. It keeps the last response's id and metadata and sums the usage of all of them. Anthropic merges consecutive assistant turns, so the model sees the same conversation either way.

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 new ChatAnthropic({ reuseLastContainer: true }) so continuations run in the same container as the paused turn.

Copy
anthropicPauseTurnMiddleware(
  middlewareOptions: AnthropicPauseTurnMiddlewareConfig = {}
): AgentMiddleware<undefined, undefined, unknown, readonly ClientTool | ServerTool[], readonly []>

Parameters

NameTypeDescription
middlewareOptionsAnthropicPauseTurnMiddlewareConfig
Default:{}

Configuration options

Example

Copy
import { createAgent, anthropicPauseTurnMiddleware } from "langchain";

const agent = createAgent({
  model: "anthropic:claude-sonnet-5-5",
  tools: [{ type: "web_search_20250305", name: "web_search" }],
  middleware: [anthropicPauseTurnMiddleware()],
});
View source on GitHub