Redeo Docs
DocsLADR / How to Add a Gate to a Step

Adding Features

How to Add a Gate to a Step

How to Add a Gate to a Step

A gate (if: block) evaluates a condition against each node's output after a step runs. Non-matching nodes are pruned; the step-level action fires based on whether survivors remain. This guide shows the three most common gate patterns.

Pattern 1: Score threshold

Add a scoring step that prunes candidates below a threshold:

yaml
- id: verify
  nodes: 5                                    # 5 parallel verifiers
  fields:
    - { name: Candidate, type: ingest, from: { stepId: generate, loopRef: current } }
  systemPrompt: 'Score 1-5. Output the integer alone.'
  if:
    integerRange: [4, 5]                      # keep only scores 4-5
    then: continue                            # survivors advance
    else: abort                               # no survivors → stop

The integerRange: [4, 5] condition parses each node's output as an integer and keeps only those in the inclusive range [4, 5]. Nodes outputting "3" or "2" are pruned. Their outputs are invisible to downstream steps.

Downstream steps use multi_ingest: { nodeRef: accumulate } to read all survivors.

Pattern 2: Reflexion loop

Add a critique step that loops back on failure:

yaml
- id: draft
  fields:
    - { name: Question, type: text, from: input.context }
    - { name: Feedback, type: ingest, from: { stepId: critique, loopRef: previous }, fallback: "" }
  systemPrompt: "Answer the question. If Feedback is provided, address it."

- id: critique
  fields:
    - { name: Answer, type: ingest, from: { stepId: draft, loopRef: current } }
  systemPrompt: 'Critique the answer. Output JSON {"verdict": "good"|"bad"}.'
  if:
    jsonMatches:
      type: object
      properties:
        verdict: { type: string, enum: [good] }
    then: continue                            # good → advance to next step
    else: { jump: { stepId: draft } }         # bad → jump back to draft

The backward jump from critique to draft creates a retry loop. Each iteration, the draft step reads the previous critique as Feedback (via loopRef: previous). The hop ceiling bounds total iterations — no infinite loop risk.

Pattern 3: Confidence early exit

Skip ahead when confidence is high:

yaml
- id: draft
  fields: [{ name: Question, type: text, from: input.context }]
  systemPrompt: 'Answer. Emit JSON {"answer": "...", "confidence": 0.0-1.0}.'
  if:
    jsonMatches:
      type: object
      properties:
        confidence: { type: number, minimum: 0.9 }
    then: { jump: { stepId: answer } }        # high confidence → skip to answer
    else: continue                            # low confidence → continue to expand

- id: expand
  fields:
    - { name: Question, type: text, from: input.context }
    - { name: Draft, type: ingest, from: { stepId: draft, loopRef: current } }
  systemPrompt: "Research deeper and improve the draft."

- id: answer
  fields:
    - { name: Result, type: ingest, from: { stepId: draft, loopRef: current }, fallback: "" }
  systemPrompt: "Return the answer."

The forward jump skips the expand step entirely on high confidence. The fallback: "" on the answer step handles the case where the jump came from expand (so draft's output is available) vs. directly from draft (where draft's output is the JSON, not the answer).