showcase/shell-docs/src/content/reference/components/CopilotChat.mdx
CopilotChat is a high-level chat container that wires an agent into CopilotChatView while providing configuration context. It obtains the agent via useAgent, triggers an initial runAgent when mounting CopilotKit agents, manages pending state, and auto-clears the input after submission. Override any of the internal slots by passing CopilotChatView props directly.
CopilotChat manages messages, running state, and suggestions automatically -- you only need to specify which agent to connect and, optionally, customise labels or slot overrides.
import { CopilotChat } from "@copilotkit/react-core/v2";
import "@copilotkit/react-core/v2/styles.css";
<CopilotChat
agentId="my-agent"
onError={(event) => {
if (event.code === "agent_connect_failed") {
showToast("Could not connect to agent. Please retry.");
}
}}
/>
CopilotChat accepts all props from CopilotChatViewProps except messages, isRunning, suggestions, suggestionLoadingIndexes, and onSelectSuggestion, which are managed internally by the agent connection.
This means you can pass slot overrides such as messageView, input, scrollView, inputContainer, feather, disclaimer, suggestionView, and welcomeScreen directly to CopilotChat.
<PropertyReference name="inputProps" type="Partial<Omit<CopilotChatInputProps, 'children'>>"
Additional props forwarded to the inner CopilotChatInput component. Use this
to configure auto-focus, custom submission handlers, transcription callbacks,
or tools menus.
</PropertyReference>
<PropertyReference name="welcomeScreen" type="SlotValue<React.FC<WelcomeScreenProps>> | boolean"
Controls the welcome screen shown when no messages exist. Pass true for the
default, false to disable, a className to style the default, or a
replacement component.
</PropertyReference>
All slot props inherited from CopilotChatView follow the same override pattern. Each slot accepts one of three value types:
| Value | Behavior |
|---|---|
| Component | Replaces the default component entirely. Receives the same props the default would. |
className string | Merged into the default component's class list via twMerge. |
| Partial props object | Spread into the default component as additional or overriding props. |
Additionally, a children render-prop can be used to receive all composed slot elements and arrange them in a custom layout.
function App() {
return (
<CopilotChat
agentId="my-agent"
labels={{ chatInputPlaceholder: "Ask me anything..." }}
/>
);
}
function App() {
return (
<CopilotChat
agentId="my-agent"
welcomeScreen={({ input, suggestionView }) => (
<div className="flex flex-col items-center justify-center h-full gap-4">
<h2>Welcome to the assistant</h2>
{suggestionView}
{input}
</div>
)}
/>
);
}
function App() {
return (
<CopilotChat
agentId="my-agent"
chatView="bg-gray-50 rounded-xl shadow-lg"
/>
);
}
CopilotChat calls useAgent with the provided agentId and binds the agent's messages, isRunning, and suggestion state to CopilotChatView.CopilotChat triggers runAgent automatically so the agent can send an initial greeting or set up state.CopilotChatConfigurationProvider, making labels, agentId, threadId, and modal state available to all descendant components via useCopilotChatConfiguration.CopilotChatView.CopilotChatView -- the layout component used internallyCopilotPopup -- popup variant of CopilotChatCopilotSidebar -- sidebar variant of CopilotChatuseAgent -- hook used internally to access the agent