--- title: "CopilotChat" description: "High-level chat component that connects an agent to a chat view" --- ## Overview `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 ```tsx import { CopilotChat } from "@copilotkit/react-core/v2"; import "@copilotkit/react-core/v2/styles.css"; ``` ## Props ### Own Props ID of the agent to use. Must match an agent configured in `CopilotKit`. Defaults to the provider-level default agent when omitted. ID of the conversation thread. Pass a specific thread ID to resume an existing conversation or let the agent create a new one. Partial label overrides for all text strings rendered inside the chat (input placeholder, toolbar buttons, disclaimer text, etc.). Any label you omit falls back to the built-in default. Slot override for the inner `CopilotChatView` component. Accepts a replacement component, a `className` string merged into the default, or a partial props object to extend the default. Error handler scoped to this chat's agent. Fires in addition to the provider-level `onError` (does not suppress it). Only receives errors whose `context.agentId` matches this chat's agent, plus errors without an `agentId` context. ```tsx { if (event.code === "agent_connect_failed") { showToast("Could not connect to agent. Please retry."); } }} /> ``` When used inside `CopilotPopup` or `CopilotSidebar`, controls whether the modal starts in the open state. Stored in the chat configuration context so child components can read it. ### Inherited CopilotChatView Props `CopilotChat` accepts all props from [`CopilotChatViewProps`](/reference/components/CopilotChatView) **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`. Whether the chat scrolls to the bottom automatically when new messages arrive. Additional props forwarded to the inner `CopilotChatInput` component. Use this to configure auto-focus, custom submission handlers, transcription callbacks, or tools menus. 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. ## Slot System 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. ## Usage ### Basic Usage ```tsx function App() { return ( ); } ``` ### Custom Welcome Screen ```tsx function App() { return ( (

Welcome to the assistant

{suggestionView} {input}
)} /> ); } ``` ### Overriding the Chat View Slot ```tsx function App() { return ( ); } ``` ## Behavior - **Agent wiring**: On mount, `CopilotChat` calls `useAgent` with the provided `agentId` and binds the agent's `messages`, `isRunning`, and suggestion state to `CopilotChatView`. - **Initial run**: If the agent has not been run yet, `CopilotChat` triggers `runAgent` automatically so the agent can send an initial greeting or set up state. - **Auto-clear input**: After a message is submitted, the input field is cleared automatically. - **Configuration context**: Wraps children in `CopilotChatConfigurationProvider`, making `labels`, `agentId`, `threadId`, and modal state available to all descendant components via `useCopilotChatConfiguration`. - **Suggestion management**: Subscribes to the agent's suggestion system and passes suggestions, loading states, and selection callbacks down to `CopilotChatView`. ## Related - [`CopilotChatView`](/reference/components/CopilotChatView) -- the layout component used internally - [`CopilotPopup`](/reference/components/CopilotPopup) -- popup variant of `CopilotChat` - [`CopilotSidebar`](/reference/components/CopilotSidebar) -- sidebar variant of `CopilotChat` - [`useAgent`](/reference/hooks/useAgent) -- hook used internally to access the agent