@runappsai/agent

中文文档
0.1.4发布于 2026/11/02MITTypeScriptESM + CJS零依赖

Agent harness: the model ↔ tool loop with a workspace, skills, sessions, compaction, a sandbox and a chat UI. Bring any OpenAI-compatible model provider (RunApps included); no runtime dependencies.

原始使用文档
文档目录7 节
  1. Install
  2. Quick start: a chat in five minutes
  3. Quick start: a command-line agent
  4. Quick start: an agent without any UI
  5. Documentation
  6. Development
  7. License

@runappsai/agent

An agent harness: the model ↔ tool loop, a file workspace with skills, saved sessions, context compaction, a JavaScript sandbox — and, separately, a complete chat UI for web pages and helpers for command-line tools. It works with any OpenAI-compatible model API (RunApps, OpenAI, DeepSeek, OpenRouter, your own proxy) and has no runtime dependencies.

ImportWhatRuns in
@runappsai/agentThe core: createAgent, openWorkspace, providers, tools, skillsBrowsers, Node, Deno, workers
@runappsai/agent/uiThe chat UI: renderChat, dropdowns, themesBrowsers
@runappsai/agent/nodeA folder as the workspace, storage on disk, terminal dialogsNode 18+

Modelled on pi (MIT): the compaction prompts, edit matching, template arguments and skills wording come from it.

Status: test phase — the API may still change.

Install

npm i @runappsai/agent
import { createAgent, openWorkspace, defineTool, openAIProvider } from "@runappsai/agent";
import { renderChat } from "@runappsai/agent/ui";                 // web pages
import { nodeFS, nodeStore, terminalUI } from "@runappsai/agent/node";   // Node

Or in a page, with no build step — the core and the UI in one script, on window.RunAppsAgent:

<script src="https://www.runapps.ai/sdk/agent-latest.js"></script>

(dist/agent-core.umd.js, also @runappsai/agent/browser/core, is the core alone.)

Quick start: a chat in five minutes

<div id="assistant" style="height: 640px"></div>

<script src="https://www.runapps.ai/sdk/agent-latest.js"></script>
<script type="module">
  // With npm: import { openWorkspace, openAIProvider, defineTool } from "@runappsai/agent";
  //           import { renderChat } from "@runappsai/agent/ui";
  const { renderChat, openWorkspace, openAIProvider, defineTool } = RunAppsAgent;

  // 1. Where the model calls go. Keep API keys on your server: point at your own proxy.
  const provider = openAIProvider({ baseURL: "/api/llm", models: "fetch" });

  // 2. A tool of your app's (optional).
  const getTime = defineTool({
    name: "get_time",
    description: "The current date and time in the user's timezone.",
    execute: () => new Date().toString(),
  });

  // 3. The chat. Each conversation gets its own directory of files in IndexedDB.
  const chat = renderChat(document.getElementById("assistant"), {
    provider,
    model: "gpt-4.1",
    appName: "My app",
    instructions: "You are the assistant inside My app. Be brief.",
    tools: [getTime],
    workspace: (sessionId) => openWorkspace(provider, { id: sessionId }),
    suggestions: ["What time is it?", "Write a haiku about Mondays"],
  });
  await chat.ready;
</script>

That is a full assistant: streaming Markdown replies, folded tool calls, a live "what it is doing" status, file attachments, a files panel, a skills menu, saved conversations, slash commands, settings (model, thinking level, limits), rewind, light/dark themes.

With RunApps instead, users sign in and pay for their own usage — no proxy and no key on your side:

<script src="https://www.runapps.ai/sdk/latest.js"></script>
<script src="https://www.runapps.ai/sdk/agent-latest.js"></script>
<script type="module">
  const client = new RunApps({ project: "my-app" });
  const chat = RunAppsAgent.renderChat(document.getElementById("assistant"), {
    client,
    workspace: (id) => RunAppsAgent.openWorkspace(client, { id }),
  });
</script>

Quick start: a command-line agent

import { createAgent, openAIProvider, openWorkspace } from "@runappsai/agent";
import { nodeFS, nodeStore, terminalUI } from "@runappsai/agent/node";

