Overview
Message types define the structure of messages in a thread. Messages use an Anthropic-style content blocks pattern where each message contains an array of content blocks (text, tool calls, tool results, components).
TamboThreadMessage
Represents a single message in a thread.
import type { TamboThreadMessage } from '@tambo-ai/react';
Definition
interface TamboThreadMessage {
/** Unique message identifier */
id: string;
/** Message role (user, assistant, or system) */
role: MessageRole;
/** Content blocks in the message */
content: Content[];
/** When the message was created (ISO 8601 timestamp) */
createdAt?: string;
/** Message metadata */
metadata?: Record<string, unknown>;
/**
* The id of the parent message, if this message was created during
* generation of another message (e.g., MCP sampling or elicitation).
*/
parentMessageId?: string;
/**
* Reasoning content from the model (transient - only during streaming).
* Each element is a reasoning "chunk" - models may emit multiple reasoning blocks.
* This data is not persisted and will not be present in messages loaded from the API.
*/
reasoning?: string[];
/**
* Duration of the reasoning phase in milliseconds (for display purposes).
* Populated when reasoning completes.
*/
reasoningDurationMS?: number;
}
Fields
Unique identifier for the message.
The message role. See MessageRole.
"user" - Message from the user
"assistant" - Message from the AI
"system" - System message (when loading from API)
Array of content blocks. See Content Types.A message can contain multiple content blocks of different types:
- Text blocks
- Tool use blocks (tool calls)
- Tool result blocks (tool responses)
- Component blocks (rendered UI)
- Resource blocks (attached files/data)
ISO 8601 timestamp when the message was created. Optional for historical messages loaded from API.createdAt: '2024-03-15T10:30:00Z'
Custom metadata associated with the message.metadata: {
sourceType: 'voice',
language: 'en-US'
}
ID of the parent message if this message was created during generation of another message (e.g., MCP sampling or elicitation).
Reasoning content from the model. Only present during streaming and not persisted to the database.Models may emit multiple reasoning blocks, so this is an array of strings.reasoning: [
'Let me think about this step by step...',
'First, I need to check the weather data...'
]
Duration of the reasoning phase in milliseconds. Populated when reasoning completes.reasoningDurationMS: 1234
MessageRole
The role/author of a message.
import type { MessageRole } from '@tambo-ai/react';
type MessageRole = "user" | "assistant" | "system";
Values
Message from the user/human.
Message from the AI assistant.
System message. Included to accommodate messages loaded from the API.
Content Types
Union type of all content block types.
import type { Content } from '@tambo-ai/react';
type Content =
| TextContent
| TamboToolUseContent
| ToolResultContent
| TamboComponentContent
| ResourceContent;
TextContent
A text content block.
import type { TextContent } from '@tambo-ai/react';
interface TextContent {
type: 'text';
text: string;
}
Discriminator for the content block type.
The text content.{ type: 'text', text: 'Hello, how can I help you?' }
TamboToolUseContent
A tool call (tool use) content block. Extended from the SDK with computed state properties.
import type { TamboToolUseContent } from '@tambo-ai/react';
interface TamboToolUseContent {
type: 'tool_use';
id: string;
name: string;
input: Record<string, unknown>;
// Computed properties (populated by useTambo() hook)
hasCompleted?: boolean;
statusMessage?: string;
tamboDisplayProps?: TamboToolDisplayProps;
}
Discriminator for the content block type.
Unique identifier for this tool call.
Name of the tool being called.
input
Record<string, unknown>
required
Tool input parameters with internal _tambo_* properties removed. Consumers see only the actual tool parameters.
Whether this tool call has completed (has a matching tool_result). Computed by useTambo().
The status message to display, resolved based on tool execution state. Computed by useTambo().
ToolResultContent
A tool result content block (response from a tool call).
import type { ToolResultContent } from '@tambo-ai/react';
interface ToolResultContent {
type: 'tool_result';
tool_use_id: string;
content: string | Array<{ type: string; [key: string]: unknown }>;
is_error?: boolean;
}
Discriminator for the content block type.
ID of the tool_use block this result corresponds to.
content
string | Array<...>
required
The tool result content. Can be a string or an array of content parts.
Whether this result represents an error.
TamboComponentContent
A component content block. Extended from the SDK with streaming state.
import type { TamboComponentContent } from '@tambo-ai/react';
interface TamboComponentContent {
type: 'component';
id: string;
name: string;
props?: Record<string, unknown>;
state?: Record<string, unknown>;
streamingState?: ComponentStreamingState;
}
Discriminator for the content block type.
Unique identifier for this component instance.
Name of the component to render.
Component props provided by the AI.
Component state (can be updated by AI or client).
ResourceContent
A resource content block (attached files/data).
import type { ResourceContent } from '@tambo-ai/react';
interface ResourceContent {
type: 'resource';
resource: {
type: string;
resource: {
uri: string;
mimeType?: string;
text?: string;
blob?: string;
};
};
}
Discriminator for the content block type.
The resource data including URI, MIME type, and content.
ComponentStreamingState
Streaming state for component content blocks.
import type { ComponentStreamingState } from '@tambo-ai/react';
type ComponentStreamingState = "started" | "streaming" | "done";
Values
Component block created, awaiting props.
Props are being streamed.
Props streaming complete. Default for historical messages loaded from API.
Special display properties that can be included in tool input to customize status messages.
import type { TamboToolDisplayProps } from '@tambo-ai/react';
interface TamboToolDisplayProps {
/** Message shown while the tool is executing */
_tambo_statusMessage?: string;
/** Message shown after the tool completes */
_tambo_completionStatusMessage?: string;
}
Custom message displayed while the tool is executing._tambo_statusMessage: 'Fetching weather data...'
_tambo_completionStatusMessage
Custom message displayed after the tool completes._tambo_completionStatusMessage: 'Weather data retrieved'
Types for sending messages to the AI.
Standard message format for user input.
import type { InputMessage } from '@tambo-ai/react';
interface InputMessage {
role: 'user';
content: string | Array<{ type: string; [key: string]: unknown }>;
}
Message type for initial messages that seed a new thread. Supports system and assistant roles in addition to user.
import type { InitialInputMessage } from '@tambo-ai/react';
interface InitialInputMessage {
role: 'user' | 'assistant' | 'system';
content: string | Array<TextContent | ResourceContent>;
}
Initial messages can only contain text and resource blocks, not tool results.
API Response Types
Types returned by the Tambo API for message operations.
MessageListResponse
Response when listing messages in a thread.
import type { MessageListResponse } from '@tambo-ai/react';
MessageGetResponse
Response when fetching a specific message.
import type { MessageGetResponse } from '@tambo-ai/react';
These types are re-exported from @tambo-ai/typescript-sdk. Refer to the SDK documentation for detailed field definitions.
Usage Examples
Rendering Messages
import { useTambo } from '@tambo-ai/react';
import type { TamboThreadMessage, Content } from '@tambo-ai/react';
function MessageList() {
const { messages } = useTambo();
return (
<div>
{messages.map((message: TamboThreadMessage) => (
<div key={message.id} className={`message-${message.role}`}>
{message.content.map((block: Content, idx: number) => (
<ContentBlock key={idx} block={block} />
))}
</div>
))}
</div>
);
}
Rendering Content Blocks
import type { Content } from '@tambo-ai/react';
function ContentBlock({ block }: { block: Content }) {
switch (block.type) {
case 'text':
return <p>{block.text}</p>;
case 'component':
return <ComponentRenderer content={block} />;
case 'tool_use':
return (
<div className="tool-call">
Calling tool: {block.name}
{block.statusMessage && <span>{block.statusMessage}</span>}
</div>
);
case 'tool_result':
return (
<div className="tool-result">
{typeof block.content === 'string' ? block.content : JSON.stringify(block.content)}
</div>
);
default:
return null;
}
}
Handling Reasoning
import type { TamboThreadMessage } from '@tambo-ai/react';
function MessageWithReasoning({ message }: { message: TamboThreadMessage }) {
return (
<div>
{message.reasoning && message.reasoning.length > 0 && (
<div className="reasoning">
<h4>Reasoning:</h4>
{message.reasoning.map((chunk, idx) => (
<p key={idx}>{chunk}</p>
))}
{message.reasoningDurationMS && (
<span className="duration">
Took {message.reasoningDurationMS}ms
</span>
)}
</div>
)}
{/* Render content blocks */}
{message.content.map((block, idx) => (
<ContentBlock key={idx} block={block} />
))}
</div>
);
}
Sending Messages
import { useTamboThreadInput } from '@tambo-ai/react';
import type { InputMessage } from '@tambo-ai/react';
function ChatInput() {
const { value, setValue, submit } = useTamboThreadInput();
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
await submit({
message: value,
metadata: {
source: 'chat-input',
timestamp: Date.now()
}
});
};
return (
<form onSubmit={handleSubmit}>
<input
value={value}
onChange={(e) => setValue(e.target.value)}
placeholder="Type a message..."
/>
<button type="submit">Send</button>
</form>
);
}
Type Imports
import type {
TamboThreadMessage,
MessageRole,
Content,
TextContent,
TamboToolUseContent,
ToolResultContent,
TamboComponentContent,
ResourceContent,
ComponentStreamingState,
TamboToolDisplayProps,
InputMessage,
InitialInputMessage,
MessageListResponse,
MessageGetResponse,
} from '@tambo-ai/react';
See Also