An open-source toolkitfor AI Agents

AI-Zen is an open-source organization around the AI Agent toolchain: a self-hosted agent runtime, terminal and desktop clients, libraries and MCP servers. Eleven repositories today.

streaming @ai-zen/cli
11Repositories
8MIT licensed
5Categories
22Built-in tools
TypeScript MCP OpenAI SDK Node.js pnpm workspace tRPC SQLite WebSocket Ink JSON-RPC 2.0 node-pty async iterator Server-Sent Events pdfjs Vue 3 Electron Tauri Live2D TypeScript MCP OpenAI SDK Node.js pnpm workspace tRPC SQLite WebSocket Ink JSON-RPC 2.0 node-pty async iterator Server-Sent Events pdfjs Vue 3 Electron Tauri Live2D
agents

What agents does

agents is the self-hosted agent runtime in this organization, and the base the other projects build on. These are its main features; each one has a corresponding implementation in the code.

You can cut in at any time

Once the service is running the agent stays online. Sending a message returns immediately and the agent goes back to idle when done; messages can keep arriving meanwhile and are queued by priority. Stopping has three degrees: interrupt the current request, stop accepting new messages but finish the queue, or end at once.

Background commands

exec waits for the result and suits short commands. async_exec returns as soon as the command starts; when it ends (normal exit, killed by timeout, failed to start) its output and exit status come back into the session as a new message.

Tools, skills and permissions

A tool is a .mjs file under tools/, a skill is skills/<id>/SKILL.md, a sub-agent is a JSON file under sub-agents/, and external services go in mcp.json. An agent’s permissions have four dimensions — tools, skills, mcps, subagents — each an allow or deny list; a tool outside them never appears in the model’s tool list.

Progressive disclosure for MCP too

Skills already work this way: the tool list carries one load_skill entry and the body is read when it is needed. MCP follows the same pattern — the list carries one load_mcp entry, and the connection plus the tool list of that server are fetched only when needed; call_mcp_tool then invokes one. Remote tools are never all put into the list.

Two ways to use it

In a terminal it opens the interactive interface; when called from a script it writes only the answer to stdout, logs to stderr, and uses the exit code to distinguish success, runtime failure and misuse.

When the context fills up

When the context is nearly full the agent stops, then writes a markdown file: the goal, the current state, what is done, what is not, key decisions, constraints, changed files and the next step. It then starts a fresh memory and keeps the old conversation as a separate session; the document can be opened and read directly.

Where the data lives

Sessions, messages, workspaces and credentials live in one SQLite file under ~/.ai-zen, with uploads in a sibling assets/ directory. The service listens on loopback by default; to let another device connect, start it with --public and issue a credential for that device.

cli

The cli interface

cli is the terminal client for agents. On the left, what it looks like in a terminal; on the right, the same program used from a script.

~/projects/ai-zen — ai
› merge the duplicated parse functions in this repo

Parsing happens in three places: src/parse.ts, src/utils/parse.ts and
src/legacy/parse.ts. Reading the call sites first, then deciding which one survives.

⠙ Calling find_text…
pending · and add the tests afterwards
────────────────────────────────────────────────
❯ 
Enter send · Ctrl+J newline · / commands · PgUp history
deepseek-flash · thinking high    working    this answer 812 tok
total 24.6k tok · ⚡ avg 38 tok/s
zsh — ai (pipe)
❯ 
ai "summarise what src/parse.ts does"

The entry point is parse(): it dispatches on extension to three parsers,
then normalises the result into { nodes, meta }.

❯ 
ai "summarise what src/parse.ts does" > answer.txt && echo $?
0

# stdout carries only the answer; logs and progress go to stderr
# exit codes: 0 success · 1 runtime failure · 2 misuse

Ask from the terminal directly

After installing the shell hook, typing a command that does not exist opens the interface with that line as the first message — no need to type ai first. Only bash and zsh are supported.

zsh — ai hook
❯ 
ai hook install
ai hook installed into /home/you/.zshrc
    Restart the terminal or run source /home/you/.zshrc to take effect
    Unknown commands will then be forwarded to the AI

❯ 
why do I get ECONNREFUSED 127.0.0.1:8790
# no such command, so the interface opens with this line as the first message
  • "Working", "idle", "stopped receiving" and "paused processing" are four different facts, each with its own slot.
  • The inbox holds messages not taken yet: they are accepted while the agent runs and taken once the batch ends.
  • Pipeline mode draws nothing and creates no session: ai "…" belongs to scripts, and --save turns it into a real one.
Quick start

Install it, then type ai in a terminal

On the first run there is no service on this machine yet, so it downloads and starts one; later runs just connect. Sessions and history live in that service, so closing the terminal does not lose them.

  • Downloads and starts one through npx when nothing runs locally; connects when something does
  • On start it prints five lines: address, version, discovery file, logs, credential file
  • The local credential lands in run/token; other devices get their own from token create
  • Sessions, messages, credentials and logs all live under ~/.ai-zen
npm i -g @ai-zen/cli
~/projects/ai-zen — zsh
❯ npm i -g @ai-zen/cli

❯ agents-host serve
Listening on    ws://127.0.0.1:8790
Version:        0.2.0-alpha.1
Discovery file: /home/you/.ai-zen/run/host.json
Logs:           /home/you/.ai-zen/logs
Credential file: /home/you/.ai-zen/run/token

❯ ai
# 本机已有宿主:直接连上;没有就用 npx 拉一台再连
❯ ai "列出这个仓库的构建脚本"
# 非 TTY 下走管道:stdout 只有答案,日志走 stderr▍
Projects

