ant_ai.core.message
AnyMessage
AnyMessage = Annotated[
Message | ToolCallMessage | ToolCallResultMessage,
Field(discriminator="kind"),
]
Type alias for any message type in the system, discriminated by the _kind field.
Message
pydantic-model
Bases: BaseModel
Generic message used in a conversation
Show JSON schema:
{
"description": "Generic message used in a conversation",
"properties": {
"kind": {
"const": "message",
"default": "message",
"title": "Kind",
"type": "string"
},
"role": {
"title": "Role",
"type": "string"
},
"content": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Content"
},
"metadata": {
"additionalProperties": true,
"title": "Metadata",
"type": "object"
}
},
"required": [
"role"
],
"title": "Message",
"type": "object"
}
Fields:
Source code in src/ant_ai/core/message.py
8 9 10 11 12 13 14 15 16 17 18 | |
kind
pydantic-field
kind: Literal['message'] = 'message'
Type of the message. Used to reconstruct, not passed to the LLM
role
pydantic-field
role: str
Role of the message sender (e.g. "user", "assistant")
content
pydantic-field
content: str | None = None
Text content of the message
metadata
pydantic-field
metadata: dict[str, Any]
Additional metadata associated with the message
MessageChunk
pydantic-model
Bases: BaseModel
Represents partial output from an LLM during streaming.
delta is the content's only the newly streamed text fragment,
not the whole message so far.
Show JSON schema:
{
"description": "Represents *partial output* from an LLM during streaming.\n`delta` is the content's only the newly streamed text fragment,\nnot the whole message so far.",
"properties": {
"role": {
"title": "Role",
"type": "string"
},
"delta": {
"title": "Delta",
"type": "string"
},
"metadata": {
"additionalProperties": true,
"title": "Metadata",
"type": "object"
}
},
"required": [
"role",
"delta"
],
"title": "MessageChunk",
"type": "object"
}
Fields:
-
role(str) -
delta(str) -
metadata(dict)
Source code in src/ant_ai/core/message.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
merge
merge(other: MessageChunk) -> MessageChunk
Combines two MessageChunk into one
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
MessageChunk
|
The other message chunk to combine with |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MessageChunk |
MessageChunk
|
A combined chunk where this is before the other chunk |
Source code in src/ant_ai/core/message.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
to_message
to_message() -> Message
Convert final chunk to a full message once streaming ends.
Source code in src/ant_ai/core/message.py
49 50 51 | |
ToolCallMessage
pydantic-model
Bases: Message
Message representing a tool call in a conversation
Show JSON schema:
{
"$defs": {
"ToolCall": {
"description": "Single tool call object inside assistant.tool_calls (OpenAI schema).",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"type": {
"default": "function",
"title": "Type",
"type": "string"
},
"function": {
"$ref": "#/$defs/ToolFunction"
}
},
"required": [
"id",
"function"
],
"title": "ToolCall",
"type": "object"
},
"ToolFunction": {
"description": "Inner function payload for a tool call (OpenAI schema).",
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"arguments": {
"title": "Arguments",
"type": "string"
}
},
"required": [
"name",
"arguments"
],
"title": "ToolFunction",
"type": "object"
}
},
"description": "Message representing a tool call in a conversation",
"properties": {
"kind": {
"const": "tool_call",
"default": "tool_call",
"title": "Kind",
"type": "string"
},
"role": {
"default": "assistant",
"title": "Role",
"type": "string"
},
"content": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Content"
},
"metadata": {
"additionalProperties": true,
"title": "Metadata",
"type": "object"
},
"tool_calls": {
"items": {
"$ref": "#/$defs/ToolCall"
},
"title": "Tool Calls",
"type": "array"
}
},
"required": [
"tool_calls"
],
"title": "ToolCallMessage",
"type": "object"
}
Fields:
-
content(str | None) -
metadata(dict[str, Any]) -
kind(Literal['tool_call']) -
role(str) -
tool_calls(list[ToolCall])
Source code in src/ant_ai/core/message.py
54 55 56 57 58 59 | |
ToolCallResultMessage
pydantic-model
Bases: Message
Message representing the result of a tool call in a conversation
Show JSON schema:
{
"description": "Message representing the result of a tool call in a conversation",
"properties": {
"kind": {
"const": "tool_call_result",
"default": "tool_call_result",
"title": "Kind",
"type": "string"
},
"role": {
"default": "tool",
"title": "Role",
"type": "string"
},
"content": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Content"
},
"metadata": {
"additionalProperties": true,
"title": "Metadata",
"type": "object"
},
"tool_call_id": {
"title": "Tool Call Id",
"type": "string"
},
"name": {
"title": "Name",
"type": "string"
}
},
"required": [
"tool_call_id",
"name"
],
"title": "ToolCallResultMessage",
"type": "object"
}
Fields:
-
content(str | None) -
metadata(dict[str, Any]) -
kind(Literal['tool_call_result']) -
role(str) -
tool_call_id(str) -
name(str)
Source code in src/ant_ai/core/message.py
62 63 64 65 66 67 68 | |
ToolFunction
pydantic-model
Bases: BaseModel
Inner function payload for a tool call (OpenAI schema).
Show JSON schema:
{
"description": "Inner function payload for a tool call (OpenAI schema).",
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"arguments": {
"title": "Arguments",
"type": "string"
}
},
"required": [
"name",
"arguments"
],
"title": "ToolFunction",
"type": "object"
}
Fields:
Source code in src/ant_ai/core/message.py
71 72 73 74 75 76 77 78 | |
name
pydantic-field
name: str
Name of the tool called
arguments
pydantic-field
arguments: str
Arguments for the tool
ToolCall
pydantic-model
Bases: BaseModel
Single tool call object inside assistant.tool_calls (OpenAI schema).
Show JSON schema:
{
"$defs": {
"ToolFunction": {
"description": "Inner function payload for a tool call (OpenAI schema).",
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"arguments": {
"title": "Arguments",
"type": "string"
}
},
"required": [
"name",
"arguments"
],
"title": "ToolFunction",
"type": "object"
}
},
"description": "Single tool call object inside assistant.tool_calls (OpenAI schema).",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"type": {
"default": "function",
"title": "Type",
"type": "string"
},
"function": {
"$ref": "#/$defs/ToolFunction"
}
},
"required": [
"id",
"function"
],
"title": "ToolCall",
"type": "object"
}
Fields:
-
id(str) -
type(str) -
function(ToolFunction)
Source code in src/ant_ai/core/message.py
81 82 83 84 85 86 87 88 89 | |
id
pydantic-field
id: str
Unique ID for the tool call, is generated by the OpenAI compatible endpoint
type
pydantic-field
type: str = 'function'
Type of the tool call