Multi-Agent AI Coding System — Planner-Executor orchestrator for Claude CLI
Project description
x-ai
Multi-Agent AI Coding System — An orchestrator that coordinates two specialized AI agents (Planner and Executor) to autonomously analyze codebases, plan changes, implement code, and self-review with iterative quality improvement.
Table of Contents
What Problem Does x-ai Solve?
Coding with AI assistants today is a single-agent experience — you give one AI a prompt and hope it gets everything right on the first try. For complex tasks, this often fails because:
- No planning phase — The AI jumps straight into coding without analyzing the codebase
- No self-review — There's no quality gate; mistakes ship as-is
- No iterative improvement — If the result is poor, you manually re-prompt
x-ai solves this by splitting the work between two specialized agents with a feedback loop:
| Agent | Role |
|---|---|
| Planner | Reads the codebase, identifies relevant files, creates a detailed implementation plan with verification steps |
| Executor | Follows the plan step-by-step, writes code, runs verification (format, lint, tests) |
After execution, the Planner reviews the Executor's changes, scores them on 5 dimensions, and provides feedback. If the score is below a threshold, the loop repeats with the feedback incorporated — automatically, without human intervention.
User Request
│
▼
┌─────────┐ ┌──────────┐ ┌─────────┐
│ PLAN │────▶│ EXECUTE │────▶│ REVIEW │
│(Planner)│ │(Executor)│ │(Planner)│
└─────────┘ └──────────┘ └────┬────┘
▲ │
│ score < threshold │
└────────── feedback ────────────┘
│
score >= threshold
│
▼
✓ SUCCESS
Architecture
System Overview
x-ai/
├── x_ai_cli/ # Core Python package
│ ├── main.py # CLI entrypoint & argument parsing
│ ├── orchestrator.py # Pipeline controller (PLAN → EXECUTE → REVIEW)
│ ├── agent_runner.py # Tmux session management & Claude interaction
│ ├── models.py # Data models (tasks, results, feedback)
│ ├── config.py # Configuration & environment variables
│ ├── logger.py # Rich console logging
│ ├── tui/ # Textual-based interactive UI
│ │ ├── app.py # Main TUI application (XAITui, Screens)
│ │ └── widgets.py # Custom TUI components (ActionLog, etc.)
│ └── skills/ # Agent behavior definitions
│ ├── planner.md # Planner agent skill (plan + review)
│ └── executor.md # Executor agent skill (execute)
├── pyproject.toml
└── README.md
Component Responsibilities
Orchestrator (orchestrator.py)
The central controller that manages the pipeline loop:
- PLAN phase — Dispatches a
plantask to the Planner agent with the user request - EXECUTE phase — Sends the Planner's implementation plan to the Executor agent
- REVIEW phase — Asks the Planner to review the Executor's output and score it
- Quality gate — If score ≥ threshold → success; otherwise build feedback and loop
Agent Runner (agent_runner.py)
Manages Claude CLI instances via tmux sessions with file-based communication:
- Creates detached tmux sessions and launches Claude inside them
- Handles startup prompts automatically (bypass permissions, trust folder)
- Writes task files (
.task.md) and polls for result files (.result.md) - Never reads Claude's output from tmux — all communication is through files on disk
Skills (skills/)
Markdown files that define each agent's behavior, communication protocol, and output format. These are injected as context when launching an agent.
planner.md— Definesplan(analyze repo → create plan) andreview(score code changes on 5 dimensions: correctness, code quality, security, performance, maintainability)executor.md— Definesexecute(follow plan → implement code → run verification)
Models (models.py)
Dataclasses for structured communication between orchestrator and agents:
AgentTask— Task file with YAML frontmatter (type, instructions, plan, feedback)AgentResult— Result file parsed from agent output (status, score, files changed)ReviewResult— Planner's review with score and notesFeedback— Structured feedback for retry rounds (mandatory fixes, score gaps, errors)
Communication Protocol
All agent communication uses Markdown files with YAML frontmatter:
---
id: "uuid-here"
type: "plan"
work_dir: "/path/to/project"
round: 1
feedback: null
---
## Instructions
Your task description here...
Agents read .task.md files and write .result.md files to the same directory.
Scoring System
The Planner scores the Executor's work on 5 weighted dimensions:
| Dimension | Weight | Description |
|---|---|---|
| Correctness | 0.25 | Does the code meet requirements? |
| Code Quality | 0.20 | Readability, naming, structure, DRY |
| Security | 0.20 | Input validation, injection prevention |
| Performance | 0.15 | Algorithmic efficiency, resource usage |
| Maintainability | 0.20 | Modularity, testability, documentation |
The weighted average becomes the round's score. If it meets the threshold (default: 70), the pipeline succeeds.
Installation
Prerequisites
- Python 3.11+
- Claude CLI — installed and authenticated
- tmux — for managing agent sessions
Install from PyPI
pip install x-ai-orchestrator
Or with pipx (recommended — installs in isolated environment):
pipx install x-ai-orchestrator
After installation, the x-ai command is available globally:
x-ai --version
Install from Source
git clone https://github.com/manhpham90vn/x-ai.git
cd x-ai
pip install .
Usage
Run Modes
x-ai can be run in two distinct modes depending on your workflow preferences.
1. Interactive GUI Mode (TUI)
Launch the full-screen Textual interface to get complete insight into the execution process and provide prompts dynamically.
# Launch the interactive TUI (no arguments)
x-ai
# You can still pass configuration flags, e.g., to set the working directory
x-ai -d /path/to/project
2. Single-shot CLI Mode
Provide the prompt directly inline to bypass the TUI entirely. This mode streams logs straight to standard output and is ideal for quick fixes or scripting.
# Run in single-shot mode with a coding task
x-ai "Add JWT authentication to the Flask API" -d /path/to/project
# Short form for single-shot mode
x-ai "Fix the login bug" -d ./my-app
CLI Options
| Flag | Short | Default | Description |
|---|---|---|---|
prompt |
— | optional | The coding task to execute (omit for interactive UI) |
--work-dir |
-d |
. |
Working directory for the target project |
--max-rounds |
-r |
3 |
Maximum retry rounds before returning best-effort |
--threshold |
-t |
70.0 |
Quality threshold score (0–100) to accept a solution |
--planner-timeout |
— | 600 |
Planner agent timeout in seconds |
--executor-timeout |
— | 600 |
Executor agent timeout in seconds |
--verbose |
-v |
false |
Enable debug-level logging |
--version |
-V |
— | Show version and exit |
Examples
# Complex task with higher quality bar
x-ai "Refactor the database layer to use SQLAlchemy async sessions" \
-d /path/to/project \
--threshold 85 \
--max-rounds 5
# Quick fix with lower threshold
x-ai "Fix typo in README" -d ./my-repo -t 50 -r 1
# Verbose mode for debugging
x-ai "Add unit tests for the auth module" -d ./api -v
Environment Variables
All CLI options can also be set via environment variables:
| Variable | Default | Description |
|---|---|---|
XAI_CLAUDE_BIN |
claude |
Path to Claude CLI binary |
XAI_TMUX_BIN |
tmux |
Path to tmux binary |
XAI_WORK_DIR |
. |
Default working directory |
XAI_MAX_ROUNDS |
3 |
Maximum retry rounds |
XAI_QUALITY_THRESHOLD |
70.0 |
Quality threshold score |
XAI_PLANNER_TIMEOUT |
600 |
Planner agent timeout (seconds) |
XAI_EXECUTOR_TIMEOUT |
600 |
Executor agent timeout (seconds) |
XAI_VERBOSE |
false |
Enable verbose logging |
XAI_PROMPT_MARKER |
❯ |
Prompt marker for Claude readiness detection |
XAI_POLL_INTERVAL |
1.0 |
Filesystem polling interval (seconds) |
Interactive TUI
x-ai includes a rich, full-screen Terminal User Interface (TUI) built with Textual. To launch it, simply run x-ai without any arguments.
TUI Features:
- Real-time Logging: View orchestrator events, Planner/Executor state changes, and task outcomes in a dynamic log panel.
- Tmux Integration (
t): Presstto open a built-in viewer that shows the live, raw terminal output of the Claude agents running in their background tmux panes. - Settings Dialog (
c): Presscto configure pipeline settings (Threshold, Max Rounds, Working Directory) interactively before running a task. - Interactive Prompting: Type your coding task directly into the TUI and press Enter to kick off the planner-executor pipeline.
Single-Shot Output
x-ai also provides real-time progress via Rich console output when running a direct prompt:
╭──────────────────────────────────────────────╮
│ x-ai — Planner-Executor AI Coding System │
│ v0.4.0 │
╰──────────────────────────────────────────────╯
Prompt: Add JWT authentication...
Work dir: /path/to/project
Max rounds: 3
Mode: Planner-Executor
Threshold: 70.0
◆ Round 1/3
▶ PLAN — Planner analyzing codebase and creating plan (round 1)
⚙ claude:planner started task a1b2c3d4
⚙ claude:planner finished a1b2c3d4 → success
▶ EXECUTE — Executor implementing code (round 1)
⚙ claude:executor started task e5f6g7h8
⚙ claude:executor finished e5f6g7h8 → success
Executor completed — 4 file(s) changed
▶ REVIEW — Planner reviewing code changes (round 1)
Planner score: 85.0 (threshold: 70.0) ✓ PASS
Score 85.0 >= threshold 70.0 — pipeline complete ✓
┌─────────────┬──────────────────────┐
│ Status │ ✓ SUCCESS │
│ Rounds Used │ 1 │
│ Time │ 245.3s │
│ Files │ src/auth/token.py │
│ │ src/api/login.py │
│ │ tests/test_auth.py │
│ │ requirements.txt │
└─────────────┴──────────────────────┘
Task File Structure
Each run creates a structured directory under tasks/:
tasks/{run_id}/
├── round_1/
│ ├── planner/ # Plan phase output
│ │ ├── {id}.task.md
│ │ └── {id}.result.md
│ ├── executor/ # Execute phase output
│ │ ├── {id}.task.md
│ │ └── {id}.result.md
│ └── reviewer/ # Review phase output
│ ├── {id}.task.md
│ └── {id}.result.md
├── round_2/... # (if retry needed)
Development
Project Setup
# Clone and setup
git clone https://github.com/manhpham90vn/x-ai.git
cd x-ai
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
Code Quality
# Lint
ruff check x_ai_cli/
# Auto-fix lint issues
ruff check x_ai_cli/ --fix
# Format
ruff format x_ai_cli/
# Check formatting without changes
ruff format --check x_ai_cli/
# Type checking
mypy x_ai_cli/
Customizing Agent Behavior
Agent behavior is defined in skills/*.md. To customize:
- Edit
skills/planner.mdto change how the Planner analyzes code or scores solutions - Edit
skills/executor.mdto change how the Executor implements code or runs verification - Modify scoring weights in
orchestrator.py→run_planner_review()instructions
Adding a New Agent Role
- Create a new skill file in
skills/{role}.md - Call
self.runner.run_agent(task_file, role="{role}")in the orchestrator - The agent runner automatically loads
skills/{role}.mdas context
Key Design Decisions
- File-based communication — Agents read/write
.task.mdand.result.mdfiles instead of using stdout, avoiding tmux capture-pane reliability issues - Sequential execution — Planner and Executor run one at a time (not in parallel), ensuring the Executor always has the latest plan
- Tmux for process management only — Tmux is used solely for creating/managing Claude sessions and handling startup prompts, never for reading output
- Skill injection — Agent behavior is defined in external Markdown files, making it easy to iterate without code changes
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file x_ai_orchestrator-0.4.0.tar.gz.
File metadata
- Download URL: x_ai_orchestrator-0.4.0.tar.gz
- Upload date:
- Size: 311.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cbe12ec091eda9706c4e0eddb83184f5ecd30cf01f5707e4ac744029fdb6927
|
|
| MD5 |
e3977315dd9345ad1a3f3035a59335d9
|
|
| BLAKE2b-256 |
c4f316d2b43c2ec3b5eae0a3d71b9484da5a637ab7203f4ae75ad92ec08abeec
|
Provenance
The following attestation bundles were made for x_ai_orchestrator-0.4.0.tar.gz:
Publisher:
publish.yml on manhpham90vn/x-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
x_ai_orchestrator-0.4.0.tar.gz -
Subject digest:
2cbe12ec091eda9706c4e0eddb83184f5ecd30cf01f5707e4ac744029fdb6927 - Sigstore transparency entry: 1038987641
- Sigstore integration time:
-
Permalink:
manhpham90vn/x-ai@3e9a65678c501a0f30555b0990d359148bf10db7 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/manhpham90vn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3e9a65678c501a0f30555b0990d359148bf10db7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file x_ai_orchestrator-0.4.0-py3-none-any.whl.
File metadata
- Download URL: x_ai_orchestrator-0.4.0-py3-none-any.whl
- Upload date:
- Size: 37.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d38fc294143112046af6964792dbf7817a1d52a063b7abd3e22124f885f91c7
|
|
| MD5 |
f3772ea592d4593e76976c0c1c425b50
|
|
| BLAKE2b-256 |
a4cdfb2d29f0bed7fdce5fbc5b8020d0b9be1a1e4d27d6c530263f0fc6b6a93d
|
Provenance
The following attestation bundles were made for x_ai_orchestrator-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on manhpham90vn/x-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
x_ai_orchestrator-0.4.0-py3-none-any.whl -
Subject digest:
6d38fc294143112046af6964792dbf7817a1d52a063b7abd3e22124f885f91c7 - Sigstore transparency entry: 1038987703
- Sigstore integration time:
-
Permalink:
manhpham90vn/x-ai@3e9a65678c501a0f30555b0990d359148bf10db7 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/manhpham90vn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3e9a65678c501a0f30555b0990d359148bf10db7 -
Trigger Event:
release
-
Statement type: