Thin, backend-neutral agent-harness middlewares for LangChain / deepagents: loop guard, binary-read guard, tool-result budget.
Project description
able-harness-kit
Thin, backend-neutral agent-harness middlewares for LangChain / deepagents.
Three production-distilled patterns that compose on top of any LangChain
AgentMiddleware stack (including deepagents).
They don't replace your agent — they harden the loop around it.
pip install able-harness-kit # after the first PyPI release
# or, from a clone:
pip install -e .
Why
Most agent failures aren't "the model isn't smart enough" — they're the loop around the model lacking observation and control:
| Middleware | The failure it kills |
|---|---|
LoopGuardMiddleware |
The agent calls the same tool with the same args, making no progress, until it burns its budget. |
BinaryReadGuardMiddleware |
read_file hands the model a base64 block for a binary file; a lossy gateway drops it; the model claims it read the file and hallucinates. |
ToolResultBudgetMiddleware |
A 200 KB tool dump blows the context window and forces premature summarization. |
Each is backend-neutral (depends only on LangChain / LangGraph public types), small enough to read in one sitting, and composes with — rather than replaces — your existing harness.
Usage
from langchain.agents import create_agent # or deepagents.create_deep_agent
from able_harness_kit import (
LoopGuardMiddleware,
BinaryReadGuardMiddleware,
ToolResultBudgetMiddleware,
)
agent = create_agent(
model,
tools=[...],
middleware=[
BinaryReadGuardMiddleware(), # fail loud on binary read_file
ToolResultBudgetMiddleware(limit=16_000), # cap oversized tool results
LoopGuardMiddleware(warn_at=3, stop_at=5), # stop no-progress tool loops
],
)
LoopGuardMiddleware
Internally fingerprints each tool call (name + normalized args), counts
consecutive repeats, and short-circuits with a directive once stop_at is hit.
The counter resets the moment a different call is seen — interventions are
minimal and reversible. Pass on_signal= to observe loop signals without
changing control flow.
BinaryReadGuardMiddleware
Intercepts read_file results whose declared media type isn't text-like and
replaces the base64 payload with a structured error pointing at a dedicated
extractor (OCR / doc-to-markdown / type sniff). Turning a silent hallucination
into an explicit "use the right tool" nudge is strictly safer; the only cost is
one extra tool hop on the first attempt. Tool name, metadata keys, and the
directive are configurable; disable per-deployment with
BINARY_READ_GUARD_ENABLED=0.
ToolResultBudgetMiddleware
Caps each tool result at a character budget. Oversized results are offloaded via
a caller-supplied offload(content, tool_name) -> OffloadRef callback (bring
your own store — filesystem, blob, vector DB), or truncated with a retrieval
hint by default.
Background
These were distilled from a multi-agent product running on non-Anthropic model gateways (Qwen / GLM / DeepSeek), and from a controlled experiment across 5 models × 9 behavioral probes (harness on vs. off) that framed a harness as an entropy-reducing control system rather than overhead. The middlewares here are the reusable, framework-neutral core of that work.
License
MIT © Hanlin Li
Project details
Release history Release notifications | RSS feed
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 able_harness_kit-0.1.0.tar.gz.
File metadata
- Download URL: able_harness_kit-0.1.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98f7d333eb5192db6f7e6d81c01c044c202c2382c8b045aa7c8abdc4424310f8
|
|
| MD5 |
e89282f4e5e6e4cdb02b8b9dc5bfc03f
|
|
| BLAKE2b-256 |
bea9bb71a48d09020505f7670c3a54c7deb719c3e90edcc7c2aeb97a2bd7365a
|
File details
Details for the file able_harness_kit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: able_harness_kit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
067acc47b706b8d38c0d8816377ef67e6b8f3bd5fb293cc8e3bb2fea7157b64f
|
|
| MD5 |
9505979c70e246b0176a91cf231a17e7
|
|
| BLAKE2b-256 |
b345232266da93f82ee9869f989a3dd5f0c2d60aa99b7e7d40592e75d21a9f5a
|