CopilotKit + AG2

Bring your AG2 agentsinto any app

CopilotKit is an open-source framework that connects your app to AG2 agents. Give your agents chat, generative UI, human-in-the-loop, AG-UI Streams, Automatic Learning and more.

Quickstart
Chat

Waking up the demo

Talk to your agent in a ready-made chat interface. Open in the showcase

AG2 and CopilotKit running together, in the React frontend. Every demo below is the same integration with one capability turned on.

Build with AG2

AG2 gives you the conversation between your agents: roles, turns and the tools they call. What it does not give you is the surface a person joins it through. Each capability below builds on something your agents already do.

Generative UI

Your agents call tools as the conversation runs. CopilotKit streams those calls to the browser and renders each one as a React component, instead of leaving the user with a spinner.

Human-in-the-loop

A frontend tool registered with useHumanInTheLoop renders your own UI, waits for the user's answer, and hands it back to the agent as the tool result.

Shared state

Your agents carry state across turns. CopilotKit mirrors it into your app and back, so changes from the user and the agent go to the same state.

Chat surfaces, headless UI, frontend tools and multi-agent flows work with AG2 too. And more

Start building

Scaffold a new app with the CLI, or follow the quickstart to connect the AG2 agent you already run.

npx copilotkit@latest init
Read the quickstart

Connect your agent

Your agents keep running as their own Python service, with AGUIStream from ag2.ag_ui in front of them. CopilotKit reaches that service over HTTP, so nothing inside AG2 changes.

app/api/copilotkit/[[...slug]]/route.ts
import {
  CopilotRuntime,
  createCopilotRuntimeHandler,
} from "@copilotkit/runtime/v2";
import { HttpAgent } from "@ag-ui/client";

const runtime = new CopilotRuntime({
  agents: {
    my_agent: new HttpAgent({ url: process.env.AGENT_URL! }),
  },
});

const handler = createCopilotRuntimeHandler({
  runtime,
  basePath: "/api/copilotkit",
});

export const GET = handler;
export const POST = handler;
Read the setup guide

How is this guide?