const provider = openAIProvider({ baseURL: process.env.OPENAI_BASE_URL, apiKey: process.env.OPENAI_API_KEY, models: "fetch" });
const workspace = await openWorkspace(provider, {
  id: "my-project",
  dir: nodeFS(process.cwd()),      // the agent works in this folder
  store: nodeStore(),              // sessions and skills in ~/.runapps-agent
});
const agent = createAgent(provider, { workspace, ui: terminalUI() });   // confirmations as y/N in the terminal

agent.on("text_delta", (e) => process.stdout.write(e.delta));
await agent.prompt(process.argv.slice(2).join(" "));

examples/cli.mjs is a complete terminal chat: streaming, tool calls, confirmations, sessions you can resume, Ctrl+C to stop. See Node and the command line.

Quick start: an agent without any UI

import { createAgent, defineTool, openAIProvider } from "@runappsai/agent";

const provider = openAIProvider({ baseURL: "https://api.deepseek.com/v1", apiKey: process.env.DEEPSEEK_KEY });

const addTodo = defineTool({
  name: "add_todo",
  description: "Add an item to the user's todo list.",
  parameters: {
    type: "object",
    properties: { text: { type: "string" }, due: { type: "string", description: "YYYY-MM-DD" } },
    required: ["text"],
    additionalProperties: false,
  },
  execute: async ({ text, due }) => { await db.todos.add({ text, due }); return `Added "${text}".`; },
});

const agent = createAgent(provider, {
  model: "deepseek-chat",
  instructions: "You manage the user's todo list.",
  tools: [addTodo],
  sandbox: false,        // no run_js
  askUser: false,        // no questions back to a user
});

agent.on("text_delta", (e) => process.stdout.write(e.delta));
const result = await agent.prompt("Add 'ship v2' for next Friday");
console.log(result.reason, result.usage);

Documentation

GuideWhat is in it
ProvidersConnecting a model API: openAIProvider, runappsProvider, writing your own, errors and retries
The agentRuns, steering and queueing, stopping and continuing, events, permissions and dialogs, sessions, compaction, all options
ToolsdefineTool, schemas, results, confirmations, progress, calls that go nowhere, MCP servers, the built-in tools
Workspace and filesThe virtual directory, mounting your app's data, a real folder, memory and project notes, prompt templates, PDFs, change events
SkillsSkill folders and zips, the app's skills, lazy skills, the user's skills, writing descriptions
Chat UIrenderChat options and handle, what the UI does, commands, one-conversation mode, theming, dropdowns, debug
Node and the command lineA folder as the workspace, storage on disk, terminal dialogs, PDFs, the CLI example
API referenceEvery export in one place

examples/chat/index.html is a complete page using everything (serve the package root and open /examples/chat/index.html); examples/cli.mjs is the terminal version.

Development

npm install
npm run build     # dist/*.js (ESM), dist/{index,ui,node}.cjs, dist/agent.umd.js + agent-core.umd.js (browser)
npm test          # node:test on the built output, model calls mocked

License

MIT

版本与发布记录

@runappsai/agent 共发布 6 个版本,首次发布于 2026/11/01;过去 12 个月发布了 6 个版本。

版本发布日期距今
0.1.4latest2026/11/021 天前
0.1.32026/11/021 天前
0.1.22026/11/021 天前
0.1.12026/11/021 天前
0.1.02026/11/011 天前
0.0.0-stage2026/11/011 天前

关于 @runappsai/agent 的常见问题

@runappsai/agent 是什么?

Agent harness:有工作区、技能、会话、压缩、沙盒和聊天UI的模型↔工具循环。带来任何兼容openai的模型提供商(包括RunApps);没有运行时依赖项。

如何安装 @runappsai/agent?

在项目目录运行 npm install @runappsai/agent,或使用 pnpm add / yarn add / bun add。

@runappsai/agent 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@runappsai/agent 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@runappsai/agent 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@runappsai/agent 可以商用吗?

@runappsai/agent 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@runappsai/agent 还在维护吗?

最新版本 0.1.4 发布于 2026/11/02(1 天前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/11/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。