Skip to content

Commit 2f38e94

Browse files
committed
feat(react-core): add useCapabilities hook
1 parent 6a5126d commit 2f38e94

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

packages/react-core/src/v2/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export { useRenderTool } from "./use-render-tool";
88
export { useDefaultRenderTool } from "./use-default-render-tool";
99
export { useHumanInTheLoop } from "./use-human-in-the-loop";
1010
export { useAgent, UseAgentUpdate } from "./use-agent";
11+
export { useCapabilities } from "./use-capabilities";
1112
export { useAgentContext } from "./use-agent-context";
1213
export type { AgentContextInput, JsonSerializable } from "./use-agent-context";
1314
export { useSuggestions } from "./use-suggestions";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { AgentCapabilities } from "@ag-ui/core";
2+
import { ProxiedCopilotRuntimeAgent } from "@copilotkit/core";
3+
import { useAgent } from "./use-agent";
4+
5+
/**
6+
* Returns the capabilities declared by the given agent (or the default agent).
7+
* Capabilities are fetched from the runtime at connection time and are
8+
* available synchronously — no loading state required.
9+
*
10+
* @param agentId - Optional agent ID. If omitted, uses the default agent.
11+
* @returns The agent's capabilities, or `undefined` if the agent hasn't
12+
* connected yet or doesn't declare capabilities.
13+
*/
14+
export function useCapabilities(agentId?: string): AgentCapabilities | undefined {
15+
const { agent } = useAgent({ agentId });
16+
17+
if (agent instanceof ProxiedCopilotRuntimeAgent) {
18+
return agent.capabilities;
19+
}
20+
21+
return undefined;
22+
}

0 commit comments

Comments
 (0)