Handlers

Handlers define what happens when a trigger fires. They contain execution blocks that run in sequence.

Handler Structure

yaml

Each block has a human-readable name (shown in debug UI) and a block field that determines its behavior.

Block Kinds

next-message

Generate a response from the LLM:

yaml

With options:

yaml

For structured output (typed JSON response):

yaml

When responseType is specified:

  • The LLM generates JSON matching the type schema
  • The output variable receives the parsed object (not plain text)
  • The client receives a UIObjectPart for custom rendering

See Types for more details.

add-message

Add a message to the conversation:

yaml

For internal directives (LLM sees it, user doesn't):

yaml

For structured user input (object shown in UI, prompt for LLM context):

yaml

When uiContent is set:

  • The variable value is shown in the UI (string → text part, object → object part)
  • The prompt text is hidden from the UI but kept for LLM context
  • Useful for rich UI interactions where the visual differs from the LLM context

tool-call

Call a tool deterministically:

yaml

set-resource

Update a persistent resource:

yaml

start-thread

Create a named conversation thread:

yaml

The model field can also reference a variable for dynamic model selection:

yaml

serialize-thread

Convert conversation to text:

yaml

generate-image

Generate an image from a prompt variable:

yaml

Edit an existing image using reference images:

yaml
FieldRequiredDescription
promptYesVariable name containing the image prompt or edit instructions
imageModelYesImage model identifier (e.g., google/gemini-2.5-flash-image)
sizeNoImage dimensions: 1024x1024, 1792x1024, or 1024x1792
referenceImagesNoVariable names containing image URLs for editing/transformation
outputNoVariable name to store the generated image URL
threadNoThread to associate the output file with
descriptionNoDescription shown in the UI during generation

This block is for deterministic image generation pipelines where the prompt is constructed programmatically (e.g., via prompt engineering in a separate thread). When referenceImages are provided, the prompt describes how to modify those images.

For agentic image generation where the LLM decides when to generate, configure imageModel in the agent config.

Display Modes

Every block has a display property:

ModeDefault ForBehavior
hiddenadd-messageNot shown to user
nameset-resourceShows block name
descriptiontool-call, generate-imageShows description
streamnext-messageStreams content

Complete Example

yaml

Block Input Mapping

The input field on blocks controls which variables are passed to the prompt. Only variables listed in input are available for interpolation.

Variables can come from protocol.input, protocol.resources, protocol.variables, trigger.input, or outputs from prior blocks.

yaml

Independent Blocks

Use independent: true for content that shouldn't go to the main chat:

yaml

This is useful for:

  • Background processing
  • Summarization in separate threads
  • Generating content for tools