Skip to main content

Closed-loop AI agent workflows — phase-based execution with validation feedback

Project description

macrocycle

Closed-loop AI agent workflows.

Phase-based execution with validation feedback -- each phase is a control loop where the agent iterates until tests pass, linters are clean, or whatever your definition of done is.

Why?

AI agents are powerful but undisciplined. They rush to implement, skip analysis, and produce brittle code. Macrocycle fixes this by forcing your agent through structured phases with automated validation feedback loops.

The control loop is the product. Integrations (Sentry, GitHub, etc.) are left to the IDE or tools like Claude Code.

Installation

pipx install macrocycle

Quick Start

macrocycle init                               # Initialize .macrocycle/
macrocycle run fix "ValueError in process_request"  # Run workflow
macrocycle run fix "..." --until analyze      # Stop after a phase
macrocycle list                               # List workflows
macrocycle status                             # Latest run info

How It Works

Each workflow is a graph of phases. Each phase is a closed-loop control system:

Phase = Control Loop
  ┌──────────┐    ┌──────────┐    ┌──────────┐
  │ Setpoint │───>│Controller│───>│ Actuator  │
  │(success  │    │(Phase    │    │(AI Agent) │
  │ criteria)│    │Executor) │    └─────┬─────┘
  └──────────┘    └────┬─────┘          │
                       │           ┌────▼─────┐
                  ┌────▼─────┐     │  Plant   │
                  │  Error   │<────│(Codebase)│
                  │  Signal  │     └────┬─────┘
                  └──────────┘     ┌────▼─────┐
                       ^           │  Sensor  │
                       └───────────│(pytest,  │
                                   │ ruff...) │
                                   └──────────┘
  1. Execute steps (LLM prompts, shell commands)
  2. Validate via a shell command (the sensor)
  3. If validation fails, feed the error back into the next iteration
  4. Repeat until convergence or iteration budget exhausted
  5. Route to next phase

Workflow Definition

Workflows live in .macrocycle/workflows/ as JSON:

{
  "id": "fix",
  "name": "Fix Issue",
  "agent": {"engine": "cursor"},
  "phases": [
    {
      "id": "analyze",
      "steps": [{"id": "impact", "type": "llm", "prompt": "Analyze: {{INPUT}}"}],
      "on_complete": "implement"
    },
    {
      "id": "implement",
      "steps": [
        {"id": "code", "type": "llm", "prompt": "Implement: {{PHASE_OUTPUT:analyze}}"},
        {"id": "test", "type": "command", "command": "pytest --tb=short"}
      ],
      "validation": {"command": "pytest -q"},
      "max_iterations": 5,
      "context": ["analyze"],
      "on_complete": "review"
    },
    {
      "id": "review",
      "steps": [{"id": "review", "type": "llm", "prompt": "Review changes..."}],
      "validation": {"command": "pytest && ruff check ."},
      "max_iterations": 3,
      "context": ["implement"]
    }
  ]
}

Step types: llm (AI prompt) / command (shell command)

Variables: {{INPUT}} / {{PHASE_OUTPUT:id}} / {{STEP_OUTPUT:id}} / {{ITERATION}} / {{VALIDATION_OUTPUT}}

Agent config cascade: Workflow -> Phase -> Step (use cheaper models for iteration-heavy phases)

Artifacts

.macrocycle/
  workflows/fix.json
  runs/
    20260312_143052_fix/
      input.txt
      manifest.json        # Checkpoint for crash recovery
      analyze/output.md
      implement/output.md
      review/output.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

macrocycle-0.4.0.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

macrocycle-0.4.0-py3-none-any.whl (41.6 kB view details)

Uploaded Python 3

File details

Details for the file macrocycle-0.4.0.tar.gz.

File metadata

  • Download URL: macrocycle-0.4.0.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for macrocycle-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b928b539be81cdc9ac78efc81de7c18da929ddf86c8915777da795a7ebe2def0
MD5 4c8cd7308a417827d03de663e68e14c1
BLAKE2b-256 1a420d68fa48db96c12fa8440face863c0d9ac5c7e8f1b644035a93d5d038bdc

See more details on using hashes here.

Provenance

The following attestation bundles were made for macrocycle-0.4.0.tar.gz:

Publisher: publish.yml on MilanPecov/macrocycle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file macrocycle-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: macrocycle-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 41.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for macrocycle-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c8716999a430ec34973f7580bd408ee0e3fd16bbb6204328143ccff472aa90c
MD5 32b73fc29950153ff4fa51786091983b
BLAKE2b-256 8138ddfb07e582eb5d1b6153b4a90b7c5944dd5071aeee3fbce4d0a0ccbb9a11

See more details on using hashes here.

Provenance

The following attestation bundles were made for macrocycle-0.4.0-py3-none-any.whl:

Publisher: publish.yml on MilanPecov/macrocycle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page