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.2.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.2-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mini_pi-0.3.2.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.2.tar.gz
Algorithm Hash digest
SHA256 926e09187f88d802a3a2e751fe77fb31b65867b4ee324f227d9409bc5e5a41ae
MD5 294c5dbbc5dfe62c22effeebc0368376
BLAKE2b-256 0df50ad1f0d2820bf9e5d3c5cad97043ac92034d9c923569a8b91cb568b4322e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mini_pi-0.3.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b19615efb340786969a22a74e4fedf4d3efbeecb05528db0feac0a059755b224
MD5 cd07ebf084be6f4c8c6a24e98568384e
BLAKE2b-256 9c93b3df85ae2c34081377bc28e817feb0ca0f228db40508f4f6a69327444b90

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