skills/copilotkit-debug/references/agent-debugging.md
| Agent Type | Package | Description |
|---|---|---|
BuiltInAgent | @copilotkit/agent | Uses Vercel AI SDK streamText with configurable model providers |
LangGraphAgent | @ag-ui/langgraph | Wraps a LangGraph deployment (Python or JS) |
A2AAgent | Varies | Agent-to-Agent protocol agent |
Custom AbstractAgent | @ag-ui/client | Any class extending AbstractAgent with a run() returning Observable<BaseEvent> |
Symptom: CopilotKitCoreErrorCode.agent_not_found or CopilotKitErrorCode.AGENT_NOT_FOUND
Diagnostic steps:
Hit the /info endpoint to see registered agents:
curl http://localhost:3001/api/copilotkit/info | jq .agents
Compare the agent names in the response with the agentId prop:
<CopilotChat agentId="myAgent" />;
// or
const { run } = useAgent({ name: "myAgent" });
Check the runtime agent map -- keys must match exactly (case-sensitive):
new CopilotRuntime({
agents: {
myAgent: new BuiltInAgent({
/* ... */
}), // Key "myAgent" is the agent ID
},
});
If using lazy agent loading (agents: Promise<...>), check that the promise resolves successfully.
If an agent throws during construction, the runtime may start without it:
resolveModel() throws if the provider string is invalid (e.g., "openai/" without a model name, or "unknown/model").RunStartedEvent
-> TextMessageStartEvent (messageId)
-> TextMessageChunkEvent (delta: "Hello")
-> TextMessageChunkEvent (delta: " world")
-> TextMessageEndEvent
RunFinishedEvent
RunStartedEvent
-> TextMessageStartEvent
-> TextMessageChunkEvent (delta: "Let me check...")
-> TextMessageEndEvent
-> ToolCallStartEvent (toolCallId, toolName)
-> ToolCallArgsEvent (delta: '{"query": "weather"}')
-> ToolCallEndEvent
-> ToolCallResultEvent (result: '{"temp": 72}')
-> TextMessageStartEvent
-> TextMessageChunkEvent (delta: "The temperature is 72F")
-> TextMessageEndEvent
RunFinishedEvent
RunStartedEvent
-> RunErrorEvent (message: "...") // Non-fatal, run continues
-> TextMessageStartEvent
-> ...
RunFinishedEvent
Or for fatal errors:
RunStartedEvent
-> RunErrorEvent (message: "...") // Fatal
// Stream ends without RunFinishedEvent
RunStartedEvent
-> StateSnapshotEvent (snapshot: {...}) // Full state
-> StateDeltaEvent (delta: [{op: "replace", path: "/count", value: 5}])
-> TextMessageStartEvent
-> ...
RunFinishedEvent
RunStartedEvent
-> ReasoningStartEvent
-> ReasoningMessageStartEvent
-> ReasoningMessageContentEvent (delta: "thinking...")
-> ReasoningMessageEndEvent
-> ReasoningEndEvent
-> TextMessageStartEvent
-> TextMessageChunkEvent
-> TextMessageEndEvent
RunFinishedEvent
Known issue: Reasoning events can cause stalls if the client-side event handler does not consume them properly (issue #3323).
Symptom: Agent emits StateSnapshotEvent or StateDeltaEvent but the React component does not re-render.
Diagnostic steps:
useFrontendTool with state, ensure the state shape matches what the component expects.copilotkit_emit_state events are reaching the frontend (see Python SDK event prefix mismatch, issue #3519).Symptom: Agent does not receive application context set via useAgentContext or similar hooks.
Diagnostic steps:
forwardedProps in the AG-UI RunAgentInput. Check the request body to /agent/:id/run.useAgentContext is called inside the CopilotKitProvider tree and before the agent runs.Error code: tool_not_found
The agent called a tool name that does not match any registered frontend tool.
Diagnostic steps:
Tool[] array in the request to /agent/:id/run.useFrontendTool is registered with the exact tool name (case-sensitive).Error code: tool_argument_parse_failed
The LLM generated arguments that do not match the tool's parameter schema.
Diagnostic steps:
ToolCallArgsEvent in the SSE stream -- the delta field contains the raw JSON.Error code: tool_handler_failed
The tool's execute function threw an exception.
Diagnostic steps:
onError callback in CopilotChat or CopilotKitProvider receives the error with context.Symptom: The tool returns a result but the agent does not produce a follow-up message.
Diagnostic steps:
ToolCallResultEvent was emitted in the SSE stream after the tool completed.runId may change after HITL resolve (issue #3456), breaking the continuation.BuiltInAgent uses resolveModel() to convert string identifiers to Vercel AI SDK LanguageModel instances.
Supported formats:
"openai/gpt-5", "openai/gpt-4o", "openai/o3-mini""anthropic/claude-sonnet-4.5", "anthropic/claude-opus-4""google/gemini-2.5-pro", "google/gemini-2.5-flash""vertex/gemini-2.5-pro" (uses Google Vertex AI)Common errors:
Invalid model string "..." -- Missing provider prefix or model nameUnknown provider "..." in "..." -- Unsupported provider (only openai, anthropic, google, vertex)OPENAI_API_KEY, ANTHROPIC_API_KEY, or GOOGLE_API_KEY not set in environmentBuiltInAgent supports MCP (Model Context Protocol) clients:
new BuiltInAgent({
model: "openai/gpt-4o",
mcpClients: [
{ type: "http", url: "http://localhost:8080" },
{
type: "sse",
url: "http://localhost:8081/sse",
headers: { Authorization: "Bearer ..." },
},
],
});
MCP debugging:
type: "http" uses StreamableHTTPClientTransporttype: "sse" uses SSEClientTransportThe CopilotKit Python SDK (v0.1.83) dispatches custom events with a "copilotkit_" prefix, but ag-ui-langgraph expects event names without that prefix. This causes copilotkit_emit_message, copilotkit_emit_state, and copilotkit_emit_tool_call to be silently dropped (issue #3519).
The official LangGraph JS template may be outdated and incompatible with current CopilotKit versions (issue #3231). Check for the latest template version.
Intelligence mode uses the CopilotKitIntelligence client to manage threads:
getOrCreateThread.apiKey or tenantId in the Intelligence configuration.Intelligence mode uses WebSocket for real-time events:
{wsUrl}/runner -- used by the runtime to communicate with the Intelligence platform{wsUrl}/client -- used by the frontend for real-time thread updatesIf WebSocket connections fail:
wsUrl is correct (should start with wss://)wsUrl -- /runner and /client suffixes are appended automaticallyThe CopilotKit Web Inspector (@copilotkit/web-inspector) provides real-time visibility into:
Enable it during development:
import { CopilotKitWebInspector } from "@copilotkit/web-inspector";
<CopilotKitProvider runtimeUrl="/api/copilotkit">
<CopilotKitWebInspector />
<YourApp />
</CopilotKitProvider>;