Search documentation

Browse Awaken Agents docs
Docs/Awaken Agentsv1.0.0-dev/Developer guide/Connect an applicationConnect a CopilotKit chat over AG-UI
Note·You're reading pre-release documentation (v1.0.0-dev). Interfaces and behavior may change before a stable release.

Developer guide · Connect an application

Connect a CopilotKit chat over AG-UI

What this page covers

Connect CopilotKit to Awaken with an AG-UI HttpAgent, verify one durable thread, and choose a production connection boundary.

Connect a CopilotKit v2 chat to an Awaken Agent through the AG-UI endpoint. Start with a direct local HttpAgent, send one task, and confirm that the same thread can be read from committed history before choosing the production path.

Goal

Finish with a CopilotKit chat that renders Awaken’s AG-UI event stream and uses one stable threadId. You will also know which component must own authentication when the browser connection moves beyond local development.

Prerequisites

  • Run awaken and complete self-hosting setup.
  • Publish a runnable model and, if needed, the Agent the chat will use.
  • Use a Node.js React project.
  • Decide whether this is a local direct connection or a production connection. CopilotKit gives those paths different configuration and security boundaries.

1. Choose the connection boundary

UseCopilotKit pathWhat it means
Local wiring and UI workagents__unsafe_dev_only with an AG-UI HttpAgentThe browser calls Awaken directly; do not ship this setting
Production direct connectionselfManagedAgents with a secured HttpAgentYour endpoint owns authentication and authorization; current CopilotKit documentation places this option in its Enterprise offering
Production runtime proxyruntimeUrl pointing to Copilot RuntimeCopilot Runtime discovers and proxies Agents; runtimeUrl does not point directly to Awaken’s /v1/ag-ui run endpoint

The next steps use the local path so you can verify the protocol without adding a second server.

2. Install CopilotKit and the AG-UI client

npm install @copilotkit/react-core@1 @ag-ui/client@0.0.58

The example uses CopilotKit’s v2 exports. Keep the versions selected by your application lockfile and review CopilotKit’s migration notes before changing its major API surface.

3. Register Awaken as a local HttpAgent

Use the default endpoint first, or replace the URL with /v1/ag-ui/agents/<agent_id> to select one published Agent:

"use client";

import { HttpAgent } from "@ag-ui/client";
import { CopilotChat, CopilotKit } from "@copilotkit/react-core/v2";

const awakenAgent = new HttpAgent({
  url: "http://localhost:8080/v1/ag-ui",
  threadId: "copilotkit-demo-1",
});

export default function App() {
  return (
    <CopilotKit
      agent="awaken"
      agents__unsafe_dev_only={{ awaken: awakenAgent }}
    >
      <CopilotChat agentId="awaken" />
    </CopilotKit>
  );
}

The registry key awaken is the ID CopilotKit components use. The endpoint path selects the Awaken Agent. The explicit threadId keeps subsequent runs on the same committed Session.

Do not replace agents__unsafe_dev_only with runtimeUrl=".../v1/ag-ui". runtimeUrl expects the Copilot Runtime API, including discovery behavior that a raw AG-UI run endpoint does not provide.

4. Verify

  1. Open the page and send a recognizable task, such as:

    List the two decisions in this note: choose an owner, then choose a deadline.
  2. Confirm CopilotChat renders the response as it arrives.

  3. Read the same thread from Awaken:

    curl -sS http://localhost:8080/v1/ag-ui/threads/copilotkit-demo-1/messages
  4. Confirm the returned items contain the submitted task and the committed Agent response.

An HttpAgent keeps messages in browser memory while the page is open. If the product must survive a refresh, load committed history before constructing the Agent and provide those messages as initialMessages.

5. Move to a production path

Before traffic reaches the endpoint:

  1. Choose Copilot Runtime proxying or the supported production selfManagedAgents path for your CopilotKit plan.
  2. Authenticate the caller and authorize the selected Workspace, Agent, and thread at the server boundary.
  3. If the browser calls Awaken directly, have your backend mint a short-lived application access token limited to ag-ui, the required thread operations, and the authorized Session binding. An application token may be sent as the HttpAgent bearer header; provider credentials and Workspace service keys may not.
  4. Terminate CORS and TLS at the owning ingress or same-origin application server.
  5. Re-run the task and committed-history check through the production URL.

Troubleshooting

If the table does not resolve the problem, record the selected connection path, package versions, route, HTTP status, thread ID, and correlation ID before contacting support. Remove tokens and message content first.

SymptomCheckAction
CopilotKit requests /info or reports a runtime connection failureThe raw AG-UI URL was passed as runtimeUrlFor local direct use, register an HttpAgent; otherwise point runtimeUrl at an actual Copilot Runtime
CopilotKit reports a missing runtime or keyThe local Agent map is absent or the v2 import is not in usePass agents__unsafe_dev_only={{ awaken: awakenAgent }} and use the /v2 exports shown above
The browser reports a CORS errorThe page and Awaken have different originsUse a same-origin proxy or configure the ingress CORS policy
A reload starts with no messagesOnly the in-memory HttpAgent state was usedFetch committed thread history and pass it as initialMessages
The run returns 404The server, port, or Agent-scoped path is wrongConfirm awaken is listening, then compare the route with the AG-UI reference

Next steps