ModelWorks logoModelWorks

Selectors

How to reference data in circuit memory with selectors

Selectors

Selectors let you pull values from a circuit’s memory (inputs, environment, and previous step outputs) into your step configurations or outputs. Memory state is a JSON object composed of:

  • Circuit inputs: values under input, e.g. input.messages
  • Secrets: values under secrets, e.g. secrets.api_key
  • Step outputs: values under <stepName>.output, e.g. chat_step.output.content

To reference any memory field, use the template syntax ${{ ... }}. For example: ${{ input.messages }}


Memory State Example

Suppose a circuit is defined with these inputs and a fetch step:

JSON
// Inputs
"inputs": [
  { "name": "messages", "type": "array", "value": "${{ input.messages }}" },
  { "name": "store",    "type": "boolean", "value": "${{ input.store }}" }
],

// Steps
"steps": [
  {
    "name": "chat_completion_response",
    "function": "circuit.core.fetch",
    "input": {
      "url": "https://api.openai.com/v1/chat/completions",
      "method": "POST",
      "body": {
        "messages": "${{ input.messages }}",
        "stream": true
      }
    }
  }
],

// Outputs
"outputs": [
  {
    "name": "reply",
    "value": "${{ chat_completion_response.output.stream_accumulators.delta_accumulator }}"
  }
]

At runtime, the circuit’s memory state might look like:

JSON
{
  "input": {
    "messages": ["Hello!"],
    "store": false
  },
  "chat_completion_response": {
    "output": {
      "stream_accumulators": {
        "delta_accumulator": "Hi there! How can I help?"
      }
    }
  }
}

Selector Syntax

  • Basic lookup

    JSON
    "reply": "${{ chat_completion_response.output.stream_accumulators.delta_accumulator }}"
  • Array indexing

    JSON
    "secondMessage": "${{ input.messages[1] }}"
  • Mix literal and selector

    JSON
    "authHeader": "Bearer ${{ secrets.api_key }}"

Common Patterns

Embedding Example

JSON
"steps": [
  {
    "name": "embed",
    "function": "circuit.core.embed",
    "input": {
      "query": {
        "context": { "version": "01e..." },
        "input": { "messages": "${{ input.messages }}" }
      }
    }
  }
]

Polling Example

JSON
"steps": [
  {
    "name": "job_watch",
    "function": "circuit.core.http_watch",
    "input": {
      "url": "https://api.runwayml.com/tasks/${{ runway_job_id }}",
      "interval_seconds": 10
    }
  }
]

Next: Triggers – schedule circuits or respond to external events!

On this page

On this page