14 projects, one toolchain

Browse AI-Zen by layer — the agent runtime and its host on top, then MCP servers, products and core libraries. Each repository stands alone, and all of them fit the same design.

agents-core MIT

Kernel

An agent is one process-local object: an input queue, an outer loop that takes entries in batches, an inner loop that sends a request and runs tools, input and output switches, one event stream and a set of plugin hooks. It reads no configuration, writes no disk and touches no credentials.

TypeScriptevent-driven
Stars7
npm weekly369
agents-sdk MIT

Capability face and runtime

Assembles definition files, built-in tools, user tools, skills, sub-agents and MCP into a runnable agent: one Scope per directory, four-dimension permission whitelists, three-level model resolution, two context thresholds and handoff. The runtime wakes resident agents, tracks who is alive, and lets sessions post to each other.

TypeScriptMCPpeer sessions
Stars7
npm weekly440
agents-host MIT

Resident host

One SQLite file holds session rows and messages, the input queue, workspaces, credentials, notices, questions and a full-text index. The surface is tRPC procedures grouped by domain plus one event stream; agents-host serve starts one on loopback port 8790.

TypeScriptSQLitetRPC
Stars7
npm weekly236
agents-client MIT

Connection layer

A tRPC client over one WebSocket: it finds a host through the discovery and credential files, launches one when nothing answers, then mirrors events and reconnects. It is not published — cli and desktop each inline it into their own build.

TypeScripttRPCWebSocket
Stars7
npm weekly—
cli MIT

Terminal client (interface + pipeline)

One executable, two ways to use it: an interactive interface on a TTY, and in a pipe ai "…" writes only the answer to stdout with logs on stderr and a three-band exit code. It launches a host through npx when nothing answers locally, and connects when one does.

TypeScriptInktRPC
Stars1
npm weekly346
air

Minimal CLI assistant

One shell tool and nothing else: the AI remembers through the filesystem and migrates context when it fills up. "Do 99% of things with 1% of the features" is the trade-off it makes.

TypeScript
Stars1
npm weekly24
async-queue MIT

Async queue

A queue that implements Symbol.asyncIterator, consumed entry by entry with for await, by one consumer or several. It is the input queue inside the agents kernel: batch-taking and the input/output switches are built on it.

TypeScriptasync iterator
Stars3
npm weekly188
event-bus MIT

Event management

A lightweight event library with on, emit, once, promise and gather. Every kernel event in agents goes through it; subscriber exceptions are caught by the kernel side.

TypeScript
Stars0
npm weekly74
lazy-promise MIT

Lazy promise

The executor runs only when then, catch or finally is called: with no consumer, nothing happens at all.

TypeScript
Stars0
npm weekly11
node-fetch-event-source MIT

SSE client

An EventSource built on fetch: you control headers, POST bodies, cancellation and reconnect logic, without the restrictions of the browser EventSource. Forked from Azure/fetch-event-source.

TypeScriptServer-Sent Events
Stars10
npm weekly446071
socket-pty MIT

A terminal you can host

Starts a real terminal process (bash, vim, a node REPL) and exposes it as a network endpoint over JSON-RPC 2.0 on a socket, so any client speaking that protocol can read and write it. The screen is rendered by xterm-headless, with a separate ./mcp entry for MCP.

TypeScriptJSON-RPC 2.0MCPnode-pty
Stars0
npm weekly13
pdf-parse-mcp MIT

Take PDFs apart for agents

An stdio MCP server that reports coordinates and sizes for text, vector shapes and bitmaps, and rasterises pages on demand — so an agent can reconstruct a design from a PDF instead of receiving a pile of text.

TypeScriptMCPpdfjs
Stars0
npm weekly18
desktop

Desktop workbench

A multi-workspace, multi-session workbench in Electron and Vue 3. Agents run on the resident host and the app persists only its connection settings, so sessions survive a host restart or a different machine.

ElectronVue 3TypeScript
Stars0
npm weekly—
live2d-copilot In progress

AI desktop companion

A Tauri + Vue desktop companion rendered with Live2D that holds a conversation, built on @ai-zen/agents-core and @ai-zen/async-queue. Planned for Steam; still in development.

TauriVue 3Live2D
Coming to Steam
Stars19
npm weekly—

Products live in their own repositories: cli · desktop · air · live2d-copilot

agents

agents has four packages — you can use just part of them

core and sdk alone are enough — no background service needed. Add host when you want survival across restarts, several clients, or sessions posting to each other. client is the connection layer, bundled into the terminal and the desktop app.

  1. 01

    agents-core — kernel

    One input queue, a request-and-tool loop, one event stream. No configuration files, no disk writes, no credentials; runOnce() is just a wrapper over the resident form.

    @ai-zen/agents-core
  2. 02

    agents-sdk — capability face and runtime

    A Scope per directory assembles tools, skills, sub-agents and MCP, with four-dimension permission whitelists, three-level model resolution, two thresholds and handoff; AgentRuntime wakes, registers, and lets sessions post to each other.

    @ai-zen/agents-sdk
  3. 03

    agents-host — resident host

    One SQLite file holds session rows, messages, the input queue, workspaces, credentials, notices and a full-text index; the surface is tRPC procedures plus one event stream, a single instance on loopback only.

    @ai-zen/agents-host
  4. 04

    agents-client — connection layer

    Finds a host through the discovery and credential files, launches one by version pin when nothing answers, then mirrors events and reconnects. Not published: the terminal and the desktop app each inline it.

    @ai-zen/agents-client
Get started

Get started

The documentation covers installation through configuration and deployment; the source is on GitHub, one repository per package.