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 Distribution

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

x2harness-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl (82.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file x2harness-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for x2harness-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 98ab106465de734d94e900cd8b6f9b8713ddbbf011eda27b473cc045cddf09f5
MD5 ab259c543072c65ec1f6b67d00f47ab0
BLAKE2b-256 5992bcd4e20547fe99e99407cbf3b19bef4a9258e7dae021ec7ff7d5c936d249

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

5 files

This release

0.1.0 This release

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