useRegisterState Hook
Register your existing React state with Cedar using theuseRegisterState
hook:
useCedarState
UseuseCedarState
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.