Conversations

How to persist conversations and make them accessible to Agent Interface.

Every conversation with AgentInterface is stored through a storage adapter. Each message is persisted (its content, any extra context, and the complete response including text and tool calls), and AgentInterface reloads the threads and messages of the selected conversation automatically.

On OpenUI Cloud, useOpenuiCloudStorage is that adapter. Cloud stores and reloads every conversation, so you run no database and write no persistence logic.

This persistence lets users return to previous conversations, and the full history informs the agent's future responses.

What gets stored

  • Threads: the containers for a conversation. Each has an id, a title, and metadata like createdAt.
  • Messages: the turns inside a thread. Each has a role (user, assistant, or tool) and its content, including any generative UI or artifacts the assistant produced.
The sidebar thread list showing several saved conversations, illustrating persisted history

Accessing conversations

To build your own thread switcher or history view, read the data with hooks instead of touching storage. useThread selects from the current thread; useThreadList selects from all threads.

import { useThread, useThreadList } from "@openuidev/react-ui";

function ChatCount() {
  const count = useThreadList((s) => s.threads.length);
  return <span>{count} chats</span>;
}

Both are selector hooks: pass a function that picks the slice you need, and the component re-renders only when that slice changes. They work anywhere inside AgentInterface. See Hooks for the full state.

Self-hosted: the scaffold stores conversations in a local store it generates. To use your own database, implement the storage contract. See Adapters & formats.

On this page