Skip to content

Commit 41ae4fa

Browse files
committed
feat(saas-demo): v2 hooks in copilot-context
- Switch imports from @copilotkit/react-core to /v2 - Replace useCopilotReadable with useAgentContext (stringify object value) - Convert navigateToPageAndPerform parameters array to a Zod object schema
1 parent 3966baa commit 41ae4fa

1 file changed

Lines changed: 18 additions & 25 deletions

File tree

examples/showcases/banking/src/components/copilot-context.tsx

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
2-
import { useCopilotReadable, useHumanInTheLoop } from "@copilotkit/react-core";
2+
import { useAgentContext, useHumanInTheLoop } from "@copilotkit/react-core/v2";
3+
import { z } from "zod";
34
import { useAuthContext } from "@/components/auth-context";
45
import { Button } from "./ui/button";
56

@@ -30,12 +31,12 @@ const CopilotContext = ({ children }: { children: React.ReactNode }) => {
3031
// A readable of app wide authentication and authorization context.
3132
// The LLM will now know which user is it working against, when performing operations.
3233
// Given the respective authorization role, the LLM will allow/deny actions/information throughout the entire app.
33-
useCopilotReadable({
34+
useAgentContext({
3435
description: "The current user logged into the system",
35-
value: currentUser,
36+
value: JSON.stringify(currentUser),
3637
});
3738

38-
useCopilotReadable({
39+
useAgentContext({
3940
description:
4041
"The available pages and operations, as well as the current page",
4142
value: {
@@ -59,28 +60,20 @@ const CopilotContext = ({ children }: { children: React.ReactNode }) => {
5960
For example, if the user is on the cards page and asks to add a card, do NOT use this action - use the addNewCard tool instead.
6061
Only use this when the user is on the wrong page entirely (e.g., on team page but asking about cards).
6162
`,
62-
parameters: [
63-
{
64-
name: "page",
65-
type: "string",
66-
description: "The page in which to perform the operation",
67-
required: true,
68-
enum: ["/cards", "/team", "/"],
69-
},
70-
{
71-
name: "operation",
72-
type: "string",
73-
description:
63+
parameters: z.object({
64+
page: z
65+
.enum(["/cards", "/team", "/"])
66+
.describe("The page in which to perform the operation"),
67+
operation: z
68+
.string()
69+
.describe(
7470
"The operation to perform. Use operation code from available operations per page. If the operation is unavailable, do not pass it",
75-
required: false,
76-
},
77-
{
78-
name: "operationAvailable",
79-
type: "boolean",
80-
description: "Flag if the operation is available",
81-
required: true,
82-
},
83-
],
71+
)
72+
.optional(),
73+
operationAvailable: z
74+
.boolean()
75+
.describe("Flag if the operation is available"),
76+
}),
8477
followUp: false,
8578
render: ({ args, respond }) => {
8679
const { page, operation, operationAvailable } = args;

0 commit comments

Comments
 (0)