Angular
Connect an Angular app to Copilot Runtime with CopilotKit.
@copilotkit/angular provides Angular components, directives, and services for CopilotKit. This guide gets you to a working Angular app with a 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.
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.This runs in a coding agent on your computer.
What is CopilotKit for Angular?#
CopilotKit for Angular is the first-party, signal-based Angular frontend for AG-UI agents and Copilot Runtime. It provides complete chat surfaces and headless APIs, and it supports zoneless applications.
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-appInstall CopilotKit#
Install the Angular frontend package, @angular/cdk, and @copilotkit/runtime for your local Copilot Runtime server:
npm install @copilotkit/angular @angular/cdk @copilotkit/runtime
npm install -D tsx typescript @types/nodepnpm add @copilotkit/angular @angular/cdk @copilotkit/runtime
pnpm add -D tsx typescript @types/nodeyarn add @copilotkit/angular @angular/cdk @copilotkit/runtime
yarn add -D tsx typescript @types/nodeMatch @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).
Connect the selected agent backend#
This URL keeps the agent backend selected. The Angular setup remains shared; the backend setup below comes from that integration's canonical showcase source.
An OpenAI Agents SDK agent is a plain Agent from agents: a name,
instructions, a model and its tools. The AG-UI adapter, ag_ui_openai_agents,
wraps it in an OpenAIAgentsAgent. The wrapper turns each AG-UI request into
a streamed SDK run and streams the SDK's events back as AG-UI events.
The model calls go through the SDK's default OpenAI client, so the usual
OPENAI_API_KEY and OPENAI_BASE_URL apply. The showcase registers one
AsyncOpenAI client for the whole process. It points that client at aimock
and copies the test headers of the current request onto every model call:
async def _forward_request_headers(request: httpx.Request) -> None:
"""Copies the current request's mock/diagnostic headers onto a model call.
``x-aimock-context`` is fixed to this package's slug so aimock picks this
package's fixtures whatever the inbound request carried. The rest is
forwarded only when present, so ordinary demo traffic is never forced
into strict mode.
"""
for key, value in get_forwarded_headers().items():
if key.startswith(_FORWARDED_PREFIXES):
request.headers[key] = value
request.headers["x-aimock-context"] = SLUG
_CLIENT: AsyncOpenAI | None = None
def openai_client() -> AsyncOpenAI:
"""The process-wide client every model call goes through."""
global _CLIENT
if _CLIENT is None:
_CLIENT = AsyncOpenAI(
http_client=httpx.AsyncClient(
timeout=httpx.Timeout(120.0, connect=10.0),
event_hooks={"request": [_forward_request_headers]},
)
)
return _CLIENT
def configure_sdk() -> None:
"""Points the Agents SDK at ``openai_client()``. Call once at startup.
Tracing is off unless OPENAI_AGENTS_TRACING=1: traces go to the OpenAI
platform, which the mock key and the aimock base URL cannot reach.
"""
set_default_openai_client(openai_client(), use_for_tracing=False)
if os.environ.get("OPENAI_AGENTS_TRACING") != "1":
set_tracing_disabled(True)
async def close_client() -> None:
global _CLIENT
client, _CLIENT = _CLIENT, None
if client is not None:
await client.close()
Nothing about CopilotKit is configured on the agent itself. On every run the wrapper:
- adds the tools the page registered to a per-request copy of the agent, as tools the browser answers;
- appends the page's
useAgentContextentries to the instructions; - makes the run's AG-UI state readable and writable through
shared_state().
The shared Agent is never changed, so one agent can serve many requests at
once.
add_openai_agents_fastapi_endpoint mounts one wrapped agent as an AG-UI
endpoint on a FastAPI app. The showcase keeps its OpenAIAgentsAgents in a
{name: agent} mapping and mounts each one at /<name>:
app = FastAPI(title="OpenAI Agents SDK Agent Server", lifespan=lifespan)
for name, agent in AGENTS.items():
add_openai_agents_fastapi_endpoint(app, agent, f"/{name}", include_health=False)Then point Copilot Runtime at http://localhost:8000/<agent name>.
Install the SDK
pip install ag-ui-openai-agents openai-agentsExpose the selected backend through Copilot Runtime
Configure Copilot Runtime to register this backend as the default
agent at /api/copilotkit. Continue with the selected backend's
Copilot Runtime guide for its runtime
adapter, credentials, and server command. Do not replace it with the
BuiltInAgent server from the standalone Angular path.
Import the styles#
Add the package stylesheet to your global styles. It's self-contained, so the chat renders without any other 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.
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.
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 backend, runtime, and Angular app#
Start the selected agent backend and Copilot Runtime with the commands
from its runtime guide. Confirm
http://localhost:8200/api/copilotkit/info reports the default
agent, then start Angular:
npm startOpen the Angular CLI URL (usually http://localhost:4200) and send a
message. The request now follows the selected path end to end:
Angular → Copilot Runtime → your selected agent backend.
Open Inspector and confirm setup#
On localhost, click the Inspector button in the corner of the app.
- Open Agents, then Agent. Your agent is listed.
- Send a chat message. Open Agents, then AG-UI Events. Events are moving.
- Open Rich Threads. The list is unlocked (Intelligence is on), or locked with Enable Intelligence (Intelligence is off).
More detail: Inspector.
Next steps#
- Runtime and backend docs: configure the server, secure requests, and deploy without leaving the selected Angular surface.
- CopilotKit Intelligence: add threads, inspection, and cloud-hosted or self-hosted operations.
- Angular task guides: build chat UI, tools, generative UI, interrupts, shared state, threads, memory, attachments, and headless UI.
- Angular feature examples: find runnable examples and canonical shared Angular source for each supported feature.
- Angular API reference: use components, signals, tools, context, and runtime services.
- Production and lifecycle: handle cleanup, errors, server rendering, hydration, zoneless Angular, and browser-only features.