x2harness (玄芯 Harness)
Production-grade Reference Architecture for Autonomous Coding Agents
The companion Python library for the book Coding Agents: Foundations, Architecture, Harnesses, and Enterprise Practice.
$$\text{Coding Agent} = \text{Foundation Model} + \text{Agent Harness}$$
x2harness provides a modular, zero-magic implementation of the Seven Subsystems that make autonomous coding agents reliable on production repositories.
The 7 Subsystems Architecture
- Model Policy Proposer (
x2harness.providers): Adapters for DeepSeek, Claude, GPT, Ollama (Qwen2.5-Coder, MiniCPM5), SGLang, and deterministic mock providers. - Context Assembler (
x2harness.context): AST skeletonization, PageRank repository maps, FastCDC content-defined chunking, and working set token budgeting. - Tool Dispatcher (
x2harness.tools): Typed JSON Schema registry, Model Context Protocol (MCP) client, and ring-buffer output truncation. - Execution Loop & Verifier (
x2harness.core&x2harness.verifier): Deterministic turn execution, 5-stage progressive verification, SBFL (Ochiai/$D^*$) fault localization, and reward-hacking guards. - Planning & Refactoring Engine (
x2harness.planner&x2harness.engine): Spec-to-DAG topological wave solver, dynamic plan repair, and Tree-sitter AST surgery. - Scale & Enterprise Concurrency (
x2harness.scale): Tarjan SCC condensation for cyclic dependency graphs, Test Impact Analysis (TIA), and ephemeral Git worktree pools. - Security, Policy & Telemetry (
x2harness.security&x2harness.telemetry): Zero-trust process/bwrap sandbox, non-bypassable policy gates, hierarchical JSON-L tracing, and inference unit economics.
Quickstart
Installation
# Install from PyPI
pip install x2harness
# Or install editable from repository
pip install -e .
Python API
from x2harness import AgentHarness
from x2harness.providers import OllamaProvider, OpenAICompatProvider
from x2harness.context import RepoMapAssembler
from x2harness.verifier import TestPipelineVerifier
from x2harness.tools import ToolRegistry, make_file_tools
# 1. Choose your model provider (cloud or local)
provider = OllamaProvider(model="qwen2.5-coder:1.5b")
# 2. Assemble the harness
harness = AgentHarness(
provider=provider,
context_assembler=RepoMapAssembler(repo_root="."),
tools=make_file_tools(workspace="."),
verifier=TestPipelineVerifier(test_command="pytest tests/"),
max_turns=10,
cost_budget_usd=0.50
)
# 3. Run autonomous task with deterministic closed-loop verification
result = harness.run(task="Fix the ZeroDivisionError in math_utils.py")
print(f"Status: {result.status.value}, Verified: {result.verified}")
Command-Line Interface (x2)
# Run agent on a task
x2 run --model ollama/qwen2.5-coder:1.5b --task "Fix broken test in tests/test_db.py"
# Inspect execution trace
x2 trace runs/trace-20260908.jsonl
# Run deterministic benchmark
x2 bench --suite minibench
License
Apache-2.0 License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 x2harness-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: x2harness-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 82.1 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98ab106465de734d94e900cd8b6f9b8713ddbbf011eda27b473cc045cddf09f5
|
|
| MD5 |
ab259c543072c65ec1f6b67d00f47ab0
|
|
| BLAKE2b-256 |
5992bcd4e20547fe99e99407cbf3b19bef4a9258e7dae021ec7ff7d5c936d249
|