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.1.tar.gz (57.1 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.1-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mini_pi-0.3.1.tar.gz
  • Upload date:
  • Size: 57.1 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.1.tar.gz
Algorithm Hash digest
SHA256 3ad6fcdd2a170cf90167c26a1ae8f27c767ed70a1d6e774bbeefdd3772b616f5
MD5 ec6e225512558341788cb04573251067
BLAKE2b-256 bb1a2fa57132ed4ddb661623acb6342cf60b12bd5f334e7c6157519b027c3981

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mini_pi-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 28.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b61cc196f33ce2988334d8b8539e4de413f47e8960a051a5845d912f0888cdf6
MD5 9f483023022664962116b6462ade849b
BLAKE2b-256 4c62ac21bc1eb9e4217b3fabd120592cc2fcd8a13b76d3db5605d1e6f4e1618c

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