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

Uploaded Python 3

File details

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

File metadata

  • Download URL: mini_pi-0.2.0.tar.gz
  • Upload date:
  • Size: 56.6 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.2.0.tar.gz
Algorithm Hash digest
SHA256 ed56afb416acd7c900d260c70f21ba88bf647ca4049f72b716a99cc4b54a9f3c
MD5 e9072ecd79e6cf4553c413c8a191df28
BLAKE2b-256 1d6e14cf3c690b97af2609703bc4c2febfad4ea16a2064b7a1adc13a83a8391c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mini_pi-0.2.0-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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02d520dacf9ec1c0bacae6fbbbff6b48affafef0b86d15869b6050e99e9abe54
MD5 53712e752c2b9d35ee53d56dbcd4afc8
BLAKE2b-256 9059f912ab035af23c17c3983df4487a64185ca788c48de7e5f9ccd51cd518c4

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