Gas Town Multi-Agent Orchestration System

repository·main·Indexed 9 days ago

https://github.com/gastownhall/gastown

A multi-agent orchestration system for AI coding agents like Claude Code and GitHub Copilot. It provides a persistent, git-backed workspace management layer and a TOML-based workflow engine (formula package) to allow multiple agents to work on complex tasks without losing context. Includes the `gt` CLI for managing Towns and Rigs, and `gt-model-eval` for comparing LLM performance on patrol decision tasks.

Tokens
193K
Snippets
525
Records
809
Agent score
96%

What's inside Gas Town

  1. Overview of the Dolt Archive plugin

    main

    The dolt-archive plugin provides a three-layered offsite backup strategy to ensure production data is safely moved off the local machine:

    1. JSONL export: Creates human-readable, diffable snapshots of issues. This is considered the 'last-resort recovery layer' and should be maintained even if other layers fail.
    2. Git push: Commits the JSONL snapshots to a Git backup repository and pushes them to GitHub.
    3. Dolt push: Performs native Dolt replication to GitHub or DoltHub remotes.

    The plugin is configured with a cooldown of 1h and a timeout of 15m.

  2. Understand the Convoy Stage & Launch testing strategy

    main

    The Convoy Stage & Launch functionality is verified through a multi-tiered testing strategy designed to ensure DAG (Directed Acyclic Graph) integrity, correct wave computation, and reliable command execution.

    Testing is categorized into four main types:

    1. Unit Tests: Test pure logic (e.g., detectCycles, computeWaves, buildDAG) in isolation using in-memory data without external dependencies like Dolt or database stubs.
    2. Integration Tests (Stubbed): Test the full command flow (package cmd) using stubbed bd and gt binaries to simulate user stories and command-line interactions.
    3. Integration Tests (Real Store): Test DAG walking and wave computation against a real Dolt store (package convoy) to ensure compatibility with actual data persistence.
    4. Snapshot & Property Tests: Use snapshot tests to ensure stable console output (TUI/JSON) and property tests to prove invariants (like determinism and acyclicity) over randomized DAGs.
  3. Understand the Gas Town architecture and core concepts

    main

    Gas Town is a multi-agent orchestration system designed to coordinate AI coding agents (like Claude Code or GitHub Copilot) with persistent work tracking. It uses a hierarchical structure to manage complexity:

    • The Mayor 🎩: The primary AI coordinator (typically a Claude Code instance) that holds full context of the workspace. This is your starting point.
    • Town 🏘️: The root workspace directory (e.g., ~/gt/) containing all projects and configurations.
    • Rigs 🏗️: Project containers that wrap a git repository and manage associated agents.
    • Crew Members 👤: Your personal workspace within a specific rig for hands-on work.
    • Polecats 🦨: Ephemeral worker agents that have persistent identities and work histories.
    • Hooks 🪝: Git worktree-based persistent storage that ensures agent work survives crashes or restarts.
    • Convoys 🚚: Units of work tracking that bundle multiple 'beads'. Convoys labeled mountain include autonomous stall detection and smart skip logic.
    • Beads 📿: The underlying data format for the git-backed issue tracking system. 'Beads' and 'issues' are used interchangeably. Bead IDs follow a prefix + 5-character alphanumeric format (e.g., gt-abc12).
  4. Understand the Convoy Lifecycle and Implementation Status

    main

    The Convoy lifecycle is managed by a core manager that handles the flow of issues and operations.

    Current Implementation Status:

    • Core convoy manager: Fully implemented and tested (covering stories S-01 through S-18).
    • Planned Features (P2): Owner field for targeted notifications.
    • Planned Features (P3): Timeout/SLA tracking for deadline management.

    Key Components for Developers:

    • Convoy Operations: Handled via CheckConvoysForIssue and feedNextReadyIssue in internal/convoy/operations.go.
    • Daemon Management: The internal/daemon/convoy_manager.go manages the lifecycle within the daemon context.
    • Formula Execution: Convoy formulas are executed via executeConvoyFormula in internal/cmd/formula.go.
  5. Compare Gas Town with other agent orchestration frameworks

    main

    Gas Town's architecture is evaluated against industry standards like CrewAI, LangGraph, and OpenAI Agents SDK. Key differentiators include:

    • Role Definition: Uses named operational roles (Mayor, Witness, Polecat) with Role Beads and Agent Beads, whereas others use triads (role/goal/backstory) or graph nodes.
    • Task Definition: Uses Beads (atomic work items with ID, status, assignee) and Molecules (multi-step workflows). Other frameworks use Task classes or graph topology.
    • Persistence: Gas Town roles and identities are persistent (survive restarts via Agent Bead + GUPP), unlike most frameworks that are per-session or checkpoint-based.
    • Coordination: Uses a pull-based model via Hooks + GUPP and workflow graphs (Molecules). Others use explicit graph edges or sequential/hierarchical flows.
    • State Management: Uses Beads backed by a Dolt database with cell-level merging, allowing high parallelism without conflicts. Most others use typed state, memory, or conversation context.
    • Parallelism: Achieves high parallelism (20-30 polecats) using OS processes and Git worktrees, providing each worker with its own filesystem isolation.
  6. What is Minimum Viable Gas Town (MVGT)?

    main

    MVGT is a method for participating in the Wasteland federation without running the full Gas Town orchestrator. It allows any system capable of running SQL and pushing to a Dolt remote to join the federation.

    Participation is achieved by interacting with the commons schema (version 1.1), a Dolt database hosted at steveyegge/wl-commons. All interactions—registering rigs, claiming work, delivering results, and reviewing work—are performed via SQL operations against specific tables, which are then committed and pushed using Dolt's Git-like workflow.

  7. Understand Witness responsibilities in the Polecat lifecycle

    main

    The Witness is a monitoring component that manages the health of the polecat pool.

    What the Witness DOES:

    • Detects and nudges stalled polecats (unexpectedly stopped sessions).
    • Cleans up zombie polecats (sessions where gt done failed to complete cleanup).
    • Respawns crashed sessions.
    • Handles escalations from polecats that explicitly request help.

    What the Witness DOES NOT do:

    • Force session cycles (polecats manage this via gt handoff).
    • Interrupt a mid-step process unless it is truly stuck.
    • Reuse polecats that are in a done state while cleanup/MR state still exists.
  8. Understand the Certificate CN format for identity

    main

    The gt-proxy-server derives a Polecat's identity (<rig>/<name>) from the Common Name (CN) in its certificate.

    • Server CN: Must be gt-proxy-server.
    • Polecat client CN: Must follow the format gt-<rig>-<name>.

    To support hyphenated rig names, the server identifies the identity by finding the last hyphen in the string after the gt- prefix. This hyphen acts as the separator between the rig and the name.

    Example Parsing: If the CN is gt-my-rig-rust, the identity is parsed as rig=my-rig and name=rust (identity: my-rig/rust).

    CN: gt-my-rig-rust   →   rig=my-rig, name=rust, identity=my-rig/rust
  9. How Molecule Lifecycle Events Work

    main

    Molecules in Gastown follow a specific lifecycle, with each stage emitting a distinct OTel event:

    1. mol.cook: The formula is compiled into a proto. This is a prerequisite for creating a wisp.
    2. mol.wisp: The proto is instantiated as a live, ephemeral molecule instance called a 'wisp'. This event includes the wisp_root_id and the bead_id it is bonded to.
    3. mol.squash: The molecule execution completes and is collapsed into a digest. This event tracks done_steps vs total_steps.
    4. mol.burn: If a molecule is destroyed without creating a digest, a mol.burn event is emitted, recording how many descendant step beads were closed.
  10. How the `gt-proxy-server` and `gt-proxy-client` work

    main

    The gt-proxy-server (running on the host) and gt-proxy-client (running in the container) enable secure communication from a sandboxed container back to the host using mTLS.

    gt-proxy-server (Host)

    • Listens on a configured address (e.g., 0.0.0.0:9876).
    • Requires mTLS: client certificates must be signed by the GasTown CA.
    • CLI Relay Model: It forwards arguments to gt or bd on the host and streams stdout, stderr, and exitCode back to the client. It injects --identity <rig>/<name> based on the certificate's Common Name (CN).
    • It maintains an allowlist of permitted subcommands to prevent arbitrary shell execution.

    gt-proxy-client (Container)

    • Replaces the standard gt and bd binaries via symlinks.
    • Automatically detects and uses the proxy if the following environment variables are set:
      • GT_PROXY_URL
      • GT_PROXY_CERT
      • GT_PROXY_KEY
    • If these are not set, it falls back to normal local execution (backward compatibility).

    API Endpoint Example

    POST /v1/exec
      body:     {"argv": ["gt", "mail", "inbox", "--json"]}
      response: {"stdout": "...", "stderr": "...", "exitCode": 0}
  11. Understand the Polecat lifecycle and operating states

    main

    Polecats (agent workers) operate through a specific lifecycle of states. The standard 'happy path' follows a linear progression from IDLE to WORKING to DONE, where completed sessions are retired rather than reused to ensure clean state management.

    Operating States

    StateDescriptionTrigger
    WorkingActively executing assigned work. Session is alive and hooks are set.After gt sling
    IdleAvailable and safe to use for new assignments.Spawned or explicitly prepared
    DoneWork completed and session retired. Branch/MR evidence is preserved.After successful gt done
    StalledWork stopped unexpectedly (crash, timeout, or interruption). Requires Witness intervention.Interruption/Crash
    ZombieWork finished, but the session failed to exit during cleanup.Failed gt done

    The Happy Path Cycle

    1. IDLE: Polecat is available.
    2. gt sling: Assigns work, moving the polecat to WORKING.
    3. WORKING: Active session with hooks set.
    4. gt done: Signals completion, moving the polecat to DONE (session is killed, but metadata remains).
             ┌──────────┐
             │  IDLE    │──── gt sling
             └────┬─────┘
                  v
             ┌──────────┐
             │ WORKING  │<──── session active, hook set
             └────┬─────┘
                  │ gt done
                  v
             ┌──────────┐
             │  DONE    │──── branch/MR evidence preserved, session exits
             └──────────┘
  12. Manage accounts and quotas via keychain swapping

    main

    When rate limits are detected, GT rotates API credentials by swapping tokens in the system keychain (GT $\rightarrow$ Agent).

    Implementation Details:

    • Platform Support: This subsystem is Darwin-only (macOS). It is not supported on Linux or Windows.
    • Mechanism: Uses SwapKeychainCredential to backup the target credential, read the source, and write to the target. For OAuth, it swaps the oauthAccount field in .claude.json.
    • Requirement: Credential swapping requires a full session restart (killing the existing process and respawning the tmux pane).