Core Concepts

Six concepts cover everything you need to build with Hyphen.

graph LR W["Workflow<br/>(JSON spec)"] --> P["Primitives<br/>(built-in steps)"] W --> A["Actions<br/>(registered ops)"] P --> C["Context<br/>(@path data flow)"] A --> C C --> AG["Agents<br/>(ReAct loops)"] AG --> R["Runs<br/>(execution + audit)"] P --> R style W fill:#e3f2fd,stroke:#1565c0 style P fill:#e8f5e9,stroke:#2e7d32 style A fill:#fff3e0,stroke:#e65100 style C fill:#f3e5f5,stroke:#6a1b9a style AG fill:#fce4ec,stroke:#c62828 style R fill:#e0f2f1,stroke:#00695c

1. Workflows

A workflow is a JSON spec that defines a process. It has a name, an optional top-level condition gate, and an ordered array of actions (steps).

json
{
  "name": "invoice_reconciliation",
  "definition": {
    "condition": { "greaterThan": ["@input.invoices.length", 0] },
    "actions": [
      { "type": "matcher", "properties": { ... } },
      { "type": "loop", "properties": { "mode": "react", ... } },
      { "type": "PbotApproval", "properties": { ... } }
    ]
  }
}

Workflows are created via POST /workflows, executed via POST /workflows/:id/execute, and produce runs with full audit trails. They can also be generated from plain language via POST /ai/generate-workflow.

AI as Compiler. Hyphen's core philosophy: AI generates the workflow spec upfront (compile time), then the engine executes it deterministically (runtime). AI doesn't improvise during execution — it produces the blueprint, and the engine follows it exactly.

---

2. Actions

Actions are reusable operations you register once and reference by name in any workflow. Five kinds:

Kind What It Does Example
http Calls REST APIs POST to Salesforce, GET from Stripe
llm AI text generation Summarize a document, extract entities
db Database queries SELECT from your warehouse
matcher Pre-configured matching Matching rules saved as a reusable action
custom-table Table operations Read/write to Hyphen-managed tables

Register an action:

bash
curl -X POST http://localhost:3009/actions \
  -H "X-Org-Id: your-org" \
  -H "Content-Type: application/json" \
  -d '{
    "action_name": "fetch_customer",
    "kind": "http",
    "url": "https://api.example.com/customers/{{customer_id}}",
    "http_method": "GET",
    "passthrough": true
  }'

Use it in a workflow step:

json
{ "type": "fetch_customer", "properties": { "customer_id": "@input.id" } }

Use it as a ReAct agent tool:

json
{ "tools": [{ "type": "action", "name": "fetch_customer" }] }

All action kinds work everywhere — in workflow steps, foreach loops, and as agent tools.

→ Full reference: Actions


3. Primitives

Primitives are built-in workflow steps that don't require registration. They handle core orchestration patterns:

Primitive Purpose When to Use
Matcher Multi-criteria data matching Reconciling two datasets (invoices↔payments, claims↔records)
Loop Batch processing (foreach) or AI reasoning (react) Processing N items, or letting an agent investigate a problem
PbotApproval Human-in-the-loop Manager sign-off, compliance review, edge case decisions
PbotForm External input collection Vendor submits shipping details, customer provides documents
Custom Table Multi-tenant data storage Audit logs, operational state, cross-run memory

Primitives use the step type field directly — no registration required:

json
{ "type": "matcher", "properties": { "left": "@input.invoices", "right": "@input.payments", ... } }
{ "type": "PbotApproval", "properties": { "comment": "Review this transaction" } }

4. Context

Context is how data flows between steps. Every workflow run maintains a context object that grows as steps execute.

@path References

The @ prefix references values from context:

Path What It References
@input.field Data passed when the workflow was executed
@matched Matched records from a matcher step
@unmatchedLeft Left-side unmatched records from a matcher
@item Current item inside a foreach loop
@__run_id The current run's ID
@__approved Boolean result from a PbotApproval step
@stepOutput.field Output from a named step (via outputKey)

Template Interpolation

Use {{ }} for string interpolation inside property values:

json
{ "message": "Hello {{input.customer_name}}, your balance is ${{context.balance}}" }

Data Flow Example

