Skip to main content

A minimal Agent Harness core — ReAct loop + tool registry + permission model

Project description

Mini Harness

A minimal Agent Harness core — the smallest complete implementation of an agent runtime. 1001 lines of Python. 49 tests. DeepSeek-first.

ReAct agent loop, streaming tool-call delta concatenation, 7-tool registry, 3-tier permission model, checkpoint/resume, step-level observability.

What is this?

The "brain + body" of an AI agent — the runtime shell that turns a raw LLM into a tool-using, permission-gated, controllable agent.

Does:

  • ReAct agent loop with streaming (think → act → observe → repeat)
  • 7 tools: read, write, edit, grep, glob, bash, fetch
  • Tool call delta concatenation (streamed arguments assembled by index)
  • 3-tier permission model (read / yn / auto) + hard-wall
  • Step trace: timing, token count, step counter per turn
  • Interrupt/Resume: Ctrl+C mid-run → rollback to checkpoint → continue/discard
  • Write verification: auto-read after write to prevent fake success

Does NOT:

  • Knowledge management, multi-agent, web dashboards, skill systems

Architecture

User Input
    │
    ▼
┌──────────────────────────────────────┐
│           Agent (loop.py)            │
│                                      │
│  save_checkpoint()                   │
│  async for delta in chat_stream():   │
│    yield text_delta  ← streaming     │
│    accumulate tool_call deltas       │
│  assemble response                   │
│  for each tool_call:                 │
│    permission gate ──────────────┐   │
│    execute handler (async)       │   │
│    result → messages ────────────┘   │
│  yield summary (steps/duration/tok)  │
└──────────────────────────────────────┘
    │            │               │
    ▼            ▼               ▼
┌─────────┐ ┌──────────┐ ┌──────────────┐
│ llm.py  │ │ tools.py │ │permissions.py│
│DeepSeek │ │ 7 tools  │ │ read/yn/auto │
│streaming│ │ unified  │ │ + hard-wall  │
│+ tokens │ │  async   │ │              │
└─────────┘ └──────────┘ └──────────────┘

Install

pip install mini-harness
# or dev:
pip install -e .

Quick Start

CLI

mini-harness

First run prompts for your DeepSeek API key (saved to ~/.mini-harness/config.toml).

> 列出当前目录的 Python 文件
  [1/15] glob · 0.8s · 45t
  [2/15] text · 0.3s · 89t
  — 2 steps · 1.1s · 134t
main.py
cli.py

Ctrl+C mid-run → [C]ontinue [D]iscard [Q]uit.

API

import asyncio
from harness import Agent, DeepSeekClient, Mode

async def main():
    client = DeepSeekClient(api_key="sk-...")
    agent = Agent(client, system_prompt="You are a helpful assistant.",
                  mode=Mode.AUTO)

    async for event in agent.run("List Python files in this project"):
        if event["type"] == "text_delta":
            print(event["text"], end="", flush=True)
        elif event["type"] == "tool_call":
            print(f"\n  [{event['step']}/{event['max_steps']}] {event['tool']}")
        elif event["type"] == "summary":
            print(f"\n{event['steps']} steps · "
                  f"{event['duration_ms']/1000:.1f}s · {event['tokens']}t")

asyncio.run(main())

Event Reference

Event Fields When
text_delta text Per-chunk during streaming
tool_call tool, params, step, max_steps, duration_ms, tokens Before tool execution
tool_result tool, success, output, step After tool execution
step_end step, kind, duration_ms, tokens Text-only responses
summary steps, duration_ms, tokens End of turn
interrupted step, message Ctrl+C caught
error message API failure, max steps

Permission Modes

Mode Read Write Bash Hard-wall bypass?
Read No
YN Prompt Prompt No
Auto No

Hard-wall (permanently blocked): rm -rf, sudo, git push --force, paths: raw/, agents/, archive/, /etc/, /proc/, /sys/.

Project Structure

mini-harness/
├── harness/
│   ├── __init__.py        # Public API
│   ├── cli.py             # REPL with interrupt dialog
│   ├── loop.py            # Agent Loop + streaming + checkpoint
│   ├── llm.py             # DeepSeek API (streaming + usage)
│   ├── tools.py           # 7 tools + registry + async handlers
│   └── permissions.py     # 3-tier + hard-wall
├── tests/                 # 49 tests
├── README.md
├── CHANGELOG.md
└── pyproject.toml

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mini_harness-1.0.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

mini_harness-1.0.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file mini_harness-1.0.0.tar.gz.

File metadata

  • Download URL: mini_harness-1.0.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for mini_harness-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7d53a790f90abed4bf692045e8dc7826e22f0b5b67a96ad5d3b674b15386cd53
MD5 0286b7f094c526bc1c705b8d242f07c7
BLAKE2b-256 9c0e91b363d0bc5c5178fcfa1039e2043cc53a5de3c539bc4c70ac06f8b62973

See more details on using hashes here.

File details

Details for the file mini_harness-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mini_harness-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for mini_harness-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 254851909e038e810514d0708adc37e3c6c5b8dabd7e251eae45e435698dace7
MD5 34277d839f1814bca81114b63ee3f823
BLAKE2b-256 e0d301c39cc57d4c9df6f8f8dbe3b46c8cdfe1bdc91da79ff9b3254918ea7458

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page