CopilotKit + OpenAI Agents SDK

Bring your OpenAI Agents SDK agentsinto any app

CopilotKit is an open-source framework that connects your app to OpenAI Agents SDK 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

Build with OpenAI Agents SDK

The Agents SDK gives you the agent: a model, its tools, guardrails and handoffs, run in a loop. What it does not give you is the surface. Somewhere for the conversation to happen, a way to show the run while it is running, and a moment for a person to step in. Each capability below builds on something your agent already does.

Generative UI

Your function tools run on the server, and their calls stream to the browser while the model writes them. CopilotKit renders each one as a React component instead of leaving the user with a spinner.

Human-in-the-loop

Mark a tool `needs_approval=True` and the SDK pauses before it runs. CopilotKit shows the user the call, and their answer resumes the run with nothing kept on the server in between.

Shared state

The page's state reaches every run, and a tool that changes it streams the new value back before its own result. Your UI and your agent work on the same data.

Frontend tools, app context, state streaming, reasoning, attachments, A2UI and sub-agents work with the OpenAI Agents SDK too. And more

Start building

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

npx copilotkit@latest init --framework openai-agents-python
Read the quickstart

Connect your agent

Your agent keeps running as its own Python service, with the ag-ui-openai-agents adapter in front of it. CopilotKit reaches that service over HTTP, so nothing inside the agent changes.

app/api/copilotkit/route.ts
import { HttpAgent } from "@ag-ui/client";
import {
  CopilotRuntime,
  createCopilotRuntimeHandler,
} from "@copilotkit/runtime/v2";
import type { NextRequest } from "next/server";

const runtime = new CopilotRuntime({
  agents: {
    openai_agent: new HttpAgent({
      url: process.env.AGENT_URL ?? "http://localhost:8000/agent",
    }),
  },
});

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

export const POST = (req: NextRequest) => handler(req);
Read the setup guide

How is this guide?