docs/content/docs/(root)/frontend-actions.mdx
import { IntegrationGrid } from "@/components/content/integration-grid"; import { Tabs, Tab } from "fumadocs-ui/components/tabs";
Frontend actions let your AI agents directly interact with and update your application's UI. They bridge the gap between your agent's decision-making and your frontend's interactive elements.
<Tabs items={['page.tsx']}> <Tab value="page.tsx">
import { z } from "zod";
import { useFrontendTool } from "@copilotkit/react-core/v2";
useFrontendTool({
name: "setTheme",
description: "Switch the app's color theme",
parameters: z.object({
theme: z.enum(["light", "dark"]),
}),
handler: async ({ theme }) => {
document.documentElement.dataset.theme = theme;
return `Theme set to ${theme}!`;
},
});
Use frontend actions when your agent needs to: