Skip to main content

Overview

Messages are the fundamental building blocks of conversations in core-ai. They represent the dialogue between users, the assistant, and tools.

Message Types

core-ai supports four message types:

System Message

System messages set the context and behavior for the assistant.
Example:

User Message

User messages represent input from the user. They can be simple text or multi-modal content with images, files, and audio.
Simple Text:
Multi-Modal Content:

Assistant Message

Assistant messages contain the model’s responses, including text, reasoning, and tool calls.
Example:
Assistant messages use a parts array to support multiple content types (text, reasoning, tool calls) in a single message.

Tool Result Message

Tool result messages provide the results of tool calls back to the model.
Example:

User Content Parts

User messages can include multiple types of content:

Text Part

Simple text content:
Example:

Image Part

Images can be provided as URLs or base64-encoded data:
URL Image:
Base64 Image:

File Part

Files can be attached with mime type information:
Example:

Audio Parts

Audio parts contain base64-encoded audio:
Not all providers support all content types. For example, Anthropic accepts PDF file parts only. Check the provider pages for model-specific input limits.

Assistant Content Parts

Assistant messages can contain text, reasoning, and tool calls:

Text Part

Regular text responses:

Reasoning Part

Extended thinking and reasoning content from the model:
The metadata field is application-owned. Provider adapters ignore it. The providerMetadata object is provider-namespaced. The top-level key is the provider identifier, such as 'anthropic', 'google', 'openai', or 'azure-openai'. Adapters treat other providers’ keys as foreign and downgrade those reasoning blocks to plain text instead of forwarding opaque metadata.
Use getProviderMetadata() when you want typed access to provider-specific metadata.
Accessing Reasoning:

Tool Call Part

Requests to call external tools:
Pass tool call parts back into the next request unchanged. Some providers put data on them that has to return verbatim: Gemini 3 rejects a request when a function call from the current turn is replayed without its thought signature.

Part metadata

Text-bearing parts can carry optional metadata for application and middleware state. Use it for annotations such as classification results, provenance, validation status, or text transformation spans. This metadata stays with the part in message history and generated results. Provider adapters do not serialize it to provider APIs. core-ai has three metadata layers:
  • GenerateOptions.metadata is call-level context for observability and middleware.
  • ReasoningPart.providerMetadata and ToolCallPart.providerMetadata are provider-owned data used to round-trip reasoning blocks and tool calls with the same provider.
  • Application-owned metadata on system messages, text parts, reasoning parts, tool calls, and tool results.

Multi-Turn Conversations

Build conversations by passing message history:

Helper functions

For message helpers like resultToMessage() and assistantMessage(), see the utilities reference.

Tool Call Flow

Here’s a complete example of handling tool calls:

Best Practices

Keep system messages concise: System messages set the tone but shouldn’t contain too much information. For large context, consider using user messages with retrieved content.
Use resultToMessage for history: Always convert generation results to messages using resultToMessage() to maintain proper conversation history with all content parts.
Multi-modal order matters: When combining text and images, place the text part first to provide context for what you’re asking about the image.

Next Steps