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            # DeepSeek/OpenAI-compatible 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)

  • Uses OpenAI SDK, defaulting to DeepSeek API
  • Converts internal message format to OpenAI-compatible format
  • Handles tool call streaming (accumulates partial function arguments)
  • 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 DeepSeek API key
export DEEPSEEK_API_KEY=sk-...

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

# Interactive mode
mini-pi -i

# Or use any OpenAI-compatible API
mini-pi -m gpt-4o -b https://api.openai.com/v1

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.3.0.tar.gz (57.0 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.3.0-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mini_pi-0.3.0.tar.gz
  • Upload date:
  • Size: 57.0 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.3.0.tar.gz
Algorithm Hash digest
SHA256 3fa2d90c9de796e20836152c9e76b8633d2b5bab358f5e809883009884bc3782
MD5 78a854a8761e5f4099b5c02441f8fbca
BLAKE2b-256 2c35dbf4ab6b3c985198f7c1f186f59b5edbde40b22fc16cd9346d94ad8f9b8d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mini_pi-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 28.1 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba00e980a48ce751698de1903c7565ada1edd973ae00d08c3b9c5a7471376bf9
MD5 6b656c1f1a1487717474cc5f13c04346
BLAKE2b-256 1730c695c8da1a33d08888419102103baae0ad094b29f0f2b77ac1ca60162ba4

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