Skip to main content

AssistantMessage

Struct AssistantMessage 

Source
pub struct AssistantMessage {
Show 46 fields pub message: AssistantMessageContent, pub session_id: String, pub uuid: Option<String>, pub parent_tool_use_id: Option<String>, pub request_id: Option<String>, pub refused_message_id: Option<String>, pub user_message_uuid: Option<String>, pub user_message_uuids: Vec<String>, pub agent_id: Option<String>, pub subagent_type: Option<String>, pub task_description: Option<String>, pub error: Option<AssistantErrorKind>, pub aborted: Option<bool>, pub resumed_from_incomplete_thinking: Option<bool>, pub supersedes: Vec<String>, pub timestamp: Option<String>, pub tool_use_meta: Vec<ToolUseMeta>, pub batch_tool_uses: Vec<BatchToolUse>, pub wire_tool_inputs: Option<Map<String, Value>>, pub wire_ingest_context: Option<Map<String, Value>>, pub historical: Option<bool>, pub resume_reason: Option<String>, pub local_command_source: Option<String>, pub narration_block_indexes: Vec<usize>, pub narration_hint: Option<String>, pub thinking_duration_ms: Option<u64>, pub thinking_display: Option<String>, pub context_usage: Option<ContextUsage>, pub usage_report: Option<Box<UsageReport>>, pub local_command_run: Option<LocalCommandRun>, pub local_command_outcome: Option<LocalCommandOutcome>, pub is_meta: Option<bool>, pub is_virtual: Option<bool>, pub is_api_error_message: Option<bool>, pub api_error_status: Option<u16>, pub api_error: Option<String>, pub api_error_code: Option<String>, pub api_error_origin: Option<String>, pub api_error_params: Option<ApiErrorParams>, pub error_details: Option<String>, pub advisor_model: Option<String>, pub attribution_agent: Option<String>, pub attribution_skill: Option<String>, pub attribution_plugin: Option<String>, pub attribution_mcp_server: Option<String>, pub attribution_mcp_tool: Option<String>,
}
Expand description

Assistant message

Fields§

§message: AssistantMessageContent§session_id: String§uuid: Option<String>§parent_tool_use_id: Option<String>§request_id: Option<String>

Anthropic API request id that produced this message (e.g. req_...).

§refused_message_id: Option<String>

Only on the assistant message that reports a refusal: the API msg_* id of the refused response (message.id on this message is a local UUID). Absent when the CLI has no well-formed id for it, and on CLIs before 2.1.301.

§user_message_uuid: Option<String>

Client uuid of the user message that triggered this turn, stamped on the turn’s first top-level assistant message so a consumer can bind the reply to the send it answers without waiting for the result. With --include-partial-messages the first non-ping stream event is stamped too, independently (CLI 2.1.269+), so the same uuid may appear on both frames. Absent on every later assistant message of the turn, on subagent frames, on synthetic/scheduled (meta) turns, and from CLIs before 2.1.259.

§user_message_uuids: Vec<String>

Client uuids of every user message whose prompt this turn has consumed so far, in consumption order — all members of a prompt batch the host merged into this one turn. Always contains user_message_uuid; at most 64 entries. Present exactly when user_message_uuid is; absent from CLIs before 2.1.259 (fall back to user_message_uuid).

§agent_id: Option<String>

ID of the subagent that produced this message: the task_id of its task events, unchanged when the subagent is resumed. Absent on main-thread messages (CLI 2.1.292+).

§subagent_type: Option<String>

Subagent type, when this assistant message was produced inside a local_agent subagent (e.g. general-purpose, Explore).

§task_description: Option<String>

Short description of the subagent task, present alongside subagent_type.

§error: Option<AssistantErrorKind>§aborted: Option<bool>

True when this message was truncated by an interrupt/abort before the stream completed — stop_reason was never received and the content may end mid-word. Absent on normally completed messages.

§resumed_from_incomplete_thinking: Option<bool>

