-
public final class AIMessagePartOne step an AI agent took while replying, such as a round of reasoning or a tool call.
The agent writes each step as a custom attachment on its reply (
ai_reasoning,ai_tool_call), and the order of the attachments is the order of the steps. The final answer stays in the message text and is shown after them.The kinds of step are open: a new one can appear without breaking your code. Read the ones you know through their typed views (reasoning, toolCall), read kinds of your own from payload, and give anything else a neutral fallback (
AIMessagePartItemshows a placeholder). Decoding is lenient: missing fields get defaults, and a step newer than this SDK understands keeps its payload but has no typed view.// Stream Chat Android moves an attachment's `name` out of `extraData`, so put it back. val parts = AIMessagePart.parts( message.attachments.map { it.type.orEmpty() to it.extraData + ("name" to it.name) }, ) for (part in parts) { part.reasoning?.let { /* … */} part.toolCall?.let { /* … */} if (part.kind == AIMessagePart.Kind("ai_citation")) { /* read part.payload */} }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classAIMessagePart.KindWhat kind of step a part is. It is an open set: compare against the kinds you know and give the rest a fallback.
public classAIMessagePart.Companion
-
Field Summary
Fields Modifier and Type Field Description private final BooleanisSupportedprivate final AIMessagePart.Kindkindprivate final Stringidprivate final Integerversionprivate final Map<String, Object>payloadprivate final AIReasoningPartreasoningprivate final AIToolCallParttoolCall
-
Method Summary
Modifier and Type Method Description final BooleangetIsSupported()final AIMessagePart.KindgetKind()What kind of step this is. final StringgetId()The step's stable identity, for diffing and animating while it streams. final IntegergetVersion()The step's format version ( v).final Map<String, Object>getPayload()The step's attachment payload, for kinds of your own or fields this SDK does not read. final AIReasoningPartgetReasoning()The step as a round of reasoning, when it is one this SDK can read. final AIToolCallPartgetToolCall()The step as a tool call, when it is one this SDK can read. Booleanequals(Object other)IntegerhashCode()StringtoString()-
-
Method Detail
-
getIsSupported
final Boolean getIsSupported()
-
getKind
final AIMessagePart.Kind getKind()
What kind of step this is.
-
getId
final String getId()
The step's stable identity, for diffing and animating while it streams. Tool calls use the model provider's tool-call ID.
-
getVersion
final Integer getVersion()
The step's format version (
v). It changes only when a kind changes incompatibly.
-
getPayload
final Map<String, Object> getPayload()
The step's attachment payload, for kinds of your own or fields this SDK does not read.
-
getReasoning
final AIReasoningPart getReasoning()
The step as a round of reasoning, when it is one this SDK can read.
-
getToolCall
final AIToolCallPart getToolCall()
The step as a tool call, when it is one this SDK can read.
-
-
-
-