showcase/shell-docs/src/content/reference/v1/hooks/useCopilotChat.mdx
{ /*
useCopilotChat is a lightweight React hook for headless chat interactions.
Perfect for controlling the prebuilt chat components programmatically.Open Source Friendly - Works without requiring a free public license key.
<Callout title="Looking for fully headless UI?"> Get started with [useCopilotChatHeadless_c](https://docs.copilotkit.ai/reference/v1/hooks/useCopilotChatHeadless_c). </Callout>import { TextMessage, MessageRole } from "@copilotkit/runtime-client-gql";
const { appendMessage } = useCopilotChat();
// Example usage without naming conflicts
const handleSendMessage = async (content: string) => {
await appendMessage(
new TextMessage({
role: MessageRole.User,
content,
})
);
};
The following properties are returned from the hook:
<PropertyReference name="visibleMessages" type="DeprecatedGqlMessage[]" deprecated> Array of messages in old non-AG-UI format, use for compatibility only </PropertyReference> <PropertyReference name="appendMessage" type="(message: DeprecatedGqlMessage, options?) => Promise<void>" deprecated> Append message using old format, use `sendMessage` instead </PropertyReference> <PropertyReference name="reloadMessages" type="(messageId: string) => Promise<void>"> Regenerate the response for a specific message by ID </PropertyReference> <PropertyReference name="stopGeneration" type="() => void"> Stop the current message generation process </PropertyReference> <PropertyReference name="reset" type="() => void"> Clear all messages and reset chat state completely </PropertyReference> <PropertyReference name="isLoading" type="boolean"> Whether the chat is currently generating a response </PropertyReference> <PropertyReference name="runChatCompletion" type="() => Promise<Message[]>"> Manually trigger chat completion for advanced usage </PropertyReference> <PropertyReference name="mcpServers" type="MCPServerConfig[]"> Array of Model Context Protocol server configurations </PropertyReference> <PropertyReference name="setMcpServers" type="(servers: MCPServerConfig[]) => void"> Update MCP server configurations for enhanced context </PropertyReference>auto (default) - Suggestions are generated automatically:
- When the chat is first opened (empty state)
- After each message exchange completes
- Uses configuration from useCopilotChatSuggestions hooks
manual - Suggestions are controlled programmatically:
- Use setSuggestions() to set custom suggestions
- Use generateSuggestions() to trigger AI generation
- Access via useCopilotChat hook
SuggestionItem[] - Static suggestions array:
- Always shows the same suggestions
- No AI generation involved
</PropertyReference>