File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,6 +34,14 @@ Programmatic control lets you run agents outside of a chat UI — trigger agent
3434 </Tab >
3535</Tabs >
3636
37+ <Callout type = " info" >
38+ Note: If you are not using CopilotKit Cloud public access/license key, then you need to pass your agentId to useAgent() hook.
39+ ``` ts
40+ const { agent } = useAgent ({agentId: " myAgent" })
41+ ````
42+
43+ < / Callout >
44+
3745You can also execute individual tools programmatically — no LLM turn needed :
3846
3947< Tabs items = {[' tool-button.tsx' ]}>
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ Use `copilotkit.runAgent()` to trigger your agent from any component — no chat
4141``` tsx title="page.tsx"
4242import { useAgent } from " @copilotkit/react-core/v2" ;
4343import { useCopilotKit } from " @copilotkit/react-core/v2" ;
44- import { randomUUID } from " @copilotkit/shared/v2 " ;
44+ import { randomUUID } from " @copilotkit/shared" ;
4545
4646export function AgentTrigger() {
4747 const { agent } = useAgent ();
Original file line number Diff line number Diff line change 2121 return (
2222 <div >
2323 { /* [!code highlight:4] */ }
24- <p >Agent ID: { agent .id } </p >
24+ <p >Agent ID: { agent .agentId } </p >
2525 <p >Thread ID: { agent .threadId } </p >
2626 <p >Status: { agent .isRunning ? " Running" : " Idle" } </p >
2727 <p >Messages: { agent .messages .length } </p >
3030 }
3131 ```
3232
33+ <Callout type = " info" >
34+ Note: If you are not using CopilotKit Cloud public access/license key, then you need to pass your agentId to useAgent() hook.
35+ ```ts
36+ const { agent } = useAgent({ agentId : " myAgent" } )
37+ ```
38+ </Callout >
39+
3340 The hook will throw an error if no agent is configured, so you can safely use ` agent ` without null checks.
3441 </Step >
3542
9198 ``` tsx title="page.tsx"
9299 import { useAgent } from " @copilotkit/react-core/v2" ;
93100 import { useCopilotKit } from " @copilotkit/react-core/v2" ;
94- import { randomUUID } from " @copilotkit/shared/v2 " ;
101+ import { randomUUID } from " @copilotkit/shared" ;
95102
96103 export function RunAgent() {
97104 const { agent } = useAgent ();
@@ -209,7 +216,7 @@ export function EventLogger() {
209216 // [!code highlight:2]
210217 const { unsubscribe } = agent .subscribe (subscriber );
211218 return () => unsubscribe ();
212- }, []);
219+ }, [agent ]);
213220
214221 return null ;
215222}
You can’t perform that action at this time.
0 commit comments