Skip to main content

Agent Mini

PyPI version CI Python 3.11+ License: MIT

A minimal, local-first AI agent you can actually understand and extend.

  • ~3,000 lines of Python — read the whole thing in an afternoon
  • Local-first — Ollama as default, OpenAI if you want cloud, or any OpenAI-compatible server
  • Zero frameworks — pure httpx + asyncio, no LangChain, no LiteLLM
  • Built-in tools — shell, files, web search, persistent memory
  • Vision — drop an image path or URL into any message; works on Ollama, OpenAI, and OpenAI-compatible providers
  • Extensible — drop a Python file in ~/.agent-mini/plugins/ and it's a tool
  • Small-model optimized — tier-scaled system prompt, token-aware context pruning, tool-call repair, and a task-eval harness to measure whether the tuning actually pays off

Quick Start

pip install agent-mini
agent-mini init
agent-mini chat

The init wizard walks you through picking a provider, model, and basic settings. It creates ~/.agent-mini/config.json — you're ready to chat.

Providers

Agent Mini ships with three providers. Set "provider" in your config:

Ollama (default) — Local Models

ollama pull llama3.1
{
  "provider": "ollama",
  "providers": {
    "ollama": {
      "baseUrl": "http://localhost:11434",
      "model": "llama3.1",
      "think": false
    }
  }
}

think controls thinking mode — false, true, or "low" / "medium" / "high".

OpenAI

{
  "provider": "openai",
  "providers": {
    "openai": {
      "apiKey": "sk-...",
      "model": "gpt-4o"
    }
  }
}

Local — Any OpenAI-Compatible Server

Works with LM Studio, vLLM, llama.cpp, text-generation-webui, etc.

{
  "provider": "local",
  "providers": {
    "local": {
      "baseUrl": "http://localhost:8080/v1",
      "apiKey": "no-key",
      "model": "my-model"
    }
  }
}

All providers support streaming and tool calling.


Tools

Available out of the box — no API keys needed:

Tool Description
shell_exec Run shell commands
read_file Read file contents
write_file Create / overwrite files
append_file Append to files
code_edit Find-and-replace in files
list_directory Browse filesystem
search_files Grep / ripgrep across files
web_search DuckDuckGo search (free, no key)
web_fetch Fetch a public URL as plain text (private/loopback hosts blocked)
memory_store Save to persistent memory
memory_recall Fuzzy search memory (TF-IDF)

Plugins

Extend with custom tools — drop a .py file in ~/.agent-mini/plugins/:

# ~/.agent-mini/plugins/timestamp.py
from datetime import datetime, timezone

TOOL_DEF = {
    "type": "function",
    "function": {
        "name": "get_timestamp",
        "description": "Get the current UTC timestamp.",
        "parameters": {"type": "object", "properties": {}, "required": []},
    },
}

async def handler(arguments: dict) -> str:
    return datetime.now(timezone.utc).isoformat()

Chat Commands

/clear              Reset conversation
/model <name>       Switch provider/model (e.g. ollama/llama3.1)
/tools              List available tools
/memory [query]     Browse or search memories
/status             Show config and token usage
/save [file]        Export conversation as Markdown
/sessions           List saved sessions
/load <id>          Resume a session
/help               Show commands

