Skip to main content

An exploration of making an agent sdk as lean as possible while being effective.

Project description

minimal-harness

Documentation: /docs

A lightweight Python agent harness for building LLM-powered agents with tool-calling support.

Latest version: 0.2.3

What This Project Is For

Minimal-harness is a lean framework for building agents that can call tools. It provides:

  • OpenAI-compatible API - Works with any OpenAI-compatible API provider
  • Tool system - Create tools via decorators; includes built-in tools (bash, file ops)
  • AsyncIterator events - Real-time async iteration for chunks, tool start/end, execution events
  • Conversation memory - Tracks token usage across interactions
  • ESC stop support - Gracefully stop LLM streaming and tool execution

Architecture

The framework uses an event-driven architecture with AsyncIterator-based event handling:

Agent (OpenAIAgent) → Internal Events → FrameworkClient → Client-Facing Events

Event flow:

async for event in agent.run(user_input=[{"type": "text", "text": "..."}]):
    if isinstance(event, LLMChunk):
        # handle chunk
    elif isinstance(event, ToolEnd):
        # handle tool result

How to Build an App

Project Structure

A typical app looks like this:

my-app/
├── cli.py          # Entry point
└── tools.py        # Your custom tools

1. Create Your Entry Point

import argparse
from minimal_harness import OpenAIAgent
from minimal_harness.client import FrameworkClient
from minimal_harness.client.events import (
    AgentStartEvent,
    AgentEndEvent,
    LLMChunkEvent,
    ToolStartEvent,
    ToolEndEvent,
)

def main():
    parser = argparse.ArgumentParser(description="My AI agent")
    parser.add_argument("--base-url", required=True)
    parser.add_argument("--api-key", required=True)
    parser.add_argument("--model", default="qwen3.5-27b")
    args = parser.parse_args()

    agent = OpenAIAgent(
        api_key=args.api_key,
        base_url=args.base_url,
        model=args.model,
    )
    client = FrameworkClient(agent)

    async def run():
        async for event in client.run(user_input=[{"type": "text", "text": "What files are in the current directory?"}]):
            if isinstance(event, AgentStartEvent):
                print(f"Agent starting...")
            elif isinstance(event, LLMChunkEvent):
                print(event.content, end="", flush=True)
            elif isinstance(event, ToolStartEvent):
                print(f"\n[Calling tool: {event.name}]")
            elif isinstance(event, ToolEndEvent):
                print(f"\n[Tool result: {event.result[:100]}...]")

    import asyncio
    asyncio.run(run())

if __name__ == "__main__":
    main()

2. Add Custom Tools

Use the @register_tool decorator to add your own tools:

from minimal_harness.tool.registration import register_tool

@register_tool(
    name="get_weather",
    description="Get weather for a location",
    parameters={
        "type": "object",
        "properties": {"location": {"type": "string"}},
        "required": ["location"],
    },
)
async def get_weather(location: str) -> str:
    return f"The weather in {location} is sunny."

The decorator auto-registers the tool. Just import it before running the agent.

3. Run

python cli.py --base-url https://api.openai.com/v1 --api-key sk-... --model gpt-4o

Or set environment variables:

export MH_BASE_URL=https://api.openai.com/v1
export MH_API_KEY=sk-...
export MH_MODEL=gpt-4o
python cli.py

Built-in Tools

Tool Description
bash Execute shell commands with timeout
read_file Read file contents with line range
create_file Create new files
patch_file Patch files (append, prepend, etc.)
delete_file Delete files

Event Types

Event Description
AgentStartEvent Agent execution started
AgentEndEvent Agent execution completed
LLMStartEvent LLM generation started
LLMChunkEvent LLM output chunk received
LLMEndEvent LLM generation completed
ExecutionStartEvent Tool execution started
ExecutionEndEvent Tool execution completed
ToolStartEvent Tool call started
ToolProgressEvent Tool intermediate progress
ToolEndEvent Tool call completed with result

Environment Variables

Variable Description
MH_BASE_URL API base URL
MH_API_KEY API key
MH_MODEL Model name (default: qwen3.5-27b)

Stop Mechanism

Press ESC during execution to gracefully stop LLM streaming and tool execution.

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

minimal_harness-0.2.3.post1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

minimal_harness-0.2.3.post1-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file minimal_harness-0.2.3.post1.tar.gz.

File metadata

  • Download URL: minimal_harness-0.2.3.post1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for minimal_harness-0.2.3.post1.tar.gz
Algorithm Hash digest
SHA256 4485855f04305bf3f9a765d8f25812ddea4db21cb417e4379574ccc12314087d
MD5 b812183b64f8a7ab576dc00f56cad4c4
BLAKE2b-256 16d8c5fb958e3121d1b52596f43da402cd78a3fdf85567ca3e21eda7161c1b8a

See more details on using hashes here.

File details

Details for the file minimal_harness-0.2.3.post1-py3-none-any.whl.

File metadata

  • Download URL: minimal_harness-0.2.3.post1-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for minimal_harness-0.2.3.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 6371e206e2ecb5de276d63c8985a31baed7ce693c81621eecb2a501de71497e2
MD5 6a20545a96bab65d2eb634bd12d9aad0
BLAKE2b-256 e7270dea7fc37c6dc4be1bbebd0a26537dc678ae4841f29b027c4d1b740bea5d

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