showcase/shell-docs/src/content/docs/tutorials/ai-todo-app/step-3-copilot-readable-state.mdx
At this point, we have a chat popup in our app and we're able to chat directly with our copilot. This is great, but our copilot doesn't know anything about our app. In this step, we'll provide our copilot with the state of our todos.
In this step, you'll learn how to provide knowledge to the copilot. In our case, we want the copilot to know about the tasks in our app.
Let's quickly review how our app's state works. Open up the lib/hooks/use-tasks.tsx file.
At a glance, we can see that the file exposes a provider (TasksProvider), which defines a useful things:
tasks)addTask)updateTask)deleteTask)All of this is consumable by a useTasks hook, which we use in the rest of our application (feel free to check out the TasksList, AddTask and Task components).
This resembles the majority of React apps, where frontend state, either for a feature or the entire app, is managed by a context or state management library.
useCopilotReadable hookOur goal is to make our copilot aware of this state, so that it can provide more accurate and helpful responses. We can easily achieve this by using the useCopilotReadable hook.
// ... the rest of the file
export const TasksProvider = ({ children }: { children: ReactNode }) => {
const [tasks, setTasks] = useState<Task[]>(defaultTasks);
// [!code highlight:4]
useCopilotReadable({
description: "The state of the todo list",
value: JSON.stringify(tasks),
});
// ... the rest of the file
};
In this example, we use the useCopilotReadable hook to provide the copilot with the state of our tasks.
description property, we provide a concise description that tells the copilot what this piece of readable data means.value property, we pass the entire state as a JSON string.Now, try it out! Ask your Copilot a question about the state of the todo list. For example:
How many tasks do I still need to get done?
Magical, isn't it? ✨
<Cards> <Card title="← Previous: Set up CopilotKit" href="/tutorials/ai-todo-app/step-2-setup-copilotkit" description="Wire the CopilotKit provider and chat UI into the app." /> <Card title="Next: Frontend tools →" href="/tutorials/ai-todo-app/step-4-frontend-tools" description="Let the copilot take actions on the todo list with useFrontendTool." /> </Cards>