Minimal Agent Harness built on LangGraph. Multi-provider, safety-guarded, memory-enabled.
- Multi-provider support (9 providers: Anthropic, OpenAI, DeepSeek, Kimi, Qwen, GLM, MiniMax, Xiaomi, Custom)
- 3-tier tool safety guard (auto-approve / always-confirm / keyword-check)
- Cross-session long-term memory (persisted to
memory.json) - Minimal 6-layer architecture (~500 lines total)
# 1. Install core dependencies
pip install -r requirements.txt
# For non-Anthropic providers, also install:
pip install langchain-openai
# 2. Edit .env — set your Provider and API Key
# 3. Run
python harness.pyTask: Write a Python script that prints Fibonacci numbers up to 100, then run it
[HARNESS] Step 1/10 — Agent thinking...
[HARNESS] Step 2/10 — Agent thinking...
=======================================================
FINAL RESPONSE
=======================================================
I wrote fib.py and ran it. Output: 1 1 2 3 5 8 13 21 34 55 89
=======================================================
Total steps used: 2/10
=======================================================
[HARNESS] Memory saved: User asked to write and run a Fibonacci script.
On the second run, MicroHarness automatically loads the previous session summary:
[HARNESS] Found 1 long-term memory record(s).
Last: 2024-01-15 — User asked to write and run a Fibonacci script...
Task: Improve the script from last time
[HARNESS] Step 1/10 — Agent thinking...
(Agent recalls previous session context from injected memory)
When the agent attempts to write code containing dangerous operations, the guard pauses and requests human confirmation:
[HARNESS] Step 1/10 — Agent thinking...
=======================================================
[HARNESS GUARD] 📝 WRITE OP
Tool : write_file
filename: cleanup.py
content : import shutil; shutil.rmtree('/tmp/sandbox')
=======================================================
Approve? (yes / no): no
❌ Rejected. Operation cancelled.
Edit .env to select your provider and supply the API key:
PROVIDER=anthropic
ANTHROPIC_API_KEY=your_key
MAIN_MODEL=claude-sonnet-4-20250514
MEMORY_MODEL=claude-haiku-4-5-20251001PROVIDER=deepseek
OPENAI_COMPATIBLE_API_KEY=your_key
MAIN_MODEL=deepseek-chat
MEMORY_MODEL=deepseek-chatPROVIDER=kimi
OPENAI_COMPATIBLE_API_KEY=your_key
MAIN_MODEL=moonshot-v1-8k
MEMORY_MODEL=moonshot-v1-8kPROVIDER=qwen
OPENAI_COMPATIBLE_API_KEY=your_key
MAIN_MODEL=qwen-plus
MEMORY_MODEL=qwen-turboPROVIDER=glm
OPENAI_COMPATIBLE_API_KEY=your_key
MAIN_MODEL=glm-4-air
MEMORY_MODEL=glm-4-flashPROVIDER=minimax
OPENAI_COMPATIBLE_API_KEY=your_key
MAIN_MODEL=abab6.5s-chat
MEMORY_MODEL=abab6.5s-chatPROVIDER=openai
OPENAI_COMPATIBLE_API_KEY=your_key
MAIN_MODEL=gpt-4o
MEMORY_MODEL=gpt-4o-miniPROVIDER=xiaomi
OPENAI_COMPATIBLE_API_KEY=your_key
MAIN_MODEL=your-model-name
MEMORY_MODEL=your-model-namePROVIDER=custom
OPENAI_COMPATIBLE_API_KEY=your_key
OPENAI_COMPATIBLE_BASE_URL=https://your-api-endpoint/v1
MAIN_MODEL=your-model-name
MEMORY_MODEL=your-model-name| Tool | Level | Behavior |
|---|---|---|
list_files |
AUTO_APPROVE | Automatically allowed |
read_file |
AUTO_APPROVE | Automatically allowed |
get_file_info |
AUTO_APPROVE | Automatically allowed |
write_file |
ALWAYS_CONFIRM | Always requires human approval |
delete_file |
ALWAYS_CONFIRM | Always requires human approval |
run_python |
KEYWORD_CHECK | Blocked if dangerous keywords detected |
| Layer | File | Responsibility |
|---|---|---|
| Config | config.py |
Reads .env, builds LLM instance by provider |
| Prompts | prompts.py |
System prompt + long-term memory injection |
| Tools | tools.py |
6 tools, sandboxed to /tmp/sandbox/ |
| Guard | guard.py |
3-tier classification, human confirmation |
| Lifecycle | harness.py |
MAX_STEPS, routing control |
| Memory | memory.py |
Cross-session persistence, memory.json |
This project is licensed under the MIT License.
When sharing or republishing this project or its content, please credit the source: jingw2/microharness.