Antfarm

repository·main·Indexed 22 days ago

https://github.com/snarktank/antfarm

A framework for building and running specialized AI agent teams in OpenClaw. Antfarm enables reliable, repeatable workflows for tasks such as feature development, security auditing, and bug fixing using a multi-agent approach. It features a TypeScript CLI, a web dashboard for real-time monitoring, and supports custom workflow definitions via YAML and Markdown with deterministic steps, agent verification loops, and role-based tool access.

Tokens
9.5K
Snippets
20
Records
62
Agent score
82%

What's inside antfarm

  1. How Antfarm agent workflows work

    main

    Antfarm uses deterministic workflows where specialized agents (e.g., planner, developer, verifier) work in a specific sequence.

    Core Principles:

    • Deterministic workflows: Steps follow a strict, repeatable order.
    • Agent Verification: Agents verify each other's work (e.g., a developer does not mark their own homework; a separate verifier checks against acceptance criteria).
    • Fresh Context: Each agent runs in a fresh session with clean context to prevent context window bloat and hallucinations. Memory is persisted via git history and progress files.
    • Retry and Escalate: Failed steps retry automatically. If retries are exhausted, the system escalates to the user.

    Architecture: Antfarm is a TypeScript CLI built on the Ralph loop. It uses YAML for definitions, SQLite for state tracking, and cron for orchestration. It requires no external infrastructure like Redis or Kafka.

  2. Use template variables for step communication

    main

    Steps communicate by passing KEY: value pairs in their output. These pairs are automatically converted into lowercased variables available to subsequent steps.

    Available Variables

    • {{task}}: The original task string passed to workflow run (always available).
    • {{prev_output}}: Variables from prior steps.
    • {{key_name}}: Any KEY: value pair returned by a previous step (e.g., if an agent returns REPO: /path, use {{repo}}).

    Example Communication

    If an agent replies with:

    STATUS: done
    REPO: /path/to/repo
    BRANCH: feature/my-thing

    Later steps can reference {{repo}} and {{branch}}.

  3. Understand Agent Roles and tool access

    main

    Roles determine the level of access an agent has to the environment during execution. Use these roles to enforce security and integrity (e.g., preventing a verifier from modifying code).

    RoleAccess
    analysisRead-only code exploration
    codingFull read/write/exec for implementation
    verificationRead + exec but NO write — preserves verification integrity
    testingRead + exec + browser/web for E2E testing, NO write
    prRead + exec only — runs gh pr create
    scanningRead + exec + web search for CVE lookups, NO write

    Note: Each role has a default timeout (20 or 30 min). Use timeoutSeconds in the agent definition to override this.

  4. How Antfarm Workflows Operate

    main

    Antfarm uses a decentralized, autonomous agent model rather than a central orchestrator.

    Core Mechanics:

    • Autonomous Agents: Specialized agents (planner, developer, verifier, tester, reviewer) execute steps by polling a shared SQLite database via staggered cron jobs (typically every 15 minutes).
    • Step Lifecycle: An agent claims a pending step, performs the work, marks it complete, and advances the workflow to the next step.
    • Context Passing: Information is passed between steps using KEY: value pairs in the agent's output.

    Force-Triggering Agents: If you do not want to wait for the 15-minute cron cycle, you can manually trigger an agent using the cron tool with action: "run" and the agent's job ID. Agent job IDs follow the pattern antfarm/<workflow-id>/<agent-id>.

  5. Create a custom Antfarm workflow

    main

    To create a custom workflow, organize your files into a specific directory structure under workflows/. Each workflow requires a workflow.yml file and a directory of agents/, where each agent has its own configuration files (AGENTS.md, SOUL.md, and IDENTITY.md).

    Directory Structure

    workflows/
    └── my-workflow/
        ├── workflow.yml          # Workflow definition (required)
        └── agents/
            ├── agent-a/
            │   ├── AGENTS.md     # Agent instructions
            │   ├── SOUL.md       # Agent persona
            │   └── IDENTITY.md   # Agent identity
            └── agent-b/
                ├── AGENTS.md
                ├── SOUL.md
                └── IDENTITY.md
    workflows/
    └── my-workflow/
        ├── workflow.yml
        └── agents/
            ├── agent-a/
            │   ├── AGENTS.md
            │   ├── SOUL.md
            │   └── IDENTITY.md
            └── agent-b/
                ├── AGENTS.md
                ├── SOUL.md
                └── IDENTITY.md
  6. Run an Antfarm Workflow

    main

    To start a multi-agent workflow, use the workflow run command. You must provide the <workflow-id> and a <detailed task with acceptance criteria>.

    Important: The task string is the contract between you and the agents. To ensure high-quality results, your task string should always include:

    1. Specific details on what to build or fix.
    2. Key technical details and constraints.
    3. Explicit acceptance criteria (e.g., using checkboxes).

    It is recommended to have the user confirm the plan and acceptance criteria before initiating the run.

    # Start a run
    node ~/.openclaw/workspace/antfarm/dist/cli/cli.js workflow run <workflow-id> "<detailed task with acceptance criteria>"
  7. Implement Verification Loops

    main

    You can create a loop where a verification step checks work and, if it fails, triggers a retry of a previous implementation step.

    When a verification step fails with STATUS: retry, the implementation step is re-run. The variable {{verify_feedback}} is automatically populated with the content from the verifier's ISSUES: output.

    Example Verification Loop

    - id: verify
      agent: verifier
      input: |
        Check the work...
        Reply STATUS: done or STATUS: retry with ISSUES.
      expects: "STATUS: done"
      on_fail:
        retry_step: implement
        max_retries: 3
        on_exhausted:
          escalate_to: human
  8. Monitor and Manage Workflow Runs

    main

    Once a workflow is running, you can monitor its progress, list all active or past runs, and manage failures using the following commands:

    • Check status: Use workflow status with a task or run-id prefix to see the current state.
    • List runs: Use workflow runs to see a history of all runs.
    • Resume failed runs: If a run fails, you can use workflow resume <run-id> to restart the process from the specific step that failed.
    • View logs: Use logs [lines] to inspect the output of the agents.
    # Check a run
    node ~/.openclaw/workspace/antfarm/dist/cli/cli.js workflow status "<task or run-id prefix>"
    
    # List all runs
    node ~/.openclaw/workspace/antfarm/dist/cli/cli.js workflow runs
    
    # Resume a failed run from the failed step
    node ~/.openclaw/workspace/antfarm/dist/cli/cli.js workflow resume <run-id>
    
    # View logs
    node ~/.openclaw/workspace/antfarm/dist/cli/cli.js logs [lines]
  9. Create a custom Antfarm workflow

    main

    You can build custom agent teams by defining agents, steps, retry logic, and verification gates in YAML and Markdown. Each agent is assigned a persona, a workspace, and strict acceptance criteria.

    Example workflow definition:

    id: my-workflow
    name: My Custom Workflow
    agents:
      - id: researcher
        name: Researcher
        workspace:
          files:
            AGENTS.md: agents/researcher/AGENTS.md
    
    steps:
      - id: research
        agent: researcher
        input: |
          Research {{task}} and report findings.
          Reply with STATUS: done and FINDINGS: ...
        expects: "STATUS: done"

    For a full guide, see docs/creating-workflows.md.

  10. Install and Uninstall Antfarm Workflows

    main

    Antfarm workflows can be installed or uninstalled globally or individually.

    To install all workflows (which creates the necessary agents and starts the dashboard), use the install command. To perform a full uninstall of all workflows, agents, cron jobs, the database, and the dashboard, use the uninstall command. Use the --force flag to ensure a complete removal.

    You can also manage workflows individually using the workflow subcommands.

    # Install all workflows (creates agents + starts dashboard)
    node ~/.openclaw/workspace/antfarm/dist/cli/cli.js install
    
    # Full uninstall (workflows, agents, crons, DB, dashboard)
    node ~/.openclaw/workspace/antfarm/dist/cli/cli.js uninstall [--force]
    
    # Install/uninstall individual workflows
    node ~/.openclaw/workspace/antfarm/dist/cli/cli.js workflow install <name>
    node ~/.openclaw/workspace/antfarm/dist/cli/cli.js workflow uninstall <name>
    node ~/.openclaw/workspace/antfarm/dist/cli/cli.js workflow uninstall --all [--force]
  11. Install Antfarm

    main

    Antfarm is installed from GitHub, not the npm registry. To install, run the following command in your terminal:

    curl -fsSL https://raw.githubusercontent.com/snarktank/antfarm/v0.5.1/scripts/install.sh | bash

    If you are using an OpenClaw agent, you can simply instruct it: "install github.com/snarktank/antfarm".

    Requirements:

    • Node.js >= 22: If you encounter a node:sqlite error, ensure you are using a real Node.js 22+ installation rather than Bun's node wrapper.
    • OpenClaw v2026.2.9+: Antfarm uses cron jobs for orchestration. If using an older version, it will fall back to the openclaw CLI.
    • gh CLI: Required for steps involving Pull Request (PR) creation.