Multi-line input: wrap with """ or '''. Line continuation: end with \.


Telegram Gateway

  1. Create a bot via @BotFather
  2. Run agent-mini init and enable Telegram during setup, or edit config:
{
  "channels": {
    "telegram": {
      "enabled": true,
      "token": "YOUR_BOT_TOKEN",
      "allowFrom": ["YOUR_USER_ID"],
      "streamResponses": true
    }
  }
}
  1. agent-mini gateway

Sandbox & Security

Control tool access:

Level Description
unrestricted All tools, all paths
workspace All tools, paths restricted to workspace (default)
readonly Read-only — no shell, write, edit
{ "tools": { "sandboxLevel": "readonly" } }

Dangerous shell commands (rm -rf, sudo, mkfs, etc.) are blocked by default. Treat the shell blocklist as friction, not a boundary — a determined caller can bypass it, so don't run the agent in an untrusted context and expect the blocklist to save you.

web_fetch is guarded against basic SSRF: requests to localhost, loopback (::1), RFC-1918 private ranges, and link-local (including the cloud metadata endpoint 169.254.169.254) are refused, and the final URL is re-checked after every redirect. DNS rebinding can still bypass — use sandboxLevel: readonly if you need a stronger guarantee.


Sessions

Conversations auto-save after each turn. Resume:

agent-mini chat -s 20260307_143022

Or inside the REPL: /sessions to list, /load <id> to resume.


How It Works

Agent Mini is a ReAct loop — the LLM reasons, picks a tool, observes the result, and repeats until it has an answer.

Key design choices for small/local models:

  • Tier-scaled system prompt — tiny models get a compact rules block and no memory recall; larger tiers get the full descriptive prompt and recent context
  • Inline tool list<available_tools> block in the system prompt so small models can see tool names at a glance without inferring from the JSON schema
  • Token-aware context — estimates token usage and prunes old tool results when approaching the model's effective context window
  • Model tier classification — auto-detects tiny/small/medium/cloud (including large open-weight sizes like :32b, :70b, 8x7b) and adjusts context budgets, iteration limits, and output caps
  • Tool call repair — fixes malformed JSON from small models (trailing commas, single quotes, unquoted keys)
  • Loop detection — catches repeated identical tool calls and nudges the LLM to try a different approach
  • History summarization — compresses long conversations to stay within context
  • Task-eval harness — measures success rate, iterations, tokens, and JSON-repair fire-rate across model tiers so the tuning above is testable, not hand-waved

Configuration Reference

{
  "provider": "ollama",
  "providers": {
    "ollama": { "baseUrl": "http://localhost:11434", "model": "llama3.1", "think": false },
    "openai": { "apiKey": "", "model": "gpt-4o" },
    "local":  { "baseUrl": "http://localhost:8080/v1", "apiKey": "no-key", "model": "local-model" }
  },
  "agent": {
    "maxIterations": 20,
    "temperature": 0.7,
    "systemPrompt": ""
  },
  "channels": {
    "telegram": { "enabled": false, "token": "", "allowFrom": [], "streamResponses": true }
  },
  "tools": { "restrictToWorkspace": false, "sandboxLevel": "workspace", "blockedCommands": [] },
  "memory": { "enabled": true, "maxEntries": 1000 },
  "workspace": "~/.agent-mini/workspace"
}

Key paths:

  • Config: ~/.agent-mini/config.json
  • Workspace: ~/.agent-mini/workspace/
  • Memory: ~/.agent-mini/memory.json
  • Plugins: ~/.agent-mini/plugins/
  • Sessions: ~/.agent-mini/sessions/

CLI

Command Description
agent-mini init Interactive setup wizard
agent-mini chat Interactive chat
agent-mini chat -m "..." Single message
agent-mini chat --workspace <dir> Override the workspace for a single run (also honours AGENT_MINI_WORKSPACE)
agent-mini gateway Start Telegram bot
agent-mini status Show config status

Project Structure

src/agent_mini/
├── cli.py                  # CLI commands (Click)
├── config.py               # Typed config
├── bus.py                  # Message routing
├── sessions.py             # Session persistence
├── agent/
│   ├── loop.py             # ReAct agent loop
│   ├── context.py          # System prompt builder
│   ├── memory.py           # JSON memory + TF-IDF search
│   ├── tools.py            # Built-in tools + plugin loader
│   ├── token_estimator.py  # Token counting + model tiers
│   └── vision.py           # Image detection + encoding
├── providers/
│   ├── base.py             # Provider interface
│   ├── ollama.py           # Ollama
│   ├── openai.py           # OpenAI
│   └── local.py            # OpenAI-compatible
└── channels/
    ├── base.py             # Channel interface
    └── telegram.py         # Telegram bot

Development

git clone https://github.com/mohsinkaleem/agent-mini.git
cd agent-mini
uv sync --extra dev
uv run pytest tests/ -v
uv run ruff check src/ tests/

Task evals

The evals/ directory contains a small, framework-free task-eval harness that runs the agent end-to-end against real fixtures (refactor a codebase, fix a failing test, answer a codebase question, etc.). Use it to measure whether the small-model optimizations actually pay off:

python evals/run.py                        # run all tasks against config model
python evals/run.py --task refactor_rename # single task
python evals/run.py --compare results/*.json  # cross-tier comparison table

See evals/README.md for the full workflow.

See CONTRIBUTING.md for guidelines.

License

MIT

Download files

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

Source Distribution

agent_mini-0.3.0.tar.gz (67.2 kB view details)

Uploaded Source

Built Distribution

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

agent_mini-0.3.0-py3-none-any.whl (46.3 kB view details)

Uploaded Python 3

File details

Details for the file agent_mini-0.3.0.tar.gz.

File metadata

  • Download URL: agent_mini-0.3.0.tar.gz
  • Upload date:
  • Size: 67.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for agent_mini-0.3.0.tar.gz
Algorithm Hash digest
SHA256 cba4381ebb165bf8efe59dc2daa5d60a6f391e109ea17a8a45d08862dfb82dd2
MD5 f4e1ffbf4bbd433a1f54dc68a3d65b11
BLAKE2b-256 0c8d409b5a89dbc5c8b736aab3c51d2d5f7803ec3a997d66e62a2e7000ac696a

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_mini-0.3.0.tar.gz:

Publisher: publish.yml on mohsinkaleem/agent-mini

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_mini-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: agent_mini-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 46.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for agent_mini-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5361a15f007db8e16f49a610f8eac14a72015cf8ae9c98ca0a1fd24d5584268e
MD5 a0d88f36d5f8f4560264d5bae1f28d1d
BLAKE2b-256 debca6f6458638a7c7cfce20da499c85d53fa61eb5cb9d9616b4b53c7bee78a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_mini-0.3.0-py3-none-any.whl:

Publisher: publish.yml on mohsinkaleem/agent-mini

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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