Messages form the backbone of communication in the AG-UI protocol. They
represent the conversation history between users and AI agents, and provide a
standardized way to exchange information regardless of the underlying AI service
being used.
AG-UI messages follow a vendor-neutral format, ensuring compatibility across
different AI providers while maintaining a consistent structure. This allows
applications to switch between AI services (like OpenAI, Anthropic, or custom
models) without changing the client-side implementation.The basic message structure includes:
Copy
Ask AI
interface BaseMessage { id: string // Unique identifier for the message role: string // The role of the sender (user, assistant, system, tool) content?: string // Optional text content of the message name?: string // Optional name of the sender}
interface AssistantMessage { id: string role: "assistant" content?: string // Text response from the assistant (optional if using tool calls) name?: string // Optional assistant identifier toolCalls?: ToolCall[] // Optional tool calls made by the assistant}
interface ToolMessage { id: string role: "tool" content: string // Result from the tool execution toolCallId: string // ID of the tool call this message responds to}
Tool calls are embedded within assistant messages:
Copy
Ask AI
interface ToolCall { id: string // Unique ID for this tool call type: "function" // Type of tool call function: { name: string // Name of the function to call arguments: string // JSON-encoded string of arguments }}
Example assistant message with tool calls:
Copy
Ask AI
{ id: "msg_123", role: "assistant", content: "I'll help you with that calculation.", toolCalls: [ { id: "call_456", type: "function", function: { name: "calculate", arguments: '{"expression": "24 * 7"}' } } ]}
Here’s a complete example of a conversation with tool usage:
Copy
Ask AI
// Conversation history;[ // User query { id: "msg_1", role: "user", content: "What's the weather in New York?", }, // Assistant response with tool call { id: "msg_2", role: "assistant", content: "Let me check the weather for you.", toolCalls: [ { id: "call_1", type: "function", function: { name: "get_weather", arguments: '{"location": "New York", "unit": "celsius"}', }, }, ], }, // Tool result { id: "result_1", role: "tool", content: '{"temperature": 22, "condition": "Partly Cloudy", "humidity": 65}', toolCallId: "call_1", }, // Assistant's final response using tool results { id: "msg_3", role: "assistant", content: "The weather in New York is partly cloudy with a temperature of 22°C and 65% humidity.", },]
The message structure in AG-UI enables sophisticated conversational AI
experiences while maintaining vendor neutrality. By standardizing how messages
are represented, synchronized, and streamed, AG-UI provides a consistent way to
implement interactive human-agent communication regardless of the underlying AI
service.This system supports everything from simple text exchanges to complex tool-based
workflows, all while optimizing for both real-time responsiveness and efficient
data transfer.