docs/content/docs/reference/v2/hooks/useThreads.mdx
useThreads is a React hook for managing conversation threads on the Enterprise Intelligence Platform. It fetches the thread list for a given agent, keeps it synchronized in realtime via WebSocket, and exposes mutation methods for renaming, archiving, and deleting threads.
Threads are sorted by most recently updated first. The hook supports cursor-based pagination when a limit is provided.
<OpsPlatformCTA variant="card" title="useThreads needs an Enterprise Intelligence Platform project" body="Sign up for a free account to get a publicLicenseKey and start syncing threads." ctaLabel="Create a free account" surface="docs_reference_use_threads" />
import { useThreads } from "@copilotkit/react-core/v2";
function useThreads(input: UseThreadsInput): UseThreadsResult
import { useThreads } from "@copilotkit/react-core/v2"; // [!code highlight]
function ThreadList() {
const {
threads,
isLoading,
renameThread,
archiveThread,
deleteThread,
} = useThreads({ agentId: "my-agent" }); // [!code highlight]
if (isLoading) return <div>Loading threads...</div>;
return (
<ul>
{threads.map((thread) => (
<li key={thread.id}>
<span>{thread.name ?? "Untitled"}</span>
<button onClick={() => renameThread(thread.id, "New name")}>
Rename
</button>
<button onClick={() => archiveThread(thread.id)}>Archive</button>
<button onClick={() => deleteThread(thread.id)}>Delete</button>
</li>
))}
</ul>
);
}
error state updates with the most recent error from any operation.threads array stays sorted by updatedAt descending (most recent first).generateThreadNames on the runtime.