Skip to main content
Access these through the tracing module:

Message

A single message in a conversation. Two construction styles are supported:
  1. Flat (back-compat, ergonomic for plain text): Message(role="assistant", content="Hi there")
  2. Explicit parts (richer; supports tool calls, mixed reasoning+text, inline media): Message(role="assistant", parts=[TextPart(content="Let me check"), ToolCallPart(id="c1", name="get_weather", arguments='{...}')])
When parts is non-empty it is the canonical representation. When empty, the serializer synthesizes a single TextPart (or ToolCallResponsePart for role="tool") from the flat fields. Message is a Pydantic model. Set any field below as a keyword argument when you construct it. Fields

Message.user

Build a user message from plain text.

Message.system

Build a system message from plain text.

Message.assistant

Build an assistant message with optional text and tool calls. Use plain text for simple replies; pass tool_calls when the assistant requests one or more tools. When both are present the text is emitted as a leading TextPart followed by each ToolCallPart so the chat view renders them inline.

Message.tool_result

Build a tool-result message for a previously-requested tool call. output may be a string, dict, list, scalar, or None; the underlying ToolCallResponsePart JSON-encodes non-strings.

MessagePart

TextPart

Plain-text content part. TextPart is a Pydantic model. Set any field below as a keyword argument when you construct it. Fields

ReasoningPart

Reasoning / chain-of-thought content part. ReasoningPart is a Pydantic model. Set any field below as a keyword argument when you construct it. Fields

ToolCallPart

An assistant’s request to invoke a tool. arguments is a string on the wire (per GenAI semconv). The JSONString annotation lets callers pass a dict / list / scalar at construction or assignment and the SDK JSON-encodes it; an already-encoded string passes through unchanged. ToolCallPart is a Pydantic model. Set any field below as a keyword argument when you construct it. Fields

ToolCallResponsePart

The result of executing a previously-requested tool call. response is a string on the wire. Same JSONString ergonomics as ToolCallPart.arguments. ToolCallResponsePart is a Pydantic model. Set any field below as a keyword argument when you construct it. Fields

BlobPart

Inline binary content (for example base64-encoded image / audio). BlobPart is a Pydantic model. Set any field below as a keyword argument when you construct it. Fields

UriPart

Reference to media content by URI. UriPart is a Pydantic model. Set any field below as a keyword argument when you construct it. Fields

FilePart

Reference to media content by provider-side file id. FilePart is a Pydantic model. Set any field below as a keyword argument when you construct it. Fields

Usage

Token usage for an LLM call. Usage is a Pydantic model. Set any field below as a keyword argument when you construct it. Fields

Reasoning

Reasoning/chain-of-thought content from an LLM call. Reasoning is a Pydantic model. Set any field below as a keyword argument when you construct it. Fields

MediaAttachment

Media emitted as an OTLP GenAI blob, URI, or provider file part. MediaAttachment is a Pydantic model. Set any field below as a keyword argument when you construct it. Fields
Last modified on September 30, 2026