Skip to main content

Multi-Agent Collaboration CLI with flock-based locking and event-driven workflow

Project description

Mai CLI

Multi-Agent Collaboration CLI — flock-based coordination, event-driven workflow, zero overhead.

Mai is a command-line tool that coordinates multiple AI agents working on a shared project. It provides atomic locking, queue-based issue routing, per-agent heartbeat timeouts, and an automated daily summary loop — all backed by a simple file-based store.


Features

  • Atomic flock locks — race-condition-free claim/complete cycles via POSIX fcntl
  • Queue-based routing — issues route to the right agent with configurable SLA per queue
  • Heartbeat-aware guardian — stale locks auto-release after heartbeat × 1.5 minutes
  • Event-driven daily summary — ordered turn-taking with idempotent trigger/collect
  • Async mirror.mai/ internal store syncs to async/ for human visibility
  • Configurable via JSON — all rules externalized to config.json; no code changes needed
  • Dual output format--format json for machine consumption, text for humans
  • Dry-run mode--dry-run previews every mutation without side effects

Installation

pip install mai-cli

Or install from source:

git clone https://github.com/yourname/mai-cli.git
cd mai-cli
pip install -e .

Quick Start

Step 1 — Initialize a project

mai project init MyProject

Step 2 — Create an issue

mai --project MyProject issue new programmer-questions "How should we handle input buffering?"

Step 3 — Have the assigned agent claim it

mai --project MyProject issue claim REQ-001

Step 4 — Mark it done

mai --project MyProject issue complete REQ-001 "Decision: ring buffer, 60Hz polling"

Step 5 — Inspect queues

mai --project MyProject queue check

Architecture

.mai/                        async/
├── queues/<queue>/  Issue files  <queue>/  Human-visible mirror
├── locks/           flock files  (internal only)
├── processing/      Active issues  <queue>/
├── decisions/       Conclusion logs  decisions/
├── history/         Audit logs  history/
├── events/          Daily-summary triggers  (internal only)
└── config.json      All collaboration rules

Lock protocol: When an agent claims an issue, Mai acquires an flock(2)-based file lock. The lock expires after heartbeat × 1.5 minutes if the agent fails to heartbeat. The lock guardian cron command automatically releases stale locks.

Daily summary flow: trigger → each agent write in order → collect merges all summaries into a single report.


Command Reference

Issue

mai issue new <queue> <title> [--ref REQ-XXX]
mai issue amend <issue-id> <remark>
mai issue claim <issue-id>
mai issue complete <issue-id> <conclusion>
mai issue list [queue]
mai issue show <issue-id>
mai issue escalate <issue-id>

Queue

mai queue check [queue] [--overdue]
mai queue blockers

Lock

mai lock check <issue-id>
mai lock force-release <issue-id>
mai lock guardian

Log

mai log history [--date YYYY-MM-DD] [--agent NAME]
mai log write <agent> <type> <summary> [status]

Daily Summary

mai daily-summary trigger
mai daily-summary write <agent> <content...>
mai daily-summary collect

Escalation

mai escalation gen <issue-id>

Bitable

mai bitable sync-status
mai bitable retry

Project

mai project init <project-name>

Configuration

Edit .mai/config.json in your project root:

{
  "queues": {
    "programmer-questions": {
      "handler": "designer",
      "sla_minutes": 120,
      "id_prefix": "REQ"
    }
  },
  "agents": {
    "programmer": { "heartbeat_minutes": 17 },
    "designer":   { "heartbeat_minutes": 29 }
  },
  "daily_summary_order": ["programmer", "designer", "architect", "narrative", "techartist"]
}

Legacy field compatibility

ownerhandler, sla_hourssla_minutes are automatically converted.


Supported Platforms

  • OS: Linux / macOS (POSIX required for flock)
  • Python: 3.8, 3.9, 3.10, 3.11, 3.12

License

MIT License

MIT License — see LICENSE for the full text.

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

mai_cli-1.1.1.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

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

mai_cli-1.1.1-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

Details for the file mai_cli-1.1.1.tar.gz.

File metadata

  • Download URL: mai_cli-1.1.1.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for mai_cli-1.1.1.tar.gz
Algorithm Hash digest
SHA256 e80102ba2781241875979b3d0e48dffccaa865c1dfc2acca7a3827f91c620970
MD5 387e40f8ee0c87532c584b95cfa60089
BLAKE2b-256 b89486831e0543652f42739053587d4ec711f360a76c87bd13036b6f2cf8c7ec

See more details on using hashes here.

File details

Details for the file mai_cli-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: mai_cli-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for mai_cli-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 17df8b98d5418e5c14e4686e80b3e122431029a25ea84a126c8e9737b39dd061
MD5 c7ca3b96b2dfcf233b9f9b7bab476f0d
BLAKE2b-256 19bb83d7b581e7af4a74df8dc802f7a241b6f2008e1912fd6bb887417bbd3b30

See more details on using hashes here.

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