Agent SDK reference - Python changedagent-sdk/python
Nearest release: v2.1.326, published 4 hours before upstream edited the page. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Upstream edited this page at 16 Nov 2026 22:46 UTC, give or take a minute or two: the time comes from Anthropic’s own sitemap rather than from a commit. This site recorded the change at 16 Nov 2026 23:07 UTC.
Upstream edited
Recorded here
Lines+3added
Lines−1removed
From line
1,728
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits85to this page, all time
The whole hunk
from line 1728, old and new numbered
/
from line 1728
17281728* `result`: text of the final assistant message on `subtype="success"`, or `None` on the `error_*` subtypes. When `subtype="success"` and `is_error=True`, this holds the API error string if one is available but can be empty, so check `api_error_status` and the preceding `AssistantMessage` content for detail.
17291729* `errors`: loop-level error strings such as the max-turns message. Populated only on the `error_*` subtypes.
17301730* `terminal_reason`: why the query loop ended, such as `"completed"`, `"max_turns"`, `"api_error"`, `"aborted_streaming"`, or `"aborted_tools"`. A value of `"aborted_streaming"` or `"aborted_tools"` means the turn was aborted before completing. Common causes are [`interrupt()`](#claudesdkclient) and a permission callback returning [`PermissionResultDeny`](#permissionresultdeny) with `interrupt=True`. `None` on CLI versions that predate the field, on results from local commands such as `/voice` or `/usage`, which bypass the query loop, or on synthesized error results emitted when the session fails fatally. Mirrors the TypeScript SDK's [`SDKResultMessage.terminal_reason`](https://code.claude.com/docs/en/agent-sdk/typescript#sdkresultmessage), which lists the full set of values.
1731* `origin`: origin of the user message that triggered this turn. In [streaming input mode](https://code.claude.com/docs/en/agent-sdk/streaming-vs-single-mode.md), check this to tell the result of your own prompt, where `origin` is `None` or `{"kind": "human"}`, from the result of an injected turn such as a background-task notification. Requires Python Agent SDK 0.2.137 or later.
1731* `origin`: origin of the user message that triggered this turn. Requires Python Agent SDK 0.2.137 or later. Don't suppress a result on `kind` alone. In [streaming input mode](https://code.claude.com/docs/en/agent-sdk/streaming-vs-single-mode.md), check `origin` to see whether your own prompt started the turn:
1732 * **Your own prompt**: `origin` is `None` or `{"kind": "human"}`
1733 * **A background-task notification**: `origin["kind"]` is `"task-notification"`. That turn's result can also hold Claude's answer to a message you sent while the turn ran tools.
17321734
17331735When several background tasks finish close together, Claude Code can answer their notifications in one turn rather than one turn each. You still receive one `ResultMessage` per notification, in order, each with an `origin` whose `kind` is `"task-notification"`. All but the last have `num_turns` set to `0` and an empty `result`, and the last one carries the turn that answers them all.
17341736
No line in this hunk matches that.