Angular

Connect an Angular app to Copilot Runtime with CopilotKit.

This guide takes an Angular app to a working chat UI backed by Copilot Runtime. When you select an agent backend in the sidebar, the backend step below changes with it. Without a selection, the guide uses CopilotKit's BuiltInAgent.

The runtime runs on your server, keeps model credentials out of the browser, and exposes the default agent that CopilotChat uses automatically.

Take your Angular copilot from local to productionAdd threads, inspection, and cloud-hosted or self-hosted CopilotKit Intelligence without changing the Angular frontend APIs in this guide.Get CopilotKit Intelligence free

Start with your coding agent

Use this prompt to connect your Angular app to Copilot Runtime with the selected agent backend, then verify a working conversation. You can also follow the manual steps below.

Open your coding agent in your project's folder, or in an empty folder for a new app.

Prerequisites

  • An OpenAI API key (or another model provider supported by Model Selection)
  • Angular 22
  • Node.js 22

Getting started

Create your Angular app

If you don't have one already, pin the CLI to the supported major:

npx @angular/cli@22 new my-copilot-app
cd my-copilot-app

Install CopilotKit

@copilotkit/angular gives you Angular components, directives, and services for CopilotKit. It supports zoneless applications. Install it with @angular/cdk, and install @copilotkit/runtime for your local Copilot Runtime server:

npm install @copilotkit/angular @angular/cdk @copilotkit/runtime
npm install -D tsx typescript @types/node
Match @angular/cdk to your Angular version

@angular/cdk must share your Angular major version. Most package managers resolve this for you, but if you hit a peer-dependency error, pin it explicitly (for example @angular/cdk@^22).

Create the Copilot Runtime

Add a small Node server that hosts Copilot Runtime at /api/copilotkit and registers a default built-in agent:

server.ts
import { createServer } from "node:http";
import { BuiltInAgent, CopilotRuntime } from "@copilotkit/runtime/v2";
import { createCopilotNodeListener } from "@copilotkit/runtime/v2/node";

const runtime = new CopilotRuntime({
  agents: {
    default: new BuiltInAgent({
      model: "openai:gpt-6-luna",
      prompt: "You are a helpful assistant for an Angular app.",
    }),
  },
});

const port = Number(process.env['PORT'] ?? 8200);

createServer(
  createCopilotNodeListener({
    runtime,
    basePath: "/api/copilotkit",
    cors: true,
  }),
).listen(port, () => {
  console.log(
    `Copilot Runtime listening at http://localhost:${port}/api/copilotkit`,
  );
});
Angular runs the runtime as its own process

Copilot Runtime runs as its own process, so runtimeUrl is an absolute URL. To use another port, run PORT=8250 npx tsx server.ts and set runtimeUrl to match.

Import the styles

Add the package stylesheet to your global styles. It's self-contained, so the chat renders without any other CSS.

src/styles.css
@import "@copilotkit/angular/styles.css";

Connect to Copilot Runtime

Point provideCopilotKit at the runtime endpoint. The chat uses the agent that your runtime registers as default.

src/app/app.config.ts
import { ApplicationConfig } from "@angular/core";
import { provideCopilotKit } from "@copilotkit/angular";

export const appConfig: ApplicationConfig = {
  providers: [
    provideCopilotKit({
      runtimeUrl: "http://localhost:8200/api/copilotkit",
    }),
  ],
};

Add the chat UI

Import the CopilotChat component into your root component and drop it into the template.

src/app/app.ts
import { Component } from "@angular/core";
import { CopilotChat } from "@copilotkit/angular";

@Component({
  selector: "app-root",
  imports: [CopilotChat],
  template: `
    <div style="height: 100vh">
      <copilot-chat />
    </div>
  `,
})
export class App {}

Run the runtime and app

Start Copilot Runtime in one terminal:

export OPENAI_API_KEY=sk-...
npx tsx server.ts

Start the Angular app in another terminal:

npm start

Open the dev server URL (the Angular CLI prints it, usually http://localhost:4200), send a message, and you'll see it stream back through Copilot Runtime.

Open Inspector and confirm setup

On localhost, click the Inspector button in the corner of the app.

  1. Open Inspect, then Agent. Your agent is listed.
  2. Send a chat message. Open Inspect, then AG-UI Events. Events are moving.
  3. Open Rich Threads. The list is unlocked (Intelligence is on), or locked with Copy setup prompt (Intelligence is off).

More detail: Inspector.

Next steps

  1. Prebuilt Components: choose a chat surface, then follow the sidebar to frontend tools, generative UI, human-in-the-loop, shared state, threads, attachments, and headless UI.
  2. Runtime and backend docs: configure the server, secure requests, and deploy without leaving the selected Angular surface.

Later:

How is this guide?