Skip to content

Class: AssistantMessage

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / AssistantMessage

Defined in: src/types/messages.ts:263

Assistant response message.

Represents a response from the AI assistant, which may contain text, media content, and/or tool call requests.

// Simple text response
const msg = new AssistantMessage('Hello! How can I help?');
// Response with tool calls
const msg = new AssistantMessage(
'Let me check the weather...',
[{ toolCallId: 'call_1', toolName: 'get_weather', arguments: { location: 'NYC' } }]
);

new AssistantMessage(content, toolCalls?, options?): AssistantMessage

Defined in: src/types/messages.ts:280

Creates a new assistant message.

String (converted to TextBlock) or array of content blocks

string | AssistantContent[]

ToolCall[]

Tool calls requested by the model

MessageOptions

Optional message ID and metadata

AssistantMessage

Message.constructor

readonly content: AssistantContent[]

Defined in: src/types/messages.ts:268

Content blocks in this message


readonly id: string

Defined in: src/types/messages.ts:124

Unique message identifier

Message.id


readonly optional metadata: MessageMetadata

Defined in: src/types/messages.ts:130

Provider-specific metadata, namespaced by provider name

Message.metadata


readonly timestamp: Date

Defined in: src/types/messages.ts:127

Timestamp when the message was created

Message.timestamp


readonly optional toolCalls: ToolCall[]

Defined in: src/types/messages.ts:271

Tool calls requested by the model (if any)


readonly type: "assistant"

Defined in: src/types/messages.ts:265

Message type discriminator

Message.type

get audio(): AudioBlock[]

Defined in: src/types/messages.ts:180

All audio content blocks in this message.

AudioBlock[]

Message.audio


get documents(): DocumentBlock[]

Defined in: src/types/messages.ts:173

All document content blocks in this message.

DocumentBlock[]

Message.documents


get hasToolCalls(): boolean

Defined in: src/types/messages.ts:301

Whether this message contains tool call requests.

boolean


get images(): ImageBlock[]

Defined in: src/types/messages.ts:166

All image content blocks in this message.

ImageBlock[]

Message.images


get reasoning(): ReasoningBlock[]

Defined in: src/types/messages.ts:195

All reasoning/thinking content blocks in this message. Available when using extended thinking models.

ReasoningBlock[]

Message.reasoning


get text(): string

Defined in: src/types/messages.ts:156

Concatenated text content from all text blocks. Blocks are joined with double newlines.

string

Message.text


get video(): VideoBlock[]

Defined in: src/types/messages.ts:187

All video content blocks in this message.

VideoBlock[]

Message.video

protected getContent(): ContentBlock[]

Defined in: src/types/messages.ts:294

Returns the content blocks for this message. Implemented by subclasses to provide type-specific content.

ContentBlock[]

Message.getContent