Metadata-Version: 2.4
Name: patchpal
Version: 1.0.2
Summary: A Python-native AI coding and automation agent harness for local and cloud LLMs, built for private data and resource-constrained machines.
Author: PatchPal Contributors
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/amaiya/patchpal
Project-URL: Documentation, https://amaiya.github.io/patchpal/
Project-URL: Repository, https://github.com/amaiya/patchpal
Project-URL: Issues, https://github.com/amaiya/patchpal/issues
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: litellm
Requires-Dist: requests>=2.31.0
Requires-Dist: beautifulsoup4>=4.12.0
Requires-Dist: ddgs>=1.0.0
Requires-Dist: rich>=13.0.0
Requires-Dist: pyyaml>=6.0.0
Requires-Dist: prompt_toolkit>=3.0.0
Requires-Dist: boto3
Requires-Dist: pymupdf>=1.23.0
Requires-Dist: python-docx>=1.0.0
Requires-Dist: python-pptx>=0.6.0
Requires-Dist: tree-sitter-language-pack<1.0.0,>=0.3.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: ruff==0.14.13; extra == "dev"
Requires-Dist: pre-commit>=3.0.0; extra == "dev"
Provides-Extra: mcp
Requires-Dist: mcp>=0.9.0; extra == "mcp"
Provides-Extra: browser
Requires-Dist: playwright>=1.40.0; extra == "browser"
Requires-Dist: nest-asyncio>=1.5.0; extra == "browser"
Provides-Extra: docs
Requires-Dist: mkdocs<2.0,>=1.5.0; extra == "docs"
Requires-Dist: mkdocs-material>=9.5.0; extra == "docs"
Requires-Dist: mkdocs-autorefs>=1.0.0; extra == "docs"
Requires-Dist: mkdocstrings>=0.24.0; extra == "docs"
Requires-Dist: mkdocstrings-python>=1.7.0; extra == "docs"
Dynamic: license-file

# PatchPal — A Python-Native AI Coding and Automation Agent

<!--![PatchPal Screenshot](assets/patchpal_screenshot.png)-->
<img src="https://raw.githubusercontent.com/amaiya/patchpal/refs/heads/main/assets/patchpal_screenshot.png" alt="PatchPal Screenshot" width="800"/>

> Batteries-included by default, lightweight when you need it. Runs on local and small-context models, sandboxed on Linux, macOS, and Windows. Use it from the terminal or as a Python SDK.

