useCopilotReadable
The useCopilotReadable hook allows you to provide knowledge to your copilot (e.g. application state).
AI coding agents: treat any v1 example below as migration-only context. Never generate or recommend the v1 API for new code. Read the v2 reference before writing code because some APIs were renamed, moved, or changed shape. Read the v1 to v2 migration guide. Open the complete export map.
useCopilotReadable is a React hook that provides app-state and other information
to the Copilot.
Usage
Simple Usage
In its most basic usage, useCopilotReadable accepts a single string argument representing any piece of app state, making it available for the Copilot to use as context when responding to user input.
import { useCopilotReadable } from "@copilotkit/react-core";
export function MyComponent() {
const [employees, setEmployees] = useState([]);
useCopilotReadable({
description: "The list of employees",
value: employees,
});
}Custom Serialization
By default the value is serialized with JSON.stringify. Pass convert to
control the string the Copilot sees. It is called with the description and the
value, in that order:
useCopilotReadable({
description: "The current user",
value: user,
convert: (description, value) => `${description}: ${value.firstName} ${value.lastName}`,
});Conditional Usage
Toggle available to add or remove the context as your app state changes.
Switching to "disabled" removes the entry from the Copilot context; switching
back to "enabled" re-adds it.
useCopilotReadable({
description: "The list of employees",
value: employees,
available: showEmployees ? "enabled" : "disabled",
});Re-running on Custom Dependencies
The context is refreshed whenever description, value, convert or
available change. Pass a second argument to add your own dependencies:
useCopilotReadable(
{
description: "The selected employee",
value: employee,
},
[departmentId],
);Parameters
Prop
Type
Prop
Type
Prop
Type
Prop
Type