Set state - Writer AI Studio

Overview

The Set state block is a core building block that connects information between different parts of your blueprint, interface, and code. It acts as a bridge, allowing data to flow from one part of your workflow to another - whether that’s from blueprint to interface, between different blueprint blocks, from interface back to blueprint, or to and from custom Python code. You can specify the variable name, value, and value type (plain text or JSON). The value is then available in subsequent blocks via the state variable.

Common use cases

How it works

  1. Link Variable: Specify the name of the state variable to set.
  2. Value type: Choose whether the value is plain text or JSON. The default if not specified is plain text.
  3. Value: Enter the value to store.

The block saves the value in the specified state variable. You can reference this variable in later blocks using the state syntax, for example, @{state.variable_name}.

Examples

Text generation workflow

This example shows how to generate text and display it in the interface using state management.

Blueprint Flow:

  1. UI Trigger → User clicks “Generate” button
  2. Text generation → Creates content based on prompt
  3. Set state → Stores generated text

Interface → Has a Text component that displays the text from the state variable

Block Configuration:

Form submission workflow with JSON value type

This example shows how to package multiple form field responses into a single state variable. It’s useful when collecting and storing related data from interface forms.

Blueprint Flow:

  1. UI Trigger → User submits a registration form. All the form fields have Link Variables set to the name of the field.
  2. Set state → Stores all form fields as JSON

Block Configuration:

{
    "firstName": @{firstName},
    "lastName": @{lastName},
    "email": @{email},
    "phoneNumber": @{phoneNumber},
    "address": {
      "street": @{address.street},
      "city": @{address.city},
      "state": @{address.state},
      "zipCode": @{address.zipCode}
    },
    "preferences": {
      "newsletter": @{preferences.newsletter},
      "notifications": @{preferences.notifications}
    }
}

To access specific fields of the JSON data, use the state syntax, for example @{form_data.firstName} or @{form_data.address.city}.

To access elements of the state variable using Python, treat it as a dictionary. For example, @{state["form_data"]["firstName"]} or @{state["form_data"]["address"]["city"]}.

Fields

Name Type Control Default Description Options Validation
Link Variable Binding - - Set the variable here and use it across your agent. - -
Value type Text - text - - -
Value Text Textarea - - - -

End states

Below are the possible end states of the block call.

Name Field Type Description
Success - success The state was updated successfully.
Error - error There was an error updating the state.

The Set state block returns the value that was set in the state variable. You can access this value in the following block as @{result}, or you can use the state syntax to access the value in the state variable, for example @{form_data}.