Skip to main content

Workflows

Workflows allow you to orchestrate multiple agents into coordinated pipelines. Agents can work sequentially, in parallel, or with conditional logic.

Workflow Engine

The workflow engine (openfang-kernel/src/workflow.rs) supports:
  • Sequential execution - Run agents one after another
  • Parallel execution - Run multiple agents concurrently
  • Conditional branching - Route based on agent outputs
  • Error handling - Retry logic and fallback paths
  • State passing - Share data between workflow steps

Creating a Workflow

1

Define workflow structure

Create a workflow.json file:
{
  "name": "research-and-summarize",
  "description": "Research a topic and create a summary",
  "steps": [
    {
      "id": "research",
      "agent": "researcher",
      "input": "{{workflow.input}}",
      "output_key": "research_results"
    },
    {
      "id": "summarize",
      "agent": "writer",
      "input": "Summarize this research: {{steps.research.output}}",
      "depends_on": ["research"]
    }
  ]
}
2

Register the workflow

openfang workflow create workflow.json
Output:
Workflow registered: research-and-summarize
ID: wf_a1b2c3d4
3

Run the workflow

openfang workflow run research-and-summarize "AI agent frameworks"
4

Check status

openfang workflow status wf_a1b2c3d4

Workflow Patterns

Sequential Pipeline

{
  "steps": [
    {"id": "step1", "agent": "agent1", "input": "..."},
    {"id": "step2", "agent": "agent2", "input": "{{steps.step1.output}}", "depends_on": ["step1"]},
    {"id": "step3", "agent": "agent3", "input": "{{steps.step2.output}}", "depends_on": ["step2"]}
  ]
}

Parallel Execution

{
  "steps": [
    {"id": "research-web", "agent": "researcher", "input": "topic: {{workflow.input}}"},
    {"id": "research-db", "agent": "analyst", "input": "query database for {{workflow.input}}"},
    {"id": "merge", "agent": "writer", "input": "Combine: {{steps.research-web.output}} and {{steps.research-db.output}}", "depends_on": ["research-web", "research-db"]}
  ]
}
Steps without depends_on run in parallel.

Conditional Branching

{
  "steps": [
    {"id": "classify", "agent": "classifier", "input": "{{workflow.input}}"},
    {"id": "technical", "agent": "coder", "input": "{{workflow.input}}", "depends_on": ["classify"], "condition": "{{steps.classify.category}} == 'technical'"},
    {"id": "business", "agent": "analyst", "input": "{{workflow.input}}", "depends_on": ["classify"], "condition": "{{steps.classify.category}} == 'business'"}
  ]
}

Variable Substitution

Workflows support template variables:
VariableDescription
{{workflow.input}}Input provided when running the workflow
{{steps.step_id.output}}Output from a previous step
{{steps.step_id.status}}Status of a previous step (success/failure)
{{env.VAR_NAME}}Environment variable

Error Handling

{
  "steps": [
    {
      "id": "risky-operation",
      "agent": "agent1",
      "input": "...",
      "retry": {
        "max_attempts": 3,
        "backoff": "exponential"
      },
      "on_failure": {
        "action": "continue",
        "fallback_step": "safe-alternative"
      }
    },
    {
      "id": "safe-alternative",
      "agent": "agent2",
      "input": "Fallback for {{steps.risky-operation.input}}"
    }
  ]
}

Triggers

Automate workflow execution with triggers:
# Run workflow on schedule
openfang trigger create \
  --type schedule \
  --cron "0 9 * * *" \
  --workflow research-and-summarize \
  --input "daily tech news"

# Run workflow on event
openfang trigger create \
  --type event \
  --pattern "agent.spawned" \
  --workflow onboarding-flow

API Usage

Create Workflow

curl -X POST http://localhost:4200/api/workflows \
  -H "Content-Type: application/json" \
  -d @workflow.json

Run Workflow

curl -X POST http://localhost:4200/api/workflows/{id}/run \
  -H "Content-Type: application/json" \
  -d '{"input": "AI trends 2026"}'

Get Status

curl http://localhost:4200/api/workflows/{id}/status
Response:
{
  "id": "wf_a1b2c3d4",
  "name": "research-and-summarize",
  "status": "running",
  "current_step": "summarize",
  "steps": [
    {"id": "research", "status": "completed", "output": "..."},
    {"id": "summarize", "status": "running"}
  ]
}

Best Practices

Begin with 2-3 step workflows before building complex pipelines.
IDs like research-web are clearer than step1.
Always configure retry logic and fallback steps for critical operations.
Use openfang workflow list to track active workflows.
Ensure each agent works correctly before chaining them.

Next Steps

Triggers

Automate workflow execution

API Reference

Complete workflow API documentation

Build docs developers (and LLMs) love