Skip to main content

How Diagram Definitions Work

Every LLM4B workflow is stored as a single structured JSON **diagram definition**. Understanding its two layers—the **visual layout** used by the Workflow De...

Workflow Authoring

How Diagram Definitions Work

Every LLM4B workflow is stored as a single structured JSON diagram definition. Understanding its two layers—the visual layout used by the Workflow Designer canvas and the compiled execution graph used by the Workflow Engine—makes it easy to author, inspect, debug, and automate diagrams reliably.


Two Layers of a Workflow Definition

When you save a workflow from the Designer (or compile a semantic WorkflowAuthoringSpec through Builder Copilot), LLM4B persists one JSON document with four top-level fields:

Code
{
  "version": 1,
  "initial_prompt": "Summarize today's urgent tickets",
  "layout": {
    "nodes": [ ... ],
    "annotations": [ ... ],
    "links": [ ... ],
    "zoom": 1.0,
    "panX": 0,
    "panY": 0
  },
  "graph": {
    "entry": "in_1",
    "nodes": { ... },
    "wires": [ ... ]
  },
  "wires": [ ... ]
}
Section Purpose
version Schema version (currently 1).
initial_prompt Optional default prompt string used when no JSON test_payload overrides initial input.
layout Visual canvas state: each node's (x, y) coordinates, flowDirection (LTR, RTL, TTB, BTT), optional caption and captionOffsetX/Y, sticky-note annotations, port-to-port visual links, and viewport zoom/pan.
graph Executable directed acyclic graph (DAG) consumed by the Workflow Engine at runtime. Contains entry (entry node ID), nodes (map of node ID → runtime node spec), wires (explicit and inferred data-routing table), and optional resilience (retry_max_attempts, retry_initial_interval_seconds, retry_backoff_coefficient, activity_timeout_seconds, max_workflow_run_duration_seconds, manual_overlap_policy).

Tip: When authoring workflows programmatically or with Builder Copilot, write a high-level WorkflowAuthoringSpec (or WorkflowGraphPatch) instead of raw canvas coordinates—the deterministic graph compiler generates both layout and graph automatically.


Cascading Resilience & Retries (graph.resilience)

Workflow-level retry and step-timeout defaults live under graph.resilience and cascade automatically to every activity-backed step (action_http, output_webhook, llm, maf_agent, llm_prompt, action_python, dataset_read, dataset_write):

Code
"resilience": {
  "retry_max_attempts": 3,
  "retry_initial_interval_seconds": 1.0,
  "retry_backoff_coefficient": 2.0,
  "activity_timeout_seconds": 1800,
  "max_workflow_run_duration_seconds": 3600,
  "manual_overlap_policy": "AllowAll"
}
  • 3-Tier Resolution Order: For each activity step, the Workflow Engine resolves retries and step timeouts in strict priority order:
    1. Per-node override inside node.config (retry_max_attempts, retry_initial_interval_seconds, retry_backoff_coefficient, activity_timeout_seconds — omitted when inheriting).
    2. Side-effect safe default or workflow default: Non-idempotent outbound actions (output_webhook and action_http using POST, PUT, PATCH, or DELETE) default to 1 attempt (no auto-retry) unless explicitly overridden on that node; read/compute steps (including GET HTTP requests) inherit graph.resilience.
    3. Platform fallback: 3 attempts, 1.0s initial delay, 2.0x backoff multiplier, and 1800s step timeout.
  • Confirmed Platform Bounds: retry_max_attempts (1–10), retry_initial_interval_seconds (0.5–300.0), retry_backoff_coefficient (1.0–5.0), activity_timeout_seconds (10–3600), and max_workflow_run_duration_seconds (10–86400, optional).
  • Non-Retryable Errors: Configuration, permission, blocked-network, and validation (4xx) errors fail immediately without retrying; automatic retries apply only to transient network, rate-limit (429), and server (5xx) failures.
  • Deterministic & Wait Steps: Pure in-workflow nodes (logic_condition, logic_switch, logic_regex, logic_parallel, logic_timer, action_approval, sub_workflow, entry triggers, and terminal exits) do not take retry overrides.

Anatomy of an Executable Graph (graph)

