MechaHarness
Python agent harness for hosts that compose inference safely — not a thin chat-client wrapper. Founding principles:
- Modular via dependency injection — pyiv ≥ 1.1
MechaHarnessConfig; hosts subclass and compose (no hand-wired harnesses / string registries) - Multi-model / lanes native — reason, judge, and media lanes;
Completion/Judgement/Generationoutcomes - Cost in the object model —
CostAccountanton the harness path so runs cannot quietly go AWOL on spend - EventLog telemetry built in — queryable lifecycle, inference, tools, cost, and access events on every run
Also: deny-by-default grants / CompoundPolicy, and host-extendable open
identity. Docs: https://rl337.org/mechaharness/
Install
pip install mechaharness
Requires Python 3.9+. Unreleased main:
pip install git+https://github.com/rl337/mechaharness.git
Quick start
# List backends / harness families
mechaharness backends
mechaharness families
# Local LM Studio (OpenAI-compatible)
mechaharness run "What is 2+2?" \
--backend lmstudio \
--family tool_loop \
--model local-model
# OpenAI
export MECHA_API_KEY=sk-...
mechaharness run "Hello" --backend openai --model gpt-4o-mini
# HTTP API
mechaharness serve --port 8080
curl -s http://127.0.0.1:8080/health
Environment variables use the MECHA_ prefix (MECHA_API_KEY, MECHA_INFERENCE_BACKEND, MECHA_MODEL, MECHA_BASE_URL, …).
Library usage
Non-DI (OpenAPI-shaped):
import asyncio
from mechaharness import RunRequest, run
async def main() -> None:
result = await run(RunRequest(prompt="What is 19 + 23?", backend="lmstudio"))
print(result.final_text)
asyncio.run(main())
DI (pyiv Config hooks):
from mechaharness.di import MechaHarnessConfig, get_injector
from mechaharness.harness.base import AbstractHarness
from mechaharness.harness.tool_loop import ToolLoopHarness
from mechaharness.inference.openai_compat import OpenAICompatStrategy
class MyConfig(MechaHarnessConfig):
def get_inference_class(self):
return OpenAICompatStrategy
def get_harness_class(self):
return ToolLoopHarness
injector = get_injector(MyConfig)
harness = injector.inject(AbstractHarness)
See Dependency injection.
Extending
Subclass InferenceStrategy (constructor takes Settings) and return it from get_inference_class(), or merge it into SettingsConfig.inference_classes(). Subclass AbstractHarness and return it from get_harness_class().
Development
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev,docs]"
./run_checks.sh
run_checks.sh is what CI runs: ruff, mypy, pytest, Sphinx, and CLI smoke. EventLog + cost without a GPU:
mechaharness run "What is 2+2?" --backend mock --family pass_through --model mock --json
Design notes
| Concern | Pattern | Why |
|---|---|---|
| Wiring | pyiv Config hooks | DI-first; hosts inject MechaHarness types |
| Provider I/O | Strategy | Swap cloud/local without touching agent logic |
| Agent loop | Template method hierarchy | Share turn accounting; specialize stop/tool rules per model family |
| Frontends | OpenAPI RunRequest / run() |
Same contract for CLI, HTTP, and non-DI Python |
| Bindings later | Pydantic + OpenAPI | Types stay serializable; API is the first non-Python client surface |
Metadata
Release files for mechaharness 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mechaharness-0.5.0.tar.gz | 227.9 kB | Without provenance | Details for mechaharness-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mechaharness-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for mechaharness-0.5.0-py3-none-any.whl |
Total release size: 468.1 kB
Release files / mechaharness-0.5.0.tar.gz
| Download URL | mechaharness-0.5.0.tar.gz |
|---|---|
| Size | 227.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eef07e22d0b89a5775cf6b918f7051d8c0a562c05660d527cd288d23b4d518ec
|
|
BLAKE2b-256 checksum How to use checksums |
58d3e96568464874e05df0c41b0d15104bc9edc472a27216f28fe1d42998cb34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / mechaharness-0.5.0-py3-none-any.whl
| Download URL | mechaharness-0.5.0-py3-none-any.whl |
|---|---|
| Size | 240.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
86e6547a97b28a241692c252aed3508b4ef1f804640f60dbbb4a1bc37b7b9f66
|
|
BLAKE2b-256 checksum How to use checksums |
f1231420adb8a6050f32a1106f69aeae3cc8df3942ec9caf5702c31a4d02ad10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for mechaharness 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.