Skip to main content
Cedar allows your agent to understand what is happening in your application, and the ability to change it. Registering a local state in Cedar is the first step to giving your agent frontend context, letting users point out parts of the UI to the agent, and letting agents manipulate state. In other words, it allows your agent to read and write to the local react state. To understand how we internally execute and render actions on your state (and how to override default behavior and rendering for state changes), read SetState Response Processing and SetState Message Rendering.

useRegisterState Hook

Register your existing React state with Cedar using the useRegisterState hook:

useCedarState

Use useCedarState to create and manage state directly in the Cedar store. It directly replaces useState and works the exact same way, but

Accessing Cedar State Functions

executeStateSetter

Execute state setter functions programmatically using the Cedar store:
Breaking Change in v0.1.11: Parameter handling has changed. State setters now receive arguments as a single object parameter instead of multiple spread parameters. Update your setter functions accordingly.
Agent Actions: State setters can be automatically invoked by your agent through structured responses. Learn more about SetState Response Processing and SetState Message Rendering to see how agents can execute these setters and display the results.
Automatic Cleanup: States are automatically unregistered when components unmount, ensuring clean state management without manual cleanup.

Schema Validation with Zod

Cedar OS has runtime validation of setter arguments using Zod schemas:

getCedarState

Retrieve the current state value for a registered Cedar state key:

setCedarState

Directly update the state value for a registered Cedar state key:

Exposing states to your agent

Now that your application states are registered in Cedar, learn how to expose just the right pieces of them to your agent:
  • Agent Input Context – orchestrate what context is sent alongside every user message, including state subscriptions and manual entries. See Agent Input Context.
  • Mentions – let users reference individual state items with simple @ mentions. See Mentions.
These docs walk you through granting the agent scoped, real-time access to your frontend data.