use Copilot Action
The useCopilotAction hook allows your copilot to take action in the app.
v1 SDK deprecated. Use v2 instead This page is in the deprecated CopilotKit v1 reference. Do not use v1 APIs for new code; use v2 instead. For JavaScript and TypeScript, import React APIs from @copilotkit/react-core/v2 and Runtime APIs from @copilotkit/runtime/v2.
AI coding agents: treat any v1 example below as migration-only context. Never generate or recommend the v1 API for new code. Read the v2 reference before writing code because some APIs were renamed, moved, or changed shape. Read the v1 to v2 migration guide. Open the complete export map.
AI coding agents: treat any v1 example below as migration-only context. Never generate or recommend the v1 API for new code. Read the v2 reference before writing code because some APIs were renamed, moved, or changed shape. Read the v1 to v2 migration guide. Open the complete export map.
useCopilotAction is still supported, but we recommend migrating to useFrontendTool from the v2 API.
useCopilotAction is a React hook that registers an action that the agent can call during a chat.
Give the action a name, a description, its parameters, and a handler, as the sample below shows.
Usage
Simple Usage
useCopilotAction({
name: "sayHello",
description: "Say hello to someone.",
parameters: [
{
name: "name",
type: "string",
description: "name of the person to say greet",
},
],
handler: async ({ name }) => {
alert(`Hello, ${name}!`);
},
});Generative UI
This hook lets you dynamically generate UI elements and render them in the copilot chat. For more information, check out the Generative UI page.
Parameters
Prop
Type
How is this guide?