A2UI Launched: Full CopilotKit support at launch!

A2UI Launched: CopilotKit has partnered with Google to deliver full support in both CopilotKit and AG-UI!

Check it out
LogoLogo
  • Overview
  • Integrations
  • API Reference
  • Copilot Cloud
Slanted end borderSlanted end border
Slanted start borderSlanted start border
Select integration...

Please select an integration to view the sidebar content.

Frontend Tools

Learn how to enable your Copilot to execute tools in the frontend.

Let the Copilot Execute Tools

useFrontendTool

In addition to understanding state, you can empower the copilot to execute tools. Use the useFrontendTool hook to define specific tools that the copilot can execute based on user input.

YourComponent.tsx
"use client" // only necessary if you are using Next.js with the App Router.
import { useFrontendTool } from "@copilotkit/react-core"; 

export function MyComponent() {
  const [todos, setTodos] = useState<string[]>([]);

  // Define Frontend Tool
  useFrontendTool({
    name: "addTodoItem",
    description: "Add a new todo item to the list",
    parameters: [
      {
        name: "todoText",
        type: "string",
        description: "The text of the todo item to add",
        required: true,
      },
    ],
    handler: async ({ todoText }) => {
      setTodos([...todos, todoText]);
    },
  });

  return (
    <ul>
      {todos.map((todo, index) => (
        <li key={index}>{todo}</li>
      ))}
    </ul>
  );
}

Specify "use client" (Next.js App Router)

This is only necessary if you are using Next.js with the App Router.

YourComponent.tsx
"use client"

Like other React hooks such as useState and useEffect, this is a client-side hook. If you're using Next.js with the App Router, you'll need to add the "use client" directive at the top of any file using this hook.

Test it out!

After defining the tool, ask the copilot to execute it. For example, you can now ask the copilot to "add a todo item" with any text you want.

Example of Copilot action

Next Steps

useFrontendTool Reference

Refer to the documentation for the useFrontendTool hook.

Tools + Generative UI

Learn how to render custom UI components alongside your tools, directly in the CopilotKit chat window.

Backend Tools

Enable backend services to provide tools via copilot backend hooks.

PREV
Self Hosting (Copilot Runtime)
Slanted end borderSlanted end border
Slanted start borderSlanted start border
NEXT
Backend Actions & Agents

On this page

Let the Copilot Execute Tools
useFrontendTool
Test it out!
Next Steps
Specify "use client" (Next.js App Router)