flowchart LR subgraph "Step 1: Matcher" M["@input.invoices + @input.payments"] end subgraph "Step 2: Loop" L["@unmatched_invoices → @item"] end subgraph "Step 3: Approval" A["@investigation (from agent result_key)"] end M -->|"matched, unmatched_invoices"| L L -->|"investigation"| A

→ Full reference: Context Resolution


5. Agents

Agents are ReAct (Reasoning + Acting) loops — AI that thinks, uses tools, observes results, and iterates toward an objective. They operate within boundaries defined by the workflow spec.

json
{
  "type": "loop",
  "properties": {
    "mode": "react",
    "objective": "Investigate this unmatched invoice and recommend an action",
    "tools": [
      { "type": "action", "name": "lookup_erp_invoice" },
      { "type": "action", "name": "gmail_send" }
    ],
    "max_iterations": 10,
    "on_stuck": { "iterations": 3, "action": "escalate" },
    "result_key": "investigation"
  }
}

Governance Model

Every agent runs inside a cage defined by its spec:

Structural permissioning — only tools explicitly declared in tools are available. The agent cannot discover or invent capabilities.

Bounded iterationmax_iterations caps prevent runaway execution.

Stuck detectionon_stuck identifies when an agent loops without progress and triggers recovery (fail, retry with hint, or escalate to human).

Human escalation__pause_for_human__ lets the agent request human input when confidence is low. The human's decision becomes part of the reasoning trace.

Reasoning traces — every iteration captures thought, action, parameters, and observation. Full chain of reasoning, queryable and auditable.

Tool Declaration

Tools support two formats — string shorthand for simple references, and full object definitions for explicit parameter schemas:

json
{
  "tools": [
    { "type": "action", "name": "lookup_ticket" },
    { "type": "action", "name": "verify_identity" },
    { "type": "workflow", "id": "wf_escalation_review" }
  ]
}

Action tools reference registered actions by name — the resolver automatically fetches descriptions and parameters. Workflow tools reference workflows by ID, letting the agent trigger sub-workflows. Built-in tools (__complete__, __pause_for_human__, __store_memory__, __retrieve_memory__, __log_progress__) are always auto-injected.

Three Deployment Patterns

Pattern Agent Role Example
Agent as Step One step in a larger workflow Matcher finds exceptions → agent investigates them
Agent as Trigger Smart ingestion layer Agent classifies incoming document → triggers the right workflow
Agent as Orchestrator Coordinates multiple workflows Agent runs KYC, sanctions screening, and account setup in sequence

→ Full reference: Agents


6. Runs

A run is a single execution of a workflow. It captures everything: input, step outputs, agent reasoning traces, human decisions, timing, and final status.

bash
# Execute a workflow → get a run
curl -X POST http://localhost:3009/workflows/{id}/execute \
  -H "X-Org-Id: your-org" \
  -d '{ "invoices": [...], "payments": [...] }'
# → { "id": "run_abc123", "status": "running" }

# Check status
curl http://localhost:3009/runs/run_abc123/status \
  -H "X-Org-Id: your-org"

Run Statuses

Status Meaning
running Execution in progress
paused Waiting for human approval or form input
completed Successfully finished
failed Execution failed
condition_not_met Top-level condition evaluated to false

What's Captured

Every run persists: the full input payload, each step's output, all agent reasoning traces (thought → action → observation for every iteration), human approval decisions with reviewer identity and comments, and timestamps for every state transition. This is the audit trail — queryable, exportable, and persistent.

→ API reference: Run Status


How They Fit Together

A typical production deployment:

  1. Register actions — connect your ERP, CRM, databases, and communication tools
  2. Define a workflow — compose primitives and actions with conditional logic
  3. Execute — send data in, get a run back
  4. Monitor — poll status, handle approvals, read reasoning traces
  5. Audit — every decision has a paper trail
sequenceDiagram participant You participant Hyphen participant AI participant Human You->>Hyphen: POST /workflows/:id/execute Hyphen->>Hyphen: Step 1: Matcher (deterministic) Hyphen->>AI: Step 2: ReAct loop (bounded) AI->>Hyphen: __complete__ with answer Hyphen->>Human: Step 3: PbotApproval (pause) Human->>Hyphen: Approved Hyphen->>Hyphen: Step 4: Custom Table (log) Hyphen->>You: Run completed ✓

Continue building: Your First Workflow walks through creating a multi-step workflow with conditional branching. Your First Agent builds a standalone ReAct agent with custom tools.