Pal: build and plan with AI in your terminal (pal cli) or browser (pal web), on a layer that cuts tokens and latency.
Build and plan with AI, in your terminal or your browser, with fewer tokens. Three built-in agents: Ask, Build and Plan. Underneath is the Pal layer, which cuts tokens and latency: only the relevant history and files are sent, a file the model already has is not sent again, and long conversations are paged and compressed.
Works with a local model (Ollama) or an API model: Anthropic, OpenAI, Gemini, Groq, DeepSeek, Mistral, Together or OpenRouter.
pip install pal-code # 1. install cd my-project pal cli # 2. the terminal: the session opens and works in this folder pal web # 3. or the browser: opens Pal in your default browser pal web runs a small server on this computer only (http://127.0.0.1:5000) and opens the Studio, with the chat and the code editor one click away. Press Ctrl+C in the terminal to stop it. Options: pal web --port 8080, pal web --page chat, pal web --no-open, pal web --dir .
✓ Local LLM Ollama running · qwen2.5-coder:7b · helper qwen2.5:1.5b ✓ Project map 214 files, 2.1k tokens (the code itself is about 180k) … Code graph built in the background; the session can start now ✓ Documents 3 converted to markdown, 2 text files indexed: only matching passages are sent docs/spec.pdf → ~/.pal/projects/shop-1a2b3c/markdown/docs/spec.pdf.md ✓ Tests python -m pytest -q Local LLM: on a computer with a GPU, Pal makes sure local models can run. If Ollama is missing it offers to install it (asks first), starts it if it is not running, and offers to download the models chosen for your GPU when they are missing. No GPU: API models only. Project map: every source file with its classes and functions, in a few thousand tokens. It is indexed, so a question about "the login handler" brings the lines of the map that name it, not the project. Code graph: built with graphify from your code (AST only: no model, nothing leaves the computer). Each request gets the graph nodes and code excerpts that match it. Documents: PDF, Word, PowerPoint, Excel, EPUB, RTF and LaTeX files are converted to markdown files (in ~/.pal/projects/..., never in your folder) and indexed with your markdown and text files. Word files work without pandoc. Only what changed is redone the next time (a second start takes well under a second). A .palignore file (like .gitignore) leaves folders or files out. First run sets up Pal for your computer. The first pal cli or pal web looks at your GPU (NVIDIA, AMD, Apple Silicon) and asks which main model (it writes and plans) you want:
Either way Pal downloads the helper, a small fast local model for its own jobs on every request (routing, trimming what you type, checking answers). Change the main model any time with \set-model: the same list, and picking a model that is not installed downloads it.
The catalogue (pal setup --list) also has the newer thinking models (qwen3.5, qwen3.6, gemma4, gpt-oss): they reason before answering, so Pal lists them but does not pick them by itself. Choose one with \set-model qwen3.6:27b.
No GPU? API models only. On a computer without a GPU Pal offers no local model: it asks for an API provider, a model and a key (the key is used for that session and never saved), and Pal's local helper jobs (routing, trimming what you type, checking answers) are off, so your message goes to the API model as typed. The savers that need no model still work: only the relevant history, files and code are sent, and files are not sent twice.
pal setup runs it again, pal setup --list shows all 39 models grouped by the GPU memory they need with how each fits your computer, and pal setup --hardware gpu:24 shows what another computer would get. Sizes are Ollama's 4-bit downloads (approximate). Ollama itself comes from https://ollama.com/download.
API models instead: \key openrouter in a session (kept for that session only, never saved), then \set-model openrouter: , or set OPENROUTER_API_KEY (or OPENAI, ANTHROPIC, GEMINI ...) and run pal cli --provider openrouter --model . The helper still runs locally.
Files: @notes.md loads a file from your folder into context; \load loads one from anywhere, and dropping files on the terminal window does the same. Text and code files go as they are; PDF, Word, PowerPoint, Excel and HTML are converted to text first. The web interface has a + button.
From a source checkout, python run.py (Windows: py run.py) creates .venv, installs everything the first time and opens the web interface; python run.py cli opens the terminal session.
The agent application layer holds agents only. Two native agents ship, both on Gemini and both using the full token-saving pipeline: a coding agent and a documentation agent. Put their keys in .env (GEMINI_API_KEY_CODING, GEMINI_API_KEY_DOCS; one shared GEMINI_API_KEY also works), and run one from the terminal:
pal agent coding "how does checkout charge the card?" --file shop.zip pal agent docs "write a README for this project" --file shop.zip The SDK (pal.sdk) is for building your own agents or bringing agents written with other frameworks.
from pal.llm_wrapper.components.base import WrapperConfig from pal.sdk import AgentSDK, ReActAgent, adapt, autogen_model_client sdk = AgentSDK.standalone(WrapperConfig(backend="gemini", model="gemini-3.5-flash", api_key="...")) ReActAgent(sdk).run("what is 6 times 7?").answer # native pattern: reasons, calls tools, answers with adapt("autogen", sdk): # AutoGen 0.2: your existing code, unchanged ... with adapt("open-interpreter", sdk): # Open Interpreter ... # AutoGen 0.4+: AssistantAgent("helper", model_client=autogen_model_client(sdk)) Framework How Checked against the real library AutoGen 0.2 (pyautogen==0.2.35) adapt("autogen", sdk) yes, a two-agent chat AutoGen 0.4+ (autogen-agentchat) autogen_model_client(sdk) yes, an agent run Open Interpreter 0.4 adapt("open-interpreter", sdk) yes, a chat turn MetaGPT adapt("metagpt", sdk) no: could not be installed in the test environment, checked against a stand-in only ReAct, Reflexion native ReActAgent, ReflexionAgent tested with scripted models Where queries go. The SDK routes by query type: model work (LLMQuery) goes to the Pal kernel; non-LLM work (OSQuery: file operations, network requests, system facts) goes to the OS kernel, Ubuntu's Linux kernel here, through a guarded interface. Files stay in a per-agent workspace (~/.pal/workspaces/ ), private network addresses are blocked, and overwrite or delete asks for confirmation (default: no).
from pal.sdk import OSQuery, LLMQuery sdk.os.write_file("notes/todo.txt", "buy milk") # OS kernel: a file operation, no model involved sdk.os.http_get("https://example.com") # OS kernel: a network request sdk.send_request(LLMQuery(messages=[{"role": "user", "content": "plan my day"}])) # Pal kernel: model work Keyboard and mouse control are not supported (they need a desktop session). The OS operations are not offered to the chat's tools; register_os_tools(sdk) makes them available to ReAct-style agents you build.
Architecture. The diagram (docs/architecture.png, source docs/architecture_figure.py) shows the Application layer, the AIOS Kernel with its components, the OS Kernel and the hardware. The kernel's blocks: LLM Wrapper (LiteLLM and OpenRouter), Local LLM, LLM Scheduler, Context Manager with Knowledge Graph and Compression, Notes, Memory and Storage managers, Tool and Access managers, and the Token, Latency and Memory trackers.
LLM Wrapper and Local LLM. Every model call goes through LiteLLM's Python SDK, in three kinds of wrapper. LiteLLM wrapper: your own key for one provider (OpenAI, Anthropic, Gemini, Groq, DeepSeek, Mistral, Together ...), direct. OpenRouter wrapper: one OpenRouter key reaches hundreds of models, some free, with a model browser (pal models --free): the way to explore. Local LLM: models served on this machine (Ollama, vLLM, LM Studio, llama.cpp) and the in-process Hugging Face model. Pick a mode with pal chat --mode explore or --mode own_key; pal doctor says which is ready. In Explore mode your prompts pass through OpenRouter. LiteLLM handles users' API keys, so it is pinned (1.102.1), hash-locked (requirements/litellm.lock, installed first by python run.py), used as an SDK only (never its proxy), and checked by pal doctor. If your provider is rate-limited or down, an optional fallback model answers. See docs/ARCHITECTURE.md.
Context Manager, and the blocks around it. One token budget over the history, the code-graph excerpts, document excerpts and notes. The context manager keeps two jobs (which turns to show, and fitting everything under the budget) and asks the others: Compression shortens old assistant replies by rule (no model: code bodies, replaced drafts and filler go; exact details stay; turns too old to show become a short facts line), the Knowledge Graph supplies the matching excerpts of an uploaded project, and the Notes Manager supplies notes from other sessions and owns everything about notes (what is kept, recalled, forgotten and tidied). Measured on a scripted 34-turn session it uses 49% fewer tokens than sending everything and 15% more than plain paging, and keeps a figure given in turn 1 that paging loses (experiments/compression_bench.py).
Three trackers. The Token Tracker counts tokens and credits each saving to the part that made it, the Latency Tracker times every turn in stages (routing, input saver, context, API, tools) so a slow turn can be explained, and the Memory Tracker reports the notes (RAM and disk), open chats, indexed projects, storage and the process's own memory. Pal's \tokens shows them.
The AIOS paper's 17 tools. 12 are kept: Wikipedia and arXiv, and (off by default) Google search, WolframAlpha, currency, WordsAPI, moon phase and five Hugging Face image and audio tools. Bing search, Google Places, IMDb rank, Shazam and TripAdvisor were removed. Google's own search API is closed to new customers, so google_search reads results through SerpApi. No real service has been called by the tests: see docs/TOOLS.md.
Tools by name. pal tools prints all 34 tools with human names (File Read Tool, Directory Read Tool, Document Search Tool, File to Markdown Converter Tool, Code Graph Builder Tool, ...) and whether each is on. The input converter and graphify are tools too: file_to_markdown, build_code_graph, query_code_graph. A chat's uploaded and generated files are deleted when the chat ends.
Demo experiments. python run.py experiment rag has a real local model build a small RAG engine, once through a plain chat client and once through Pal, and reports the tokens saved. python run.py experiment build has a real local model (Ollama) write code, saves it to files in experiment_output/, judges it with a project's tests, and compares a plain chat client with Pal on tokens, time and correctness. There is no simulation. python run.py experiment runs a long question-and-answer session instead (a clearly labelled simulation if Ollama is not available). Neither is part of the package: see experiments/README.md.
Terminal chat. pal chat (add --agent coding, --file notes.md); commands /file, /agent, /reset, /stats, /quit.
Limits: only text replies are redirected (framework tool calling is not), and non-native agents get the light savers (tidying, optional repeat cache, stats), not the full pipeline, because the framework owns its prompts.
Open the Experiment tab and press Run demo. It sends 6 realistic messages (plan a small launch, with an attached survey) twice with the model you picked, once like a plain chat app and once through Pal, then shows the tokens the API reported and the time taken for each, the saving, and the launch brief it produced. The Chat tab shows a running "saved this chat" bar.
pip install pal-code # installs the `pal` command pal cli # opens the REPL in the current folder pal cli opens the pal code start screen: the logo and the chatbox, with the agent and model dropdowns and the mic. After the first message the chatbox sits under the work. Tab switches the agent (Build is tell mode, Ask is chat mode, Plan writes numbered steps):
Savings from paging, documents and the code graph are estimates (characters / 4). Set token_counter: provider for the model's own counts (an extra network call per count).
Defaults: src/pal/config/default.yaml. Override with PAL_CONFIG=my.yaml, or with environment variables: PAL__MEMORY__ENABLED=false, PAL__CONTEXT__HOT_TURNS=10. Unknown keys and bad values stop startup with a clear message. pal config prints the effective settings.
Data (memory, indexed documents, code graphs) lives in ~/.pal, or PAL_HOME.
Pure Python, no shell scripts required. CI (.github/workflows/ci.yml) runs lint, types and tests on Linux, macOS and Windows with Python 3.10 to 3.13. Where it differs:
The chat does not use the orchestrator. The maintainer's environment for this refactor was Linux only: the macOS and Windows columns are covered by code that avoids POSIX-only calls and by the CI matrix, not by a run.
docs/ARCHITECTURE.md gives the overview (start-up, the terminal session, the engine, the web, data); docs/ENGINE.md has every engine component and the design of a turn.
pip install -e ".[dev,full]" pytest # ~470 tests, no network, no real model ruff check src tests mypy The kernel-level work (patched Linux kernel, /proc/pal_stats) stays in a separate repo.
documents graph compression litellm vector embeddings inprocess voice full dev
ai coding-assistant cli llm ollama tokens code-graph
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.