**PatchPal** is a Python-native AI coding agent harness that helps you build software, debug issues, and automate tasks. You can use it interactively through the [terminal UI](https://amaiya.github.io/patchpal/usage/interactive/) (`patchpal`) or headless through the [Python SDK](https://amaiya.github.io/patchpal/usage/python-api/) (`agent.run("task")`). It supports agent skills, tool use, and generating and running Python code, enabling interactive workflows for tasks such as data analysis, visualization, web scraping, API interactions, and research with synthesized findings. It was originally designed for working with private data (e.g., via local models or AWS GovCloud Bedrock) and on resource-constrained machines.

**Batteries-included, or lightweight when you need it.** Out of the box, PatchPal includes [built-in tools](https://amaiya.github.io/patchpal/features/tools/) for file editing, shell commands, code analysis, web search, browser automation, and task planning. It also supports skills, MCP, project memory, and autopilot, and installs as a single Python package. For local or small-context models, [TinyAgent](https://amaiya.github.io/patchpal/context-management/#small-context-windows-tinyagent) automatically slims down to five core tools plus optional web tools, with a compact system prompt, handoff compaction, and selective file reading. On larger windows, `PATCHPAL_MINIMAL_TOOLS=true` gives a similar reduced toolset.

**Key Features**
- [Local Models](https://amaiya.github.io/patchpal/models/local-models/) with [small-context-window support](https://amaiya.github.io/patchpal/context-management/#small-context-windows-tinyagent) (TinyAgent) and [ReAct mode](https://amaiya.github.io/patchpal/models/local-models/#react-mode-for-models-without-function-calling)
- [Sandbox Mode](https://amaiya.github.io/patchpal/usage/sandbox/) for secure container isolation with network restrictions on Linux, macOS, and Windows
- [Python SDK](https://amaiya.github.io/patchpal/usage/python-api/) for flexibility and extensibility
- [Built-in](https://amaiya.github.io/patchpal/features/tools/) and [Custom Tools](https://amaiya.github.io/patchpal/features/custom-tools/)
- [Terminal Interface](https://amaiya.github.io/patchpal/usage/interactive/) for interactive development
- [Browser Automation](https://amaiya.github.io/patchpal/features/tools/#browser-automation-14-tools-optional) for interactive web tasks, form filling, and JavaScript-heavy sites
- [Skills System](https://amaiya.github.io/patchpal/features/skills/) and [MCP Integration](https://amaiya.github.io/patchpal/features/mcp/)
- [Autopilot Mode](https://amaiya.github.io/patchpal/usage/autopilot/) using [Ralph Wiggum loops](https://github.com/amaiya/patchpal/tree/main/examples/ralph/)
- [Project Memory](https://amaiya.github.io/patchpal/features/memory/) automatically loads project context from `MEMORY.md` (repository root or `~/.patchpal/repos/<repo-name>/MEMORY.md`) at startup

PatchPal prioritizes customizability: custom tools, custom skills, a flexible Python API, and support for any tool-calling LLM.

Full documentation is [here](https://amaiya.github.io/patchpal).

## Quick Start

```bash
$ pip install patchpal          # install
$ patchpal --model <model_id>   # start
```

> Model support: Any [LiteLLM-supported model](https://models.litellm.ai/) can be used.
> Platform support: Linux, macOS, and Windows are all supported

**Alternative: Run with Docker/Podman (no installation required)**

```bash
# Using pre-built image with patchpal installed (default model)
docker run -it --rm \
  -v $(pwd):/workspace \
  -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \
  ghcr.io/amaiya/patchpal-sandbox:latest \
  patchpal --model anthropic/claude-sonnet-4-5

# Or with Podman
podman run -it --rm \
  -v $(pwd):/workspace \
  -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \
  ghcr.io/amaiya/patchpal-sandbox:latest \
  patchpal --model anthropic/claude-sonnet-4-5

# Specify a different model
docker run -it --rm \
  -v $(pwd):/workspace \
  -e OPENAI_API_KEY=$OPENAI_API_KEY \
  ghcr.io/amaiya/patchpal-sandbox:latest \
  patchpal --model openai/gpt-5-mini
```


## Setup
0. **Install**: `pip install patchpal`
   - **Optional**: For browser automation (14 additional tools): `pip install patchpal[browser] && python -m playwright install chromium`
1. **Get an API key or a Local LLM Engine**:
   - **[Cloud]** For Anthropic models (default): Sign up at https://console.anthropic.com/
   - **[Cloud]** For OpenAI models: Get a key from https://platform.openai.com/
   - **[Local]** For vLLM: Install from https://docs.vllm.ai/ (free - no API charges)
   - **[Local]** For Ollama: Install from https://ollama.com/ (⚠️ set `OLLAMA_CONTEXT_LENGTH`, e.g., `16384` or `32768` - see Ollama section below)
   - **[Local]** Not sure which local engine to use (vLLM, Ollama, PolyStrata, llama.cpp, ...)? See [Choosing an Inference Engine](https://amaiya.github.io/patchpal/models/local-models/#choosing-an-inference-engine)
   - For other providers: Check the [LiteLLM documentation](https://docs.litellm.ai/docs/providers)

2. **Set up your API key as environment variable**:
```bash

# For Anthropic (default)
export ANTHROPIC_API_KEY=your_api_key_here

# For OpenAI
export OPENAI_API_KEY=your_api_key_here

# For vLLM - API key required only if configured
export HOSTED_VLLM_API_BASE=http://localhost:8000 # depends on your vLLM setup
export HOSTED_VLLM_API_KEY=token-abc123           # optional depending on your vLLM setup

# For Ollama, no API key required

# For other providers, check LiteLLM docs
```


3. **Run PatchPal**:
```bash
# Use default model (anthropic/claude-sonnet-4-5)
patchpal

# Use a specific model via command-line argument
patchpal --model openai/gpt-5.2-codex  # or openai/gpt-5-mini, anthropic/claude-opus-4-5, etc.

# Use vLLM (local)
# Note: vLLM server must be started with --tool-call-parser and --enable-auto-tool-choice
export HOSTED_VLLM_API_BASE=http://localhost:8000
export HOSTED_VLLM_API_KEY=token-abc123
patchpal --model hosted_vllm/openai/gpt-oss-120b

# Use Ollama (local - set OLLAMA_CONTEXT_LENGTH and PATCHPAL_CONTEXT_LIMIT to the same window)
export OLLAMA_CONTEXT_LENGTH=16384 # or set the context length in the Ollama app's Settings
PATCHPAL_CONTEXT_LIMIT=16384 patchpal --model ollama_chat/gemma4:e4b

# Use any OpenAI-compatible server (e.g., PolyStrata, llama.cpp, LM Studio) - include /v1 in the URL
# OPENAI_API_KEY can be any non-empty value if the server doesn't check keys
OPENAI_API_BASE=http://127.0.0.1:8080/v1 OPENAI_API_KEY=dummy PATCHPAL_CONTEXT_LIMIT=32768 \
  patchpal --model openai/<served-model-name>

# Or set the model via environment variable
export PATCHPAL_MODEL=openai/gpt-5.2
patchpal
```

**Tip for Local Models:** Local models (i.e., models served by Ollama or vLLM) work best with these settings:
- **Always:** set `PATCHPAL_CONTEXT_LIMIT` to your served window (e.g., `32768` to match `OLLAMA_CONTEXT_LENGTH=32768`, or `16384` on resource-constrained machines). PatchPal can't detect it from the server. At 64K or less, PatchPal uses [TinyAgent](https://amaiya.github.io/patchpal/context-management/#small-context-windows-tinyagent), which includes minimal tools plus small-window compaction and reading.
- **Model with function calling, window over 64K:** `PATCHPAL_MINIMAL_TOOLS=true` limits tools to `read_file`, `read_lines`, `write_file`, `edit_file`, `run_shell`, reducing tool confusion.
- **Model without function calling:** `PATCHPAL_REACT_MODE=true` enables text-based tool invocation (see [ReAct mode docs](https://amaiya.github.io/patchpal/models/local-models/#react-mode-for-models-without-function-calling)).
- **Ollama:** `PATCHPAL_STREAM_OUTPUT=false` was a workaround for [unreliable streamed tool calls](https://github.com/openclaw/openclaw/issues/5769). PatchPal now handles Ollama's streamed tool calls correctly, so this may no longer be needed; try it if tool calls still fail.
- **Offline:** `PATCHPAL_ENABLE_WEB=false` disables web tools.


## Beyond Coding: General Problem-Solving

While originally designed for software development, PatchPal is also a general-purpose assistant. With web search, file operations, shell commands, and custom tools/skills, it can help with research, data analysis, document processing, log file analyses, etc.

<img src="https://raw.githubusercontent.com/amaiya/patchpal/refs/heads/main/assets/patchpal_assistant.png" alt="PatchPal as General Assistant" width="650"/>

## FAQ

> There are so many coding agent harnesses. Why build yet another one?

1. Most agent harnesses are [built in TypeScript](https://news.ycombinator.com/item?id=44212560). We wanted [something in Python](https://amaiya.github.io/patchpal/usage/python-api/) that we could easily extend for our custom workflows.
2. PatchPal includes a [unique guardrails system](https://amaiya.github.io/patchpal/safety/) that is better suited to privacy-conscious use cases involving sensitive data.
3. We needed an agent harness that seamlessly works with [both local and cloud models](https://amaiya.github.io/patchpal/models/overview/#supported-models), including AWS GovCloud Bedrock models.

> I noticed there's another package called PatchPal on GitLab. Are they related?

No, they're separate projects. The [project with the same name on GitLab](https://gitlab.com/patchpal-ai) is unrelated to this one.

> On Windows Subsystem for Linux (WSL), why is it stalling intermittently at "Thinking..."?

This is a [known issue](https://github.com/microsoft/WSL/issues/6264#issuecomment-762154193) with WSL2.

Try examining and then lowering the `mtu`:

```bash
$ cat /sys/class/net/eth1/mtu
1427

$ sudo ip link set eth1 mtu 1400
```

## Documentation

Full documentation is [available here](https://amaiya.github.io/patchpal/).