True when this turn continued the preceding truncated assistant turn inside its trailing signed thinking block (max-output-tokens recovery). Histories replayed through the bridge must carry the flag back so the normalizer keeps the run’s prefix on the wire.

§supersedes: Vec<String>§timestamp: Option<String>§tool_use_meta: Vec<ToolUseMeta>§batch_tool_uses: Vec<BatchToolUse>

{id, name} of the original Batch* tool_use block(s) for a message whose content was decomposed into synthetic v1 tool_use blocks. Round-tripped so a replayed history reassembles the batch block on the wire. Wrapper-level sibling — never inside message.content.

§wire_tool_inputs: Option<Map<String, Value>>

tool_use.input exactly as the API produced it, keyed by tool_use id, for a message whose message.content carries the client-normalized input. Round-tripped so a replayed history echoes each earlier tool call back to the API as the API emitted it. Wrapper-level sibling — never inside message.content (CLI 2.1.259+).

§wire_ingest_context: Option<Map<String, Value>>

What the client-side input normalization read from process state for the inputs in wire_tool_inputs, keyed by the same tool_use ids. Round-tripped so a replayed history can verify each recorded input against the normalized one. Wrapper-level sibling — never inside message.content (CLI 2.1.266+).

§historical: Option<bool>

Replayed history rather than a live message, stamped by the Remote Control bridge when it flushes history to the session server, which also stamps it on deliveries it replays (CLI 2.1.266+).

§resume_reason: Option<String>

Why this frame’s turn is the automatic re-run of a turn a worker restart interrupted: the host’s CLAUDE_CODE_RESUME_REASON when it set one (host_draining, checkpoint_restore, container_recreated, …), else interrupted_turn. Stamped on the same reply frames as user_message_uuid, which on such a re-run names the interrupted turn’s own last user prompt. Absent on every other turn and from CLIs before 2.1.268.

§local_command_source: Option<String>

The originating system/local_command row’s wire-form content, carried on the loop-synthesized local-command twin so a bridge/SDK history replay rebuilds the internal system row instead of dropping the output. Wrapper-level sibling — never inside message.content (CLI 2.1.259+).

§narration_block_indexes: Vec<usize>

Ascending zero-based indexes into message.content of the thinking blocks whose signature the server tagged as narration (server summaries of the prose between tool calls, not the model’s own reasoning), so a renderer can label them as summaries without decoding the signature envelope. Fail-closed: an unparseable or legacy signature is not listed. Omitted when the frame has no such block and by CLIs before 2.1.260; treat unlisted thinking blocks as ordinary thinking. Wrapper-level sibling — never inside message.content.

§narration_hint: Option<String>

How a renderer should treat this frame’s narration blocks: "hidden" or "faint" on CLI 2.1.280+ (kept open for future values). Omitted when the CLI expresses no preference.

§thinking_duration_ms: Option<u64>

How long the thinking block in this frame took to stream, in whole milliseconds (at least 1): from its content_block_start to its content_block_stop, so the wait for the response’s first token is not counted. For display only. Sent only on a frame whose one content block is a thinking block that was streamed; absent from CLIs before 2.1.287 and from a CLI replaying history it rebuilt from SDK frames, so be ready to show the block without a duration. Wrapper-level sibling — never inside message.content.

§thinking_display: Option<String>

The thinking.display value Claude Code put in the API request body for the response that streamed this frame’s thinking block; same source and meaning as StreamEventMessage::thinking_display. Sent only on a frame whose one content block is a thinking block that was streamed, and only when the request body had a display. Absent from CLIs before 2.1.296 and from a CLI replaying history it rebuilt from SDK frames; an absent key states nothing. Marked @internal upstream, so treat the value set as open. Wrapper-level sibling — never inside message.content.

§context_usage: Option<ContextUsage>

Structured twin of the /context report, carried on the synthetic assistant message that delivers the markdown table. Present only on /context results from CLIs new enough to attach it (2.1.239+).

§usage_report: Option<Box<UsageReport>>

