Skip to main content

A minimal AI coding agent — built from scratch for learning

Project description

mini-pi

PyPI version Python

A minimal AI coding agent, built from scratch for learning how AI coding agents work.

Inspired by pi.

Architecture

mini-pi/
├── main.py                      # Entry point
├── pyproject.toml                # Project config & dependencies
├── AGENTS.md                     # Project memory (for AI agents)
├── docs/
│   └── ROADMAP.md               # 7-phase development plan
└── src/mini_pi/
    ├── types.py                 # Core type definitions (messages, tools, events)
    ├── llm/
    │   └── client.py            # Anthropic LLM client with streaming & tool calling
    ├── tools/
    │   ├── base.py              # Tool base class & registry
    │   ├── read.py              # Read files (text & images)
    │   ├── bash.py              # Execute shell commands
    │   ├── write.py             # Create/overwrite files
    │   └── edit.py              # Precise text replacement editing
    ├── agent/
    │   └── loop.py              # Core agent loop (LLM ↔ tools)
    └── cli.py                   # CLI entry point

Components

1. Types (types.py)

Core data structures: Content blocks (text, image, thinking, tool_call, tool_result), Messages (User, Assistant, ToolResult), Tool definitions with JSON Schema, Usage tracking.

2. LLM Client (llm/client.py)

  • Wraps Anthropic's API with streaming support
  • Converts internal message format to Anthropic's format
  • Handles tool call streaming (accumulates partial JSON)
  • Tracks token usage

3. Tools (tools/)

  • read: Read files (text with offset/limit, images as base64)
  • bash: Execute shell commands with timeout & output truncation
  • write: Create/overwrite files (auto-creates parent dirs)
  • edit: Precise text replacement with validation (no-overlap, uniqueness checks)

4. Agent Loop (agent/loop.py)

The core agentic pattern:

User prompt → LLM (with tools) → Tool calls? → Execute → Repeat
                                → No tool calls? → Done

5. CLI (cli.py)

  • Single-prompt mode: mini-pi "List all Python files"
  • Interactive mode: mini-pi -i (multi-turn conversation)
  • Bash shortcut: !ls to run commands directly

Roadmap

See docs/ROADMAP.md for the full development plan across 6 phases.

Installation

For users (recommended)

# Via uv tool (fast, isolated environment)
uv tool install mini-pi

# Or via pipx
pipx install mini-pi

# Or via pip
pip install mini-pi

For development

git clone https://github.com/YOUR_USERNAME/mini-pi.git
cd mini-pi
uv sync

Setup

# Set your Anthropic API key
export ANTHROPIC_API_KEY=sk-ant-...

# Run
mini-pi "What files are in the current directory?"

# Interactive mode
mini-pi -i

Learning Path

This project implements the core of what makes pi tick:

  1. LLM Client - How to talk to LLM APIs with tool calling
  2. Agent Loop - The fundamental agentic pattern
  3. Tools - File I/O, bash execution, precise editing
  4. Streaming - Real-time response streaming

See docs/ROADMAP.md for planned features across 6 phases.

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_pi-0.1.0.tar.gz (52.3 kB view details)

Uploaded Source

Built Distribution

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

mini_pi-0.1.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file mini_pi-0.1.0.tar.gz.

File metadata

  • Download URL: mini_pi-0.1.0.tar.gz
  • Upload date:
  • Size: 52.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mini_pi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 164e455415b8401c7fe673b996ec29b49e9bc5e3677641294c5fc9044ace70db
MD5 38fbed55792081a5d82b1a9fdfc05cc4
BLAKE2b-256 9103aa5c8dc7bd375e2b870fc07a6514a4dfc410cb04d678b48bbb83e8e276f9

See more details on using hashes here.

File details

Details for the file mini_pi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mini_pi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mini_pi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e8bff4135097ddd97b807cb87a95170aa4b4dd7a113d7af5eada276dac3861f
MD5 8a3af57329a1763edd23f6cc2cd88eb2
BLAKE2b-256 043746f85356fbe24c6f6dda9ab1038ccc8ae2b17770953e18c5c855643cf7d8

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