Skip to main content
Cedar enables your agent to not only read state but also execute actions through structured responses. This guide shows you how to set up an end-to-end flow where your agent can understand your application state and perform actions on it.

Overview

The agentic actions flow consists of four main parts:
  1. Register State Setters - Define what state manipulation actions can be performed
  2. Register Frontend Tools - Define what other actions can be executed
  3. Configure Structured Responses - Set up your agent to return structured data
  4. Handle LLM Results - Process the structured responses and execute actions

Complete Example: Product Roadmap

Let’s walk through a complete example using a product roadmap application where the agent can add features, remove nodes, and manage diffs.

Step 1: Register State with Custom State Setters

First, register your state with custom state setters that define the available actions:

Step 2: Register Frontend Tools

In addition to state setters, you can register frontend tools that agents can execute directly. These tools handle UI actions, notifications, talking to external systems, and other operations that don’t directly manipulate Cedar state:

Step 3: Configure Your Agent for Structured Responses

Configure your agent backend to return structured responses. For state setters, your agent should return setState type responses. For frontend tools, your agent should return frontendTool type responses.
Example:

Step 4: Handle LLM Results

Cedar’s handleLLMResult function automatically processes both setState and frontendTool responses. It will:
  1. Find the relevant state setter or frontend tool
  2. Validate provided args against the argsSchema (if provided)
  3. Execute the function if args are valid
  4. Add the message to the chat
Note: This default handling can be customized using Custom Response Processing. You can also customize how setState completion is displayed with Custom Message Rendering.

Using Actions in Your UI

You can trigger actions directly from your UI components:

Best Practices

1. Use Descriptive Action Names

Make your setter names clear and action-oriented:

2. Use Descriptive Schema Fields

Help your agent understand what parameters to provide using Zod’s describe method for both state setters and frontend tools:

3. Use Conditional Tool Registration

Register tools only when they’re relevant to the current state:

4. Handle Errors Gracefully

Add error handling in both state setters and frontend tools:

Automatic Schema Distribution

Cedar automatically includes the schemas of all registered state setters and frontend tools in the context sent to your agent. This enables your agent to understand both the data structure and what actions are available.

Schema Structure

The schemas are included in top-level fields alongside your subscribed state data:

Zod Schema Integration

Both state setters and frontend tools use Zod schemas to define parameter validation and provide rich type information to your agent. Cedar automatically converts Zod schemas to JSON Schema format using zod-to-json-schema and includes them in the context sent to your agent. To take advantage of this, just register an argsSchema with any state setter or frontend tool.
This schema-based approach provides several benefits:
  • Type Safety: Runtime validation of parameters
  • Rich Documentation: Descriptive field information for agents
  • Automatic JSON Schema: Converted format perfect for LLM understanding
  • Consistent API: Single source of truth for parameter definitions

Next Steps