The Machine (TM): a local AI agent that can control your machine
pip install the-machine==0.9.0 Copy PIP instructions
A local AI agent that can control your machine, extensible and permission-gated.
TM is a Python agent harness inspired by the architecture of pi, rebuilt around explicit permission approval for filesystem, shell, and network access.
Core agent, providers, built-in tools, permissions, and CLI are working. See the phase table below.
the-machine is on PyPI. uv is recommended (it can also install Python for you).
# Windows (PowerShell) powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" # macOS / Linux curl -LsSf https://astral.sh/uv/install.sh | sh On Windows keep the installer in a child process as shown: irm ... | iex on its own runs it inside your current shell, so the script's internal exit 1 closes the window before the error is readable.
uv tool install "the-machine[all]" uv tool update-shell # add the tool bin dir to PATH; restart the terminal afterwards tm --help Or with pip, inside a virtual environment:
pip install "the-machine[all]" [all] pulls in the Anthropic, Google, and TUI extras. Drop it for a minimal install (OpenAI-compatible providers only; --tui then needs textual).
uv tool install "the-machine[all] @ git+https://github.com/beyondalbert/tm" # without git: uv tool install "the-machine[all] @ https://github.com/beyondalbert/tm/archive/refs/heads/main.tar.gz" From a clone (development) git clone https://github.com/beyondalbert/tm cd tm uv sync --all-extras uv run tm --help First run tm --login deepseek # store an API key (input visible) tm "list the files in this folder" Requires Python 3.11+. uv installs a suitable interpreter automatically.
tm --update tm --update checks PyPI and upgrades in place. It uses whichever installer owns the environment (uv tool, pipx, or pip), so uv is not required. On Windows the running tm.exe cannot replace itself, so the upgrade runs in a small detached helper (log: /update.log); exit tm and start it again when it finishes.
Multi-provider via official SDK adapters. Domestic providers first (DeepSeek, Qwen, Kimi, Zhipu GLM), then OpenAI and any OpenAI-compatible endpoint (Ollama, vLLM, LM Studio).
Set the API key for the provider you want, then run:
$env:DEEPSEEK_API_KEY = "sk-..." python -m uv run tm "list the files in this folder" Where to set the API key Three options, in order of convenience:
Store it once (recommended). Prompts for the key (visible, so you can confirm it) and saves it to the credentials file:
python -m uv run tm --login deepseek After saving, TM echoes back a masked preview (for example sk-000...0000 (35 chars)) so you can confirm it was entered correctly.
[providers] deepseek = "sk-..." qwen = "sk-..." Environment variable (session or persistent):
# current shell only $env:DEEPSEEK_API_KEY = "sk-..." # persistent for your user (restart the terminal afterwards) [Environment]::SetEnvironmentVariable("DEEPSEEK_API_KEY", "sk-...", "User") Override the config location with TM_CONFIG_DIR if you do not want the default directory.
Stored credentials take precedence over environment variables.
Anthropic and Google use their official SDKs; the rest use the OpenAI-compatible adapter. ollama and other local servers need no key.
Define your own provider (any OpenAI-compatible, Anthropic, or Google endpoint) or extra models in /models.toml (Windows: %APPDATA%\the-machine\models.toml). It is merged over the built-in catalog, so tm --list-models and /model pick it up without editing code.
The interactive helper writes these files for you:
tm models add-local # prompts for endpoint, model id, context window, ... tm models edit-local local # change an existing provider (values pre-filled) tm models list # show providers defined in models.toml [providers.myprovider] name = "My Provider" api = "openai-completions" # or anthropic-messages / google-generative-ai base_url = "https://api.example.com/v1" api_key_env = "MYPROVIDER_API_KEY" # a name, or a list of names default_model = "my-model" [[providers.myprovider.models]] id = "my-model" context_window = 32768 max_tokens = 4096 input_cost = 0.5 # optional: USD per 1M tokens output_cost = 1.5 cache_read_cost = 0.05 # add or override models on a built-in provider [[providers.deepseek.models]] id = "deepseek-v4-lite" context_window = 65536 Store the key with tm --login myprovider, or set the env var named above. Switch to a custom model with /model my-model or tm --model my-model.
Context files (AGENTS.md / CLAUDE.md, walking up from cwd, plus the global config dir) are appended to the system prompt. Disable with --no-context-files.
When stdout is not a terminal (piped or redirected) or textual is not installed, tm falls back to the console REPL automatically.
Copying text. The TUI captures the mouse for in-app selection and scrolling. Drag to select text and press Ctrl+Shift+C to copy it. Copying uses the real system clipboard (clip/Set-Clipboard on Windows, pbcopy, wl-copy, or xclip/xsel), with an OSC52 fallback for terminals that support it. With no selection, Ctrl+Shift+C copies the last reply. You can also run /copy [n] to copy the nth-from-last reply. If copying does nothing (some terminals intercept Ctrl+Shift+C), start the TUI with --no-mouse and use the terminal's own selection (Shift+drag on most terminals). Set mouse = false in settings to make that the default.
Every file, shell, and network action is evaluated against a policy. Deny rules win, then allow rules, then the default decision. Reads are allowed by default (default_read = "allow"); writes, shell, and network default to ask. Undecided actions prompt the user; a (always) remembers the scope and persists it to /approvals.json, so it survives a restart. All decisions are appended to /audit.jsonl.
To reduce prompts during a session, /auto on (or Ctrl+Y in the TUI) auto approves everything that is not explicitly denied for the rest of the session; /auto off returns to prompting, and tm --yolo starts in that mode. A built-in list of destructive commands always asks and is never remembered, as does elevate.
Policy files are merged from /policy.toml (global) and /.aiagent/policy.toml (project). Example:
default = "ask" # writes, shell, network default_read = "allow" # reads (set "ask" to be prompted) [files.read] allow = ["**"] deny = ["**/.env", "**/id_rsa"] [files.write] allow = ["src/**", "tests/**"] deny = [".git/**"] [shell] allow = ["git *", "ls *", "pytest *"] deny = ["rm -rf *", "shutdown*", "format *"] [network] allow = ["api.deepseek.com"] File rules are folder-aware: a rule naming a directory (src, src/, or src/**) covers everything under it, so you can control access per folder instead of per file. When the policy leaves an action as ask and you answer a (always), TM remembers the scope: the containing folder for file actions, the program for shell commands (git covers git status, git log, ...), and the host for network actions.
Note: shell commands are matched textually. TM cannot reliably stop a shell command from making network calls; use a sandbox/container when you need a hard network boundary.
Project trust. Project-local resources that can run code or change the policy (.aiagent/extensions, .aiagent/skills, .aiagent/prompts, .agents/skills, .aiagent/policy.toml, .aiagent/SYSTEM.md) are loaded only after you trust the directory. TM asks on first use, remembers the decision in /trust.json, and honors --approve/--no-approve, /trust [off], and the default_project_trust setting (ask | always | never). Context files such as AGENTS.md are not gated. Non-interactive runs (-p, --json, --mode rpc) do not prompt and decline by default, so allowlist what they may do in policy.toml or start them with --yolo.
Changes and undo. Mutating tools append to /changes/changes.jsonl. File writes/edits snapshot the previous content; package installs and service start/stops record enough to reverse them, so /undo [n] restores the previous state. Destructive shell commands (a built-in deny list) always need an explicit, non-remembered approval. elevate is never auto-approved or remembered. Use tm --dry-run to preview mutations without applying them.
Inside tm (agent REPL or TUI) type / for commands:
Completion. In the TUI, press Tab to accept a suggestion: type / to complete a command, or @ to fuzzy-search a file path. Up/Down move the selection and Escape dismisses it.
Input. The TUI prompt is multi-line: Enter submits, Shift+Enter (or Ctrl+J) inserts a newline, and pasting keeps every line. While a turn is running, Esc or Ctrl+C stops it and Ctrl+P pauses/resumes it (the status line shows which). Stopping cancels the in-flight model request and kills a running shell/python command. Reasoning output and tool results are folded to one line by default; Ctrl+O expands/collapses them. Very long sessions keep only the most recent ~150 messages on screen (older ones are hidden) so the view stays fast; the full history is still in the session file.
Network errors. Transient provider failures (timeouts, connection resets, 429/5xx) are retried up to max_retries times with a visible "network problem: retrying" notice. Non-transient errors (auth, bad request) stop the run.
Sessions are appended to JSONL files under /sessions/, tagged with the working directory. tm continues the most recent session for the current directory by default (in the TUI, its history is rendered on startup).
Each session file is a full store with three durable forms — an append-only entry tree, bound values/lists, and an append-only usage ledger. Writes commit atomically (one transaction per JSONL line; a torn final line is discarded whole), and the durable operation restart point from --durable lives in the same store.
Inside a session, /resume [n|id] switches sessions (a picker modal in the TUI), /tree navigates conversation points, and /fork copies a branch to a new file. The TUI re-renders the resumed conversation's history on startup and after /resume, /new, /tree, and /fork.
The provider/model you switch to with /model is remembered per session and restored when that session is resumed, overriding the settings default.
TM can connect to a tm_im server as an agent: it receives chat messages in real time and replies by running the normal TM agent. Each account gets its own config file, so several can run on one machine in the background:
tm im config new alice --model deepseek-chat # one config per account tm im start --config alice # run in the background tm im logs -f --config alice tm im stop --config alice tm im --help lists every subcommand (run, start, stop, status, logs, me, conversations, send, login, config). See docs/im.md for the full reference (config fields, multiple accounts, model selection, safety, troubleshooting).
/settings.toml (Windows: %APPDATA%\the-machine\settings.toml):
provider = "deepseek" model = "deepseek-v4-pro" temperature = 0.2 max_tokens = 8192 system_prompt = "Extra instructions appended to the system prompt." auto_compact = true # summarize older context when nearing the limit compact_threshold = 0.8 # fraction of the context window that triggers it compact_keep_recent = 6 # recent messages kept verbatim max_turns = 300 # max agent turns per prompt (also `tm --max-turns N`) max_retries = 3 # retries for transient network errors (also `--max-retries N`) default_project_trust = "ask" # ask | always | never cache_retention = "short" # short | long (provider prompt cache; TM_CACHE_RETENTION overrides) env_probe = true # add a machine summary to the system prompt python_executable = "" # interpreter for the python tool (default: the one running TM) python_timeout = 120 # seconds per python script workspace_dir = "" # where python scripts are saved (default: /workspace) auto_install = true # install missing pip packages declared by the python tool language = "auto" # UI language: en | zh | auto (also --lang, /lang) Automatic compaction runs before a prompt when the estimated context exceeds context_window * compact_threshold. Disable per run with --no-auto-compact. If a turn ends truncated or with an overflow error, TM compacts and retries, keeping a smaller tail each attempt (down to just the summary) until it fits; the summarizer itself gets a size-bounded transcript, and if it still fails TM drops the oldest messages. Summaries are structured (goal, progress, decisions, next steps) and updated incrementally on each compaction, and list the files that were read or modified. Compaction is stored as a durable entry, so the summarized context survives a restart.
Per-model pricing (input_cost, output_cost, cache_read_cost, USD per 1M tokens) can be set in models.toml; the footer then shows $cost and the cache hit rate (CH%).
TM inspects the machine before assuming anything, and writes Python when shell one-liners are not enough.
The architecture and the multi-phase plan live in docs/design/device-management.md.
Tool output. Command and file output is capped at 2000 lines or 50KB, whichever is hit first. Command output (shell, python, elevate) keeps the end, where errors and the exit code appear, and a non-zero exit code marks the result as an error; file and search output keeps the beginning (reads add Use offset=N to continue, grep caps each match line at 500 characters). When output is truncated, the full text is saved under /workspace/spill/ and the notice names that file.
Context files. AGENTS.md / CLAUDE.md (and AGENTS.override.md) are loaded from the global config dir and walking up from the working directory, and appended to the system prompt. Disable with --no-context-files.
Skills. A skill is a directory with a SKILL.md (optional frontmatter with name and description). Load from /skills/, .agents/skills/, or .aiagent/skills/. Their names/descriptions are advertised in the system prompt; load one with /skill: .
--- name: code-review description: Review code for bugs and security issues --- Review the target for bugs, security issues, and missing tests. Prompt templates. Markdown files in /prompts/ or .aiagent/prompts/, invoked as / ; {{input}} is replaced by the text after the command.
Review this for bugs, security, and performance: {{input}} Extensions. Python modules in /extensions/ or .aiagent/extensions/. Each defines setup(api) and can register tools, event listeners, and slash commands. Extensions run with full process permissions.
from tm.tools.base import Tool, text_result def setup(api): api.register_tool(MyTool()) api.on("tool_execution_end", lambda event: None) api.register_command("greet", lambda arg: f"hello {arg}") Telemetry Opt in with --telemetry (or telemetry = true in settings). Spans are written to /telemetry.jsonl. The contract (tm/telemetry/) is deliberately narrow and never carries prompts, message content, tool arguments, tool output, or credentials — only structural metadata and counts. redact() is the single choke point, and adapters (NoopTelemetry, MemoryTelemetry, FileTelemetry) can only ever see redacted spans.
Opt in with --durable (or durable = true). Each tm run is a durable operation tracked in /state.jsonl: before an uncertain external effect (a tool call) the intent is recorded, and it is settled afterwards. Messages are persisted to the session as they are produced, so the in-flight call is durable too.
On the next start, TM automatically recovers interrupted operations:
Recovered re-runs still go through the permission gate. See tm/core/operation.py and tm/core/agent.py.
Set up once (installs the project editable, so source edits take effect with no reinstall):
python -m uv sync --all-extras Run the app from source:
python -m uv run tm # TUI python -m uv run tm --no-tui # console REPL python -m uv run tm "prompt" # one-shot agent run python -m uv run tm --json "prompt" # stream agent events as JSON (great for debugging) python -m uv run tm --login deepseek # store an API key On Windows, start.bat (cmd) and run.ps1 (PowerShell) wrap the above and set up dependencies on first run:
.\start.bat # or: .\run.ps1 .\start.bat --no-tui # console REPL .\start.bat "prompt" # one-shot Tests and quality gates (same as CI):
python -m uv run pytest -q # full suite python -m uv run pytest tests/evals -q -m eval # offline eval scenarios python -m uv run python scripts/run-evals.py # eval report python -m uv run pytest tests/test_tui.py -q # one file python -m uv run pytest -q -k tool # by name python -m uv run ruff check . # lint python -m uv run mypy # types python -m uv build # wheel + sdist Before a release, scripts/release-smoke.ps1 builds, validates metadata in a throwaway venv, and runs tm --version / tm --list-models.
Secret scanning. CI runs gitleaks (.github/workflows/secret-scan.yml, configured by .gitleaks.toml), and tests/test_no_secrets.py fails the suite if a tracked file looks like it contains a committed secret. Never put real keys in tests, docs, or fixtures; use an obvious placeholder such as sk-xxxx.
uv.lock is committed. CI (.github/workflows/ci.yml) runs ruff and mypy on Linux, and the test suite on Linux, Windows, and macOS for Python 3.11 and 3.12. See RELEASE.md for publishing to PyPI.
Device management phases D-G are planned in docs/design/device-management.md: dynamic monitoring, OS-native scheduling, remote SSH, and reuse/specialization. Possible future work: more providers, provider-side prompt caching controls, a web UI, and multi-agent orchestration.
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.