Inside graph.nodes, every reachable node is keyed by its unique id and serialized into one of three runtime shapes:

  1. Sequential / Activity Nodes (next edge):
    Code
    "http_1": {
      "type": "activity",
      "activity": "http_request_activity",
      "config": {
        "method": "GET",
        "url": "https://api.example.com/v1/orders/{{order_id}}",
        "output_key": "order_data"
      },
      "next": "cond_1"
    }
    
  2. Branching Nodes (logic_condition, logic_switch) (expression + branches map):
    Code
    "cond_1": {
      "type": "switch",
      "expression": {
        "path": "order_data.total",
        "op": ">=",
        "value": 500
      },
      "branches": {
        "true": "approve_1",
        "false": "out_ok"
      }
    }
    
    • logic_condition includes "op" and "value" inside expression and routes strictly to "true" or "false".
    • logic_switch omits "op" and matches str(jmespath(path, state)) against named keys in branches, falling back to "default".
  3. Entry & Terminal Nodes:
    • Entry triggers (trigger_input, trigger_webhook, trigger_signal, trigger_schedule, trigger_interval) sit at graph.entry and have zero input ports.
    • Terminal exits (output_return → "type": "terminal", output_finish → "type": "terminal_finish") have zero output ports.
    • Non-terminal output nodes such as Webhook Callback expose an optional output port (1) and continue to next when wired.

How the Workflow Engine Executes a Diagram

The Workflow Engine traverses graph using a topological readiness queue (adapted Kahn's algorithm):

  1. Predecessors & In-Degree: Before starting, the engine builds predecessor/successor maps from every next and branches edge and counts each node's in_degree (number of upstream predecessors).
  2. Entry Seed: The node referenced by graph.entry is placed into the ready queue with initial input stored under __initial__.
  3. Concurrent Dispatch: Every node whose in_degree reaches 0 runs asynchronously. Parallel sibling branches execute concurrently, and a fan-in (join) node automatically waits until all of its predecessors finish or are bypassed.
  4. Conditional Branching & Dead-Path Elimination:
    • When a switch / logic_condition node evaluates, only its chosen branch's successor is activated.
    • All unchosen branches undergo recursive bypass propagation: downstream nodes whose predecessors are all bypassed are automatically marked bypassed and skipped without executing.
    • If a join node downstream has one active predecessor and one bypassed predecessor, the bypassed edge still decrements in_degree so the active path proceeds cleanly without deadlocking.
  5. Completion vs. Early Finish:
    • Reaching Workflow Output records _workflow_output and completes its branch naturally.
    • Reaching Finish triggers graceful early termination: it records _finish_message and _workflow_output, sets the requested status (Completed, Failed, or Canceled), and cancels any remaining in-flight tasks.

Complete Annotated Diagram Example

Code
{
  "entry": "in_1",
  "nodes": {
    "in_1": {
      "type": "trigger_input",
      "next": "http_1"
    },
    "http_1": {
      "type": "activity",
      "activity": "http_request_activity",
      "config": {
        "method": "GET",
        "url": "https://api.example.com/v1/customers/{{customer_id}}",
        "output_key": "customer"
      },
      "next": "cond_1"
    },
    "cond_1": {
      "type": "switch",
      "expression": {
        "path": "customer.tier",
        "op": "==",
        "value": "enterprise"
      },
      "branches": {
        "true": "llm_1",
        "false": "finish_skip"
      }
    },
    "llm_1": {
      "type": "activity",
      "activity": "llm_activity",
      "config": {
        "provider": "vertex_gemini",
        "model": "gemini-2.5-flash",
        "secret_name": "gemini_prod_key",
        "prompt_source": "template",
        "prompt_template": "Write a VIP welcome note for {{customer_name}}.",
        "output_key": "welcome_note"
      },
      "next": "out_1"
    },
    "out_1": {
      "type": "terminal",
      "config": {
        "payload_source": "specific_key",
        "payload_key": "welcome_note"
      }
    },
    "finish_skip": {
      "type": "terminal_finish",
      "config": {
        "termination_type": "Completed",
        "message": "Skipped non-enterprise account."
      }
    }
  },
  "wires": [
    { "from_node": "__initial__", "from_key": "customer_id", "to_node": "http_1", "to_key": "customer_id" },
    { "from_node": "http_1", "from_key": "customer", "to_node": "cond_1", "to_key": "customer" },
    { "from_node": "__initial__", "from_key": "customer_name", "to_node": "llm_1", "to_key": "customer_name" },
    { "from_node": "llm_1", "from_key": "welcome_note", "to_node": "out_1", "to_key": "welcome_note" }
  ]
}

Validation Modes

Every diagram passes through two validation modes before saving or running:

  • AuthoringDraft: Permits work-in-progress settings (such as a missing BYOK secret or unconfigured webhook secret) as Warning diagnostics while blocking structural errors (unknown node types, cycles, disconnected ports, or quota limits).
  • StrictRunReady: Promotes missing required settings, unresolved Secrets Vault references, missing Agent Skills, or invalid Dataset scopes into blocking Error diagnostics before a run can start.

See How Data Flows Between Nodes and Expression and I/O Rules next to learn how values travel across edges and how each node reads them.