Runtime Layer
assistant-ui components are full stack components. This means that they include both the UI presentation, but also logic to communicate with an external system. This logic is handled by the runtime layer and APIs.
You interact with the runtime layer in two ways:
- defining a runtime for your app
- using the runtime APIs to interact with the runtime
Defining a runtime
assistant-ui ships with two low-level runtimes:
useLocalRuntime
useExternalStoreRuntime
Both of these runtimes let you implement your own runtime. The conceptual difference between the two is that useLocalRuntime
takes ownership of the data layer, while useExternalStoreRuntime
does not.
If you have a stateful API to integrate, use useExternalStoreRuntime
, if you have a stateless API to integrate, use useLocalRuntime
.
Higher level runtimes
For many services and APIs, assistant-ui provides deeper integrations. These are built with the two low-level runtimes mentioned above.
useEdgeRuntime
: Connect to Vercel AI SDK backends or Edge Runtime backendsuseVercelUseChatRuntime
: Integrate with Vercel AI SDK'suseChat
hookuseVercelUseAssistantRuntime
: Integrate with Vercel AI SDK'suseAssistant
hook (OpenAI Assistants API)useVercelRSCRuntime
: Integrate with Vercel AI SDK React Server ComponentsuseLangGraphRuntime
: Connect to LangGraph ClouduseTrieveRuntime
: Connect to Trieve.ai- ...
Runtime Providers
The following components accept a runtime
prop:
AssistantRuntimeProvider
Thread
These components put the Runtime in the React Context, so that all child components can access the runtime.
Runtime Adapters
Most runtimes accept additional adapters to configure extra integrations:
- ChatModelAdapter: Configures the backend API
- AttachmentAdapter: Configures the file/media attachment API
- SpeechSynthesisAdapter: Configures the speech API
- FeedbackAdapter: Configures the feedback API
Using the runtime APIs
The same API used by the assistant-ui components is also available to you. This allows you to build your own UI components and integrate them with the runtime layer.
Runtime Hierarchy
The runtime API is nested as such:
The AssistantRuntime (which encompasses everything), is sometimes simply called Runtime
.
Runtime Context Provider Components
The following components provide the runtime APIs:
Accessing runtime APIs
You can access the runtime APIs with react hooks:
Accessing runtime state
Most runtimes also expose a state through two methods getState
and subscribe
. The following helper hooks subscribe to the state, so that your component is updated when the state changes:
You might not want to subscribe to evey update. In that case, pass a callback selector to the hook: