Skip to content

Function: useMastraThreads()

useMastraThreads(agentId?, enabled?): object

Fetch (and re-fetch) the caller’s conversation threads for an agent via client.threads(agentId). Drives the conversation list / sidebar so the user can switch between the threads they own. Newest first (updatedAt DESC), scoped server-side to the caller’s resource.

Returns a refresh() the chat driver calls after a turn completes (a new thread appears, or its auto-generated title lands) and after a clear / delete, so the list stays in sync without polling. Pass enabled: false to skip the fetch entirely (e.g. when the sidebar is hidden), in which case threads stays empty. A failed fetch degrades to an empty list - the conversation list is a non-critical enhancement layered over the always-available default thread.

string

boolean = true

object

error: Error | null

loading: boolean

refresh: () => void

void

threads: object[]