Last Stop Reason • AI Agent SDK

last_stop_reason: Structured reason the last tool-execution loop stopped.

last_stop_reason

Method

</div>

This is a method of the Agent class in the agent module.

Structured reason the last tool-execution loop stopped.

One of `"completed" (task finished), "max_steps" (the unified step budget from ExecutionConfig.max_steps was reached and the run was truncated), a provider block/refusal/truncation ("content_filtered" | "refused" | "length_truncated") derived from the LLM finish_reason/refusal signal, "timeout" (the turn passed ExecutionConfig.max_execution_time or the run_autonomous deadline), or "error"`. Lets CLI/CI callers branch on the terminal reason instead of parsing a magic string. Reads from whichever backend (OpenAI-native or LiteLLM) executed the last turn.

Signature

python
def last_stop_reason() -> str

Returns

ResponseField str

The result of the operation.

Source

View on GitHub

praisonaiagents/agent/agent.py at line 4120