From f7f0c1fac869cd25b7fa884e5c5a909ff98e292e Mon Sep 17 00:00:00 2001 From: Howard Gil Date: Tue, 24 Feb 2026 13:18:20 -0800 Subject: [PATCH] fix: prevent CopilotListeners crash when no agents registered (#3249) Replace useAgent() hook with copilotkit.getAgent() in CopilotListeners to avoid throwing when the agents map is empty. This fixes crashes for users who use CopilotKit without agents (e.g., only for context/tools). Co-Authored-By: Claude Opus 4.6 --- packages/v1/react-core/src/components/CopilotListeners.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/v1/react-core/src/components/CopilotListeners.tsx b/packages/v1/react-core/src/components/CopilotListeners.tsx index 8d0ed804910..13e76fc241e 100644 --- a/packages/v1/react-core/src/components/CopilotListeners.tsx +++ b/packages/v1/react-core/src/components/CopilotListeners.tsx @@ -1,6 +1,5 @@ import { useCallback, useEffect, useMemo, useRef } from "react"; import { - useAgent, useCopilotChatConfiguration, useCopilotKit, } from "@copilotkitnext/react"; @@ -70,7 +69,7 @@ export function CopilotListeners() { const resolvedAgentId = existingConfig?.agentId; const { setBannerError } = useToast(); - const { agent } = useAgent({ agentId: resolvedAgentId }); + const agent = copilotkit.getAgent(resolvedAgentId); usePredictStateSubscription(agent);