Skip to main content

x2harness (玄心 Harness)

Production-grade Reference Architecture for Autonomous Coding Agents

License Python

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

  1. Model Policy Proposer (x2harness.providers): Adapters for DeepSeek, Claude, GPT, Ollama (Qwen2.5-Coder, MiniCPM5), SGLang, and deterministic mock providers.
  2. Context Assembler (x2harness.context): AST skeletonization, PageRank repository maps, FastCDC content-defined chunking, and working set token budgeting.
  3. Tool Dispatcher (x2harness.tools): Typed JSON Schema registry, Model Context Protocol (MCP) client, and ring-buffer output truncation.
  4. Execution Loop & Verifier (x2harness.core & x2harness.verifier): Deterministic turn execution, 5-stage progressive verification, SBFL (Ochiai/$D^*$) fault localization, and reward-hacking guards.
  5. Planning & Refactoring Engine (x2harness.planner & x2harness.engine): Spec-to-DAG topological wave solver, dynamic plan repair, and Tree-sitter AST surgery.
  6. Scale & Enterprise Concurrency (x2harness.scale): Tarjan SCC condensation for cyclic dependency graphs, Test Impact Analysis (TIA), and ephemeral Git worktree pools.
  7. 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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

x2harness-0.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (98.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

x2harness-0.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (85.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

x2harness-0.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (99.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

x2harness-0.1.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (76.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

x2harness-0.1.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (75.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file x2harness-0.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for x2harness-0.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 944184185c9f4912dc99c95f609b06385a61f09288986dc4b396b83550caa841
MD5 c34db161b84f6750315b8fe8c34980ae
BLAKE2b-256 cec39bf399621c29395bf24036548a49abf0ca311c0a46e502a5e3f8b2b5d6b1

See more details on using hashes here.

File details

Details for the file x2harness-0.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for x2harness-0.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1bc32e0d0bb78c7a81c7ed2454ad14531456718796ed7b8e06ecf0ca53dab1fa
MD5 2754fbe16eace94b2e9df0e1c2d71de0
BLAKE2b-256 185fd0953da3a3b199b00c664009ca5fff612350b7a90876a7c337d8dd99406d

See more details on using hashes here.

File details

Details for the file x2harness-0.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for x2harness-0.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bf43972eb1feb9d3e3d7038c3075425fb93b18e0275091d7d1acd74f58a64adb
MD5 e763c65ad9770f7bd24f4ad7ada70c29
BLAKE2b-256 657e9527dec3412af16a395aeed21f798b7337e5ebaf5814ef834bf3c914ed56

See more details on using hashes here.

File details

Details for the file x2harness-0.1.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for x2harness-0.1.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 95a91361bffbe8e879a9b4abdc474aa921338106001cae41cbdb54a6b6bd54d3
MD5 0814ef257ed167d3077a1f093be30743
BLAKE2b-256 452ef7a586307859e689acc630941e2d0e9cd1f6b627d6c6271e02c73b4cd221

See more details on using hashes here.

File details

Details for the file x2harness-0.1.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for x2harness-0.1.1-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 122d16ecd7ed355adf2ed236536bf5f80413cfd81b0f900f93da45b76f3b3a05
MD5 4cfe7e8366527c844e80d5464c7debd8
BLAKE2b-256 86726d0c06a453d62c026cb9442ad59624378eb5c3fada2a6688307d7ee5a462

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

5 files

0.1.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page