CopilotKit

Framework

CopilotKit/CopilotKit

Full-stack SDK for building agentic applications with generative UI.

Overview

CopilotKit is an open-source SDK for building agent-native applications with generative UI, shared state, and human-in-the-loop workflows. It supports React, Angular, Vue, and React Native, enabling agents to dynamically render UI components.

README Preview

\n\n\n\n# CopilotKit\n\n\n\n[Docs](https://docs.copilotkit.ai/?ref=github_readme) ·\n[Examples](https://www.copilotkit.ai/examples) ·\n[Enterprise Intelligence Platform](https://go.copilotkit.ai/enterprise-intelligence-platform) ·\n[Discord](https://discord.gg/6dffbvGU3D?ref=github_readme)\n\n\n\nBuild **agent-native applications** — on any framework, on any surface.\n\nGenerative UI, shared state, and human-in-the-loop workflows for React, Angular, Vue, React Native — and beyond the browser.\n\n\n\n[](https://go.copilotkit.ai/copilotkit-docs)\n\n\n  \n    \n  \n\n  \n    \n  \n\n  \n    \n  \n  \n  \n  \n    \n  \n\n\n  \n      \n    \n    \n      \n    \n\n  \n\n---\n\n## What is CopilotKit\n\nCopilotKit is a best-in-class SDK for building full-stack agentic applications, Generative UI, and chat applications.\n\nWhat started as a React library is now a **multi-platform agentic framework**: the same agent can power your web app, your mobile app, and your team's Slack workspace.\n\nWe are the company behind the **[AG-UI Protocol](https://github.com/ag-ui-protocol/ag-ui)** - adopted by Google, LangChain, AWS, Microsoft, Mastra, PydanticAI, and more!\n\nhttps://github.com/user-attachments/assets/72b7b4f3-b6e7-460c-a932-5746fe3c8db3\n\n Add AI to your app in 1 minute\n\n**Features:**\n\n- **Chat UI** – A fully customizable chat interface that supports message streaming, tool calls, and agent responses.\n- **Backend Tool Rendering** – Enables agents to call backend tools that return UI components rendered directly in the client.\n- **Generative UI** – Allows agents to generate and update UI components dynamically at runtime based on user intent and agent state.\n- **Shared State** – A synchronized state layer that both agents and UI components can read from and write to in real time.\n- **Human-in-the-Loop** – Lets agents pause execution to request user input, confirmation, or edits before continuing.\n- **Self-Learning** *(early access)* – Agents that continuously impr

FAQ (5)

Troubleshooting
Why does useCopilotAction renderAndWaitForResponse render nothing in Next.js dev under React StrictMode?

This is caused by a StrictMode remount bug in @copilotkit/react-core 1.53.x and earlier. The provider's guarded effect overwrites hook-registered renderToolCalls with the props-only list, so useHumanInTheLoop / renderAndWaitForResponse UIs are missing in next dev. Upgrade to @copilotkit/react-core 1.54.0 or later; 1.54.1 is confirmed working: npm install @copilotkit/react-core@^1.54.1. Upgrade related CopilotKit packages, such as @copilotkitnext/react, to compatible versions. As a temporary workaround, disable StrictMode in next.config.js with reactStrictMode: false; production builds are not affected because they do not double-invoke effects.

GitHub Issue #7695
Troubleshooting
How do I fix the ZodError "threadId Required, runId Required" on /connect replay after stopping a CopilotKit run?

Upgrade CopilotKit to v1.76.0 or later. The stop-generated RUN_FINISHED event now includes the run's threadId and runId, so it passes @ag-ui/core schema validation during /connect replay.

npm install @copilotkit/runtime@^1.76.0
# Update other @copilotkit/* packages to the same release

If you cannot upgrade immediately, restart an in-memory runtime to discard the invalid stored event. For persistent storage such as SQLite, remove the malched {"type":"RUN_FINISHED"} event from the run history. A source-level workaround is to patch finalizeRunEvents so the synthetic RUN_FINISHED copies threadId and runId from the corresponding RUN_STARTED event, instead of appending only { type: EventType.RUN_FINISHED }.

GitHub Issue #7527
Troubleshooting
Why does dispatchAction resolve before onAction finishes in CopilotKit A2UIProvider (@copilotkit/a2ui-renderer)?

This is a known bug in @copilotkit/a2ui-renderer (v1.71.1): although OnActionCallback is typed as (message) => void | Promise<void>, A2UIProvider calls onActionRef.current(message) without returning its result — both in the MessageProcessor action handler and in the surface dispatch method — so the promise is dropped and dispatchAction resolves immediately. **Fix:** patch packages/a2ui-renderer/src/react-renderer/core/A2UIProvider.tsx to return the callback's result in both places:

// MessageProcessor action handler
processorRef.current = new MessageProcessor([...], (action) => {
  if (onActionRef.current) {
    // ...build `message`
    return onActionRef.current(message);
  }
});

// dispatch
dispatch: (message: any) => onActionRef.current?.(message),

This is safe for synchronous handlers. @a2ui/web_core already propagates the promise (SurfaceModel.dispatchAction awaits onAction.emit(...), and EventEmitter.emit awaits each listener), so returning the value is all that's needed. **Workaround until patched:** use a bare MessageProcessor directly (without A2UIProvider) whose action handler returns your async onAction promise — then dispatchAction correctly resolves after the handler settles.

GitHub Issue #7906
Troubleshooting
How do I fix CopilotKit A2UI rendering failures caused by `ag_ui` vs `ag-ui` state key mismatch in LangGraph?

LangGraph may normalize the hyphenated ag-ui state key to ag_ui, while CopilotKit middleware reads only state["ag-ui"]. As a result, a2ui_schema and inject_a2ui_tool are not found, A2UI tools are not injected, and components may render as unknown.

Workaround: normalize the state key before CopilotKit/A2UI logic runs in each affected node:

async def chat_node(state):
    if "ag_ui" in state and "ag-ui" not in state:
        state["ag-ui"] = state["ag_ui"]

    # Existing agent logic
    response = await model.ainvoke(state["messages"])
    return {"messages": [response]}

Apply the same normalization in sub-agents or any node that reads A2UI state. You can verify the actual keys with:

print("ag-ui" in state, "ag_ui" in state)
print(list(state.keys()))

Affected configurations include CopilotKit 0.1.94+, ag-ui-langgraph 0.0.40+, and LangGraph 1.1.0+.

GitHub Issue #5463
Troubleshooting
How do I fix PocketBase 'context deadline exceeded' when a startup check lists one record but times out counting all records?

PocketBase's list() method counts total records by default, even when perPage is set to 1. On large tables such as cvdiag_events with ~23.6 million rows, the generated SELECT COUNT(DISTINCT id) query can exceed PocketBase's 30-second deadline and return HTTP 400.

Fix the presence check by disabling the total count:

pb.list(collection, {
  perPage: 1,
  skipTotal: true,
});

Apply this to both diagnostic collection checks:

- cvdiag_events
- cvdiag_raw_byte_samples

In the reported staging environment, the read-only check with perPage=1&skipTotal=true completed in 112 ms. Keep the existing health, authentication, missing-collection, and permission checks unchanged. No schema change, retry policy, or timeout increase is required. If the startup probe fails, buildCvdiagPersistenceWriter() disables durable diagnostics and events fall back to stdout, so the misleading generic cvdiag.pb-writer.write-failed log should be interpreted as a startup read/probe failure.

GitHub Issue #7555