Tambo Lockup

Message Threads

Understand how conversations are structured in Tambo.

Message threads are the core building block for creating interactive AI experiences with Tambo. They provide a structured way to manage conversations between users and Tambo, with hooks that make it easy to interact with thread state, send messages, and display responses. Each thread maintains a history of messages and can include both text content and rendered components, allowing for rich conversational interfaces where users can see both chat history and dynamic UI components.

const { thread } = useTambo()
const { value, setValue, submit } = useTamboThreadInput();

//send a message to Tambo under the current thread
const userMessage = "What is the weather like today?"
setValue(userMessage);
await submit({
  streamResponse: true, // We recommend streaming the response to the user
});

...

//render the thread's messages, which will include responses from Tambo
thread.messages.map((message) => (
<div>
  <p>Sent by: {message.role}</p>
  <p>message text: {message.content[0]?.text}</p>
  <p>component: {message.renderedComponent}</p>
</div>
))