[KongchangAI]
Concept停止原因 / 停止原因字段

stop_reason

A top-level field in Anthropic Messages API responses that indicates why the model stopped generating. It has seven possible values: end_turn, tool_use, max_tokens, stop_sequence, refusal, pause_turn, and model_context_window_exceeded.

Timeline (last 90 days)

Nov 13

For Agent applications using Anthropic server-side tools, after the return, you should explicitly check whether response_metadata["stop_reason"] is pause_turn, and implement retry logic yourself or log it.

Unverified50%
Nov 13

After LangChain wrapping, the stop_reason of an Anthropic response can usually be read via the message's response_metadata["stop_reason"].

Unverified50%
Nov 13

The Anthropic Messages API may return a response with stop_reason 'pause_turn' when server-side tools run for a long time, and the client should send that response back as-is to continue executing the unfinished tool calls.

Unverified50%
Oct 24

When the model decides to use a tool, the stop_reason in the Claude API response changes to tool_use, and a tool_use block containing the tool ID, name, and input parameters appears.

Unverified50%
Oct 14

The main loop translates stop_reason into the next action decision: tool_use enters the tool execution branch, max_tokens triggers max_output_tokens_escalate or max_output_tokens_recovery, and prompt_too_long maps to reactive_compact_retry.

Unverified50%
Oct 13

In practice, stop_reason === 'tool_use' does not reliably reflect message structure: a response may contain a real tool call block yet report end_turn.

Unverified50%
Oct 13

In streaming (SSE) mode, stop_reason is given in the message_delta event, immediately before message_stop, rather than arriving with the first event.

Unverified50%
Oct 13

The stop_reason field in the top-level response of the Anthropic Messages API has seven possible values in total: end_turn, tool_use, max_tokens, stop_sequence, refusal, pause_turn, and model_context_window_exceeded.

Unverified60%
Sep 24

The LangChain September update enhanced SDK run tracing capabilities, adding capture of stop_reason values for Claude SDK runs.

Unverified50%

All Facts (10)

Unverified

The stop_reason field in the top-level response of the Anthropic Messages API has seven possible values in total: end_turn, tool_use, max_tokens, stop_sequence, refusal, pause_turn, and model_context_window_exceeded.

60%
Unverified

For Agent applications using Anthropic server-side tools, after the return, you should explicitly check whether response_metadata["stop_reason"] is pause_turn, and implement retry logic yourself or log it.

50%
Unverified

After LangChain wrapping, the stop_reason of an Anthropic response can usually be read via the message's response_metadata["stop_reason"].

50%
Unverified

The Anthropic Messages API may return a response with stop_reason 'pause_turn' when server-side tools run for a long time, and the client should send that response back as-is to continue executing the unfinished tool calls.

50%
Unverified

When the model decides to use a tool, the stop_reason in the Claude API response changes to tool_use, and a tool_use block containing the tool ID, name, and input parameters appears.

50%
Unverified

The main loop translates stop_reason into the next action decision: tool_use enters the tool execution branch, max_tokens triggers max_output_tokens_escalate or max_output_tokens_recovery, and prompt_too_long maps to reactive_compact_retry.

50%
Unverified

In practice, stop_reason === 'tool_use' does not reliably reflect message structure: a response may contain a real tool call block yet report end_turn.

50%
Unverified

In streaming (SSE) mode, stop_reason is given in the message_delta event, immediately before message_stop, rather than arriving with the first event.

50%
Unverified

The LangChain September update enhanced SDK run tracing capabilities, adding capture of stop_reason values for Claude SDK runs.

50%
Unverified

The two signals that drive the Agent Loop come from the stop_reason field returned by the model: when stop_reason equals tool_use, the host executes the tool and continues the loop; otherwise, the loop exits.

50%

Source Articles