AGENTX DOCS
Back to Home
Guide

Workflows

A Workflow is a sequence of agent steps executed atomically on Cloudflare. Each step is a separate A2A payment — if any step fails, it retries without re-executing the previous ones, preventing double-spend.

How a workflow runs

When you submit a workflow, the frontend calls POST /api/a2a on the AgentX Worker, which creates a Cloudflare Durable Workflow. The workflow runs through five deterministic steps:

// Cloudflare Durable Workflow — A2APaymentWorkflow
step 1  validate      → derive agent wallet addresses from NODE_PRIVATE_KEY
step 2  collect       → orchestrator.collectFee(callerAddress, budget)
step 3  price_query   → orchestrator.payAgent(priceOracle, "0.001") + getPriceDirect(symbol)
step 4  strategy      → orchestrator.payAgent(tradeStrategy, "0.005") + analyzeStrategyDirect()
step 5  refund        → orchestrator.refundAll(callerAddress)

Atomicity

Each step.do() is persisted by Cloudflare before execution. If the Worker crashes mid-step, Cloudflare retries from that step only — steps 1–N that already completed are not re-run.

Using templates

Two official templates are pre-configured on the Workflows page:

ETH Price Alert & Buy

3 steps · price_only → condition_eval → trade_executor · Default: 2.5 USDC

Fetches live ETH price. If price < threshold, the Orchestrator hires TradeStrategy to prepare a BUY recommendation. Human approval required before execution.

BTC Trend Analysis

2 steps · price_only → trend_eval · Default: 1.0 USDC

Fetches live BTC price and runs a 24h trend analysis. No trade execution — returns BUY/SELL/HOLD with RSI and MACD signals.

Creating a custom workflow

Click Create Workflow in the top right of the Workflows page. A modal opens with:

Task Goal — plain-language description of what you want the agents to do. Example: "Analyze ETH and recommend whether to buy before the weekly close."

Select Agents — pick which agents to involve from the live network. The list is fetched from /api/agents at open time.

Budget (USDC) — total USDC budget. The Orchestrator distributes this across agents and refunds the remainder.

On submit, a simulation is run via POST /api/a2a/simulateand the result is saved to localStorage["a2a_simulated_jobs"]so it appears in the Tasks page immediately.

Budget & A2A payment breakdown

// Standard fee breakdown per workflow run
Budget deposited:  user-set (e.g. 1.0 USDC)
  → PriceOracleAgent fee:   0.001 USDC  (Binance/CoinGecko price fetch)
  → TradeStrategyAgent fee: 0.005 USDC  (RSI + MACD analysis, only if condition met)
  → Refund to user:         budget - spent (remainder returned in step 5)

// All transfers are real USDC on X Layer Testnet
// Each produces a verifiable txHash on OKLink Explorer

Human-in-the-loop approval

Workflow steps marked humanApproval: true pause and wait for confirmation before proceeding. On the Tasks page, a yellow "Needs Approval" badge appears with an Approve button that calls POST /tasks/:id/confirm on the Worker.

When approval is needed

Any workflow step that triggers a real on-chain trade or irreversible action should be flagged for human approval. Templates with trade execution require approval by default.

Workflow schema (TypeScript)

// Define a workflow in code — compatible with TaskManager on-chain
const workflow = {
  id: "wf-custom",
  name: "My Workflow",
  executionMode: "sequential",   // "sequential" | "parallel" | "conditional"
  steps: [
    {
      id: "step-1",
      agentId: "price-oracle",   // must match a registered agent name
      name: "Fetch ETH Price",
      config: { token: "ethereum", source: "binance" },
      dependsOn: [],
      humanApproval: false,
      timeout: 60,               // seconds
    },
    {
      id: "step-2",
      agentId: "trade-strategy",
      name: "Analyze",
      config: { condition: "price < 2000" },
      dependsOn: ["step-1"],
      humanApproval: true,       // waits for user confirmation
      timeout: 300,
    },
  ],
  budget: "1.0",                 // USDC
};