Skip to main content
Cedar processes your agent responses via a switch statement based on the “type” field. This allows you to completely customize how structured responses from your agent backend are processed. This is the system through which messages are added to the chat, state actions are executed, or any decisions are made on how to deal with responses from the backend. Cedar-OS  Diagram Note: This system is how we run anything user customisable, such as Custom Message Rendering.

LLM Response Structure

When your agent backend returns responses, they follow the LLMResponse interface:
The object field is where Cedar looks for structured responses to process. It can contain:
  • A single StructuredResponseType object
  • An array of StructuredResponseType objects for multiple operations
  • undefined if no structured output was generated
Only objects in the object field are processed by the response processing system. The content field is always added to the chat by default as a simple text message.

Base Response Type

All structured responses in Cedar extend the BaseStructuredResponseType interface:

Requirements for Custom Response Processing

To use the custom response processing system, your response objects must have a type field. This field determines which processor will be used to handle the response.

Response Processor Interface

Cedar uses a strongly typed ResponseProcessor interface that ensures type safety throughout the processing pipeline:
Key typing features:
  • The execute function receives your narrowly typed custom response (e.g., NotificationResponse)
  • The validate function receives the broadly typed StructuredResponseType for runtime validation

Custom Response Type Definition

Cedar exports a CustomStructuredResponseType<T, P> type that allows you to create type-safe custom responses:

Response Processor Factory Function

Cedar exports a createResponseProcessor factory function to create type-safe processors:

How Response Processing Works Internally

When a response comes back from the backend, Cedar uses the following process:
  1. Response Reception: The system receives the LLM response and checks for structured objects in the object field
  2. Type Detection: If an object exists, the system examines its type field
  3. Processor Lookup: The system searches for a registered processor that matches the response type
  4. Validation: If a processor is found and has a validation function, it checks if the response structure is valid
  5. Processing: If validation passes (or no validation exists), the processor’s execute function is called
  6. Override Behavior: This is the ONLY thing that runs - it completely overrides default behavior, so if you want to add the message to chat, you must do so manually in your processor

Full Implementation Examples

Default Response Types and Processors

Cedar automatically handles these response types with default behavior. Each type has a corresponding default processor:

"message" Type

  • Behavior: Adds text messages directly to chat with specified role
  • Properties: content: string, role?: 'user' | 'assistant' | 'bot'
  • Default Processor: messageResponseProcessor adds messages to chat

"setState" Type

  • Behavior: Executes state actions via state setters and adds setState message to chat
  • Properties: stateKey: string, setterKey: string, args?: unknown
  • Default Processor: setStateResponseProcessor executes state actions and adds to chat
SetState Factory Functions: Cedar provides special factory functions for setState responses:

"progress_update" Type

  • Behavior: Updates existing progress messages or creates new ones with state tracking
  • Properties: text: string, state: 'in_progress' | 'complete' | 'error'
  • Default Processor: progressUpdateResponseProcessor manages progress message lifecycle

"frontendTool" Type

  • Behavior: Executes registered frontend tools with full type safety and validation
  • Properties: toolName: string, args?: unknown
  • Default Processor: frontendToolResponseProcessor executes tools and adds execution message to chat
  • Learn More: See the complete Frontend Tools documentation for detailed implementation examples

"humanInTheLoop" Type

  • Behavior: Suspends workflow execution and creates interactive UI for user input/approval
  • Properties: status: 'suspended', runId: string, stepPath: [string[], ...string[][]], suspendPayload?: object, message?: string, timeoutMs?: number
  • Default Processor: humanInTheLoopResponseProcessor manages workflow suspension/resume lifecycle
  • Learn More: See the complete Human-in-the-Loop documentation for detailed implementation examples

Zod Schema Validation

Cedar exports Zod schemas for all default response processor types, enabling runtime validation and type safety:
Available Zod Schemas:
  • BackendMessageResponseSchema - For "message" type responses
  • SetStateResponseSchema - For "setState" type responses
  • LegacyActionResponseSchema - For "action" type responses (backwards compatibility)
  • ProgressUpdateResponseSchema - For "progress_update" type responses
  • HumanInTheLoopResponseSchema - For "humanInTheLoop" type responses
  • FrontendToolResponseSchema - For "frontendTool" type responses
If you override any of these default types, you lose the built-in behavior. Since processors completely override default handling, ensure your custom implementation covers all functionality you need, including adding messages to the chat if desired.
Cedar encourages organizing custom processors in dedicated files for easier maintenance and debugging:
This structure keeps all Cedar-related logic organized under a cedar-os directory, making it easier to maintain, debug, and ensure consistency across your application. Remember that processors completely override default behavior, so plan your implementations to handle all the functionality you need.