AssistantMessage class

An assistant message containing a response or tool calls.

Assistant messages represent responses from the model. They can contain:

  • Text content
  • Tool/function calls
  • A refusal message
  • Reasoning content (for models that support reasoning like DeepSeek R1)

Example

final message = ChatMessage.assistant(
  content: 'The weather in San Francisco is sunny.',
);
Inheritance
Annotations
  • @immutable

Constructors

AssistantMessage({String? content, String? name, String? refusal, List<ToolCall>? toolCalls, String? reasoningContent, String? reasoning, List<ReasoningDetail>? reasoningDetails})
Creates an AssistantMessage.
const
AssistantMessage.fromJson(Map<String, dynamic> json)
Creates an AssistantMessage from JSON.
factory

Properties

content String?
The text content of the assistant message.
final
hashCode int
The hash code for this object.
no setteroverride
hasReasoningContent bool
Whether this message contains reasoning content.
no setter
hasToolCalls bool
Whether this message contains tool calls.
no setter
isRefusal bool
Whether the model refused to respond.
no setter
name String?
An optional name for the participant.
final
reasoning String?
OpenRouter only. The reasoning summary from the model.
final
reasoningContent String?
DeepSeek R1 / vLLM only. The reasoning content from the model.
final
reasoningDetails List<ReasoningDetail>?
OpenRouter only. Detailed reasoning information.
final
refusal String?
The refusal message if the model declined to respond.
final
role String
The role of the message author.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
toolCalls List<ToolCall>?
The tool calls made by the assistant.
final

Methods

copyWith({Object? content = unsetCopyWithValue, Object? name = unsetCopyWithValue, Object? refusal = unsetCopyWithValue, Object? toolCalls = unsetCopyWithValue, Object? reasoningContent = unsetCopyWithValue, Object? reasoning = unsetCopyWithValue, Object? reasoningDetails = unsetCopyWithValue}) AssistantMessage
Creates a copy with the given fields replaced.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toApiJson() Map<String, dynamic>
Converts to JSON for sending back to the API.
toJson() Map<String, dynamic>
Converts to JSON.
override
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override