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.User Message
User messages represent input from the user. They can be simple text or multi-modal content with images, files, and audio.Assistant Message
Assistant messages contain the model’s responses, including text, reasoning, and tool calls.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.User Content Parts
User messages can include multiple types of content:Text Part
Simple text content:Image Part
Images can be provided as URLs or base64-encoded data:File Part
Files can be attached with mime type information:Audio Parts
Audio parts contain base64-encoded audio: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: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.Tool Call Part
Requests to call external tools:Part metadata
Text-bearing parts can carry optionalmetadata 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.metadatais call-level context for observability and middleware.ReasoningPart.providerMetadataandToolCallPart.providerMetadataare provider-owned data used to round-trip reasoning blocks and tool calls with the same provider.- Application-owned
metadataon 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 likeresultToMessage() and assistantMessage(), see the utilities reference.
Tool Call Flow
Here’s a complete example of handling tool calls:Best Practices
Next Steps
- Configure generation with Configuration options
- Learn about Error Handling
- Explore Providers for provider-specific features