Structured twin of the /usage report, carried on the synthetic assistant message that delivers its text: the session totals, the plan’s usage rows and extra-usage spend, for remote clients that render a card from data. Present only on /usage results from CLIs new enough to attach it (2.1.273+) and from claude.ai-subscriber sessions; the text in message.content remains the canonical fallback. Wrapper-level sibling — never inside message.content.

§local_command_run: Option<LocalCommandRun>

On the local-command twin, the run that printed the row: the command’s name (no slash) and its arguments as the echo shows them (*** when the command marks them sensitive). Present when a local command’s dispatch printed the row or a command.run hook answered it, absent on a never-ran notice. Wrapper-level sibling — never inside message.content (CLI 2.1.273+).

§local_command_outcome: Option<LocalCommandOutcome>

On the local-command twin, what the row reports (unavailable_headless, unknown, failed, restart_required), so a host can offer a fix instead of relaying the text. Absent when the row reports none of these; new kinds are additive, so treat an unknown one as absent. Wrapper-level sibling — never inside message.content (CLI 2.1.281+).

§is_meta: Option<bool>§is_virtual: Option<bool>§is_api_error_message: Option<bool>§api_error_status: Option<u16>§api_error: Option<String>

Typed kind of the API error when is_api_error_message is true. An open set the CLI grows release to release: 2.1.274 extends the original max_output_tokens / dlp_request_denied / claude_code_version_too_old with effort_requires_thinking, advisor_incompatible, tool_history_mismatch, autocompact_thrashing, pdf_too_large, pdf_password_protected, media_removed (CLI 2.1.288+: the API refused an image or a document, so Claude Code leaves it out of the requests that follow), no_response, tls_untrusted_ca, gateway_content_type, provider_credentials, gateway_signin_required, gateway_session_expired, api_key_auth_disabled, org_disabled_credential, invalid_credential_header, model_requires_usage_credits, long_context_credits_required, consent_unanswered, no_allowed_fallback, model_substitution_disabled, field_not_granted, (CLI 2.1.292+) usage_limit_reached — the request was refused by the account’s own usage limit, a plan limit or a spend cap on usage credits; ApiErrorParams::rate_limit_info says which and when it resets — and (CLI 2.1.307+) empty_completion — the model ended its turn with no visible text and its one retry had no content block, so the turn ends as an error instead of a blank reply — and (CLI 2.1.311+) unattended_start_limit — a cloud session’s restarted process hit the configured limit of unattended carry-ons within 24 hours, so no request was sent; terminal for the turn, so a consumer replaying history must not re-send the prompt that led to it — and unattended_start_unconfirmed — the process could not check whether it was allowed to carry on, so no request was sent; not terminal. Kinds with parameters carry them in Self::api_error_params.

§api_error_code: Option<String>

The server’s error.details.error_code for this API error, copied through when it is an identifier (^[a-z][a-z0-9_]{0,63}$) and dropped otherwise. Carries server gate codes this CLI build has no api_error value for, so a host can key on a new gate without a Claude Code release. Absent when the response carried no code and from CLIs before 2.1.274.

§api_error_origin: Option<String>

first_party when this API error was built from a response Anthropic’s own API sent: the first-party provider, the default https://api.anthropic.com endpoint answering directly, over TLS verified with no added CA, override or socket tunnel. Absent in every other case (a base-URL override, a gateway, a third-party provider, a connection error, an error Claude Code raised itself, any replayed frame); treat absence as unknown origin. It says which endpoint answered, not that the text is the server’s verbatim, so render stamped text as plain text. Open set — treat an unknown value as absent (CLI 2.1.300+).

§api_error_params: Option<ApiErrorParams>

Parameters of Self::api_error, present only for the kinds that have any (CLI 2.1.274+).

§error_details: Option<String>§advisor_model: Option<String>§attribution_agent: Option<String>§attribution_skill: Option<String>§attribution_plugin: Option<String>§attribution_mcp_server: Option<String>§attribution_mcp_tool: Option<String>

Trait Implementations§

Source§

impl Clone for AssistantMessage

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AssistantMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AssistantMessage

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for AssistantMessage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.