🤖 Open-source, local-first alternative to Grok Bot, OpenAI dots and Claude Duet. Your own AI bots on any model: GPT, Claude, Gemini, Grok, DeepSeek, Kimi, GLM and 70+ more through one Modelflare key. Reach them in the app, WeChat or Feishu; they remember you, work in the background, run commands and use your computer. Pay per use.
Python ai-agentai-assistantchatbotclaudecomputer-usedeepseekdesktop-appdshelectronfeishugeminigptgrokllmlocal-firstmodelflaremulti-modelopenai-compatiblepersonal-ai-agentwechat
docs: persona and prompts, media confirmation only when needed, notice after a restart
Marlae6bcb1e6eb7d
diff --git a/README.md b/README.mdindex 801e351..728ba9d 100644--- a/README.md+++ b/README.md@@ -186,6 +186,7 @@ docker exec amb cat /data/ui-token # 然后打开 http://<主机>:3600/?token=- **真正的文件操作。** 机器人能读写文件、在沙箱里执行命令,并把结果作为文件发回聊天。- **每个机器人三档权限。** *只读*、*工作区*(默认:只能写自己的文件夹,越界先问你)、*完全权限*(不进沙箱;递归删除仍会先问)。- **审批卡片,没有意外。** 越界的操作会停下来,等你回答。+- **重启了也会告诉你。** 应用退出或崩溃时还没处理完的消息,下次启动会在原对话里说一声,请你重新发送,不会自动重做。- **斜杠命令**,如 `/model`、`/reset`,在应用里和微信、飞书对话中都能用。<p align="center">@@ -195,7 +196,7 @@ docker exec amb cat /data/ui-token # 然后打开 http://<主机>:3600/?token=## 🖥️ 操作你的电脑,生成图片和视频- **电脑操作**由内置的 [Cua Driver](https://github.com/trycua/cua) 提供。默认自动执行;把某个机器人切到「改变界面前先问我」,每一次点击和输入都要等你点头。读取屏幕内容永远不需要审批。macOS 上的电脑操作是 Beta 功能。-- **图片和视频生成**每次运行前都会先问你,先让你看到模型和提示词,也可以当场换模型。+- **图片和视频生成**用默认模型、花费不高时直接生成;要换模型、预计花费较高或要求不明确时先问你,让你看到模型和提示词,也可以当场换模型。想每次都确认,在机器人设置里打开即可。<p align="center"><img src="docs/assets/features/computer-use.gif" alt="机器人打开记事本、输入一段备忘并保存,每次点击和输入前都有审批卡片" width="100%">diff --git a/README_en.md b/README_en.mdindex c668860..ae9ce65 100644--- a/README_en.md+++ b/README_en.md@@ -186,6 +186,7 @@ A bot is more than a chat window: it has a persona, a default model, its own wor- **Real file work.** Bots read and write files, run commands in a sandbox, and send the results back to the chat as files.- **Three permission presets per bot.** *Read-only*, *Workspace* (the default: write inside the bot's own folder, ask before anything outside) and *Full access* (no sandbox; recursive deletes still ask first).- **Approval cards, not surprises.** Out-of-bounds actions stop and wait for your answer.+- **Told after a restart.** A message still in progress when the app quit or crashed is flagged in its conversation at the next start, so you can send it again; nothing is redone on its own.- **Slash commands** such as `/model` and `/reset` work in the app and in WeChat and Feishu chats.<p align="center">@@ -195,7 +196,7 @@ A bot is more than a chat window: it has a persona, a default model, its own wor## 🖥️ Operates your computer, and makes images and video- **Computer use** is powered by the bundled [Cua Driver](https://github.com/trycua/cua). By default, actions run automatically. Switch a bot to *ask before changing the screen* and every click and keystroke waits for you. Reading the screen never needs approval. On macOS, computer use is a Beta feature.-- **Image and video generation** asks before every run, so you see the model and prompt first and can swap the model on the spot.+- **Image and video generation** runs right away with the default model at a normal cost. It asks first when switching models, when the estimated cost is high or when the request is unclear, so you see the model and prompt and can swap the model on the spot. To be asked every time, turn it on in the bot's settings.<p align="center"><img src="docs/assets/features/computer-use.gif" alt="A bot opens Notepad, types a short note and saves it, while an approval card asks before each click and keystroke" width="100%">diff --git a/docs/development.md b/docs/development.mdindex bde684c..2ad316b 100644--- a/docs/development.md+++ b/docs/development.md@@ -12,8 +12,9 @@```src/- core/ 统一消息类型、会话队列与去重、运行时(/model /reset、流式)+ core/ 统一消息类型、会话队列与去重、运行时(/model /reset、流式)、重启后的提醒agent/ 代理模式:DSH 宿主与桥接、审批、权限预设、记忆与上下文管家、生图 / 生视频、电脑操作、Windows PowerShell+ prompts/ 交给代理模型的全部提示词:人设、聊天规则、记忆说明、每段第一条消息、技能说明llm/ OpenAI 兼容客户端(模型接入接口)magpie/ 内置 magpie 守护:隔离目录、空闲端口、自动生成密钥、健康检查、崩溃重启、干净退出channels/ feishu/(长连接 + CardKit) weixin/(iLink,MIT 声明见 LICENSE.openclaw-weixin)@@ -87,7 +88,7 @@ docker exec amb cat /data/ui-token # 打开 http://<主机>:3600/?token=<令- 登录后还能在 设置 → Modelflare 查看按天、按模型的用量,Modelflare 发来的通知,以及复制邀请链接。- 机器人预算(需要登录):机器人设置 → 预算,开启后这个机器人用自己的 Key(内置网关里单独的 provider),最多花设定的美元数;关闭后回到共用的 Key。- 生图 / 生视频:代理模式下机器人有 `media_models`(可用模型、默认模型、参数范围、参考价)、`media_docs`(从 docs.modelflare.dev 实时读该模型的请求格式)、`generate_image`、`generate_video` 四个工具,并自带一份 media 技能说明。各模型的参数格式不同,机器人按文档写请求体,工作区里的参考图写成 `workspace:路径` 即可;Key 始终只在本程序里,由本程序带着该机器人用的 Key 调 Modelflare,结果存进机器人工作区的 `media/`,再交付到聊天。-- 生成前确认:每次生成图片或视频之前都会在聊天里问你这次用哪个模型(附提示词、参数和参考价),可以确认、换成别的模型或取消;微信回复编号或模型名,飞书 / 网页点选。10 分钟内没回答就不生成。+- 生成前确认:用默认模型、预计花费不超过 $0.5 时直接生成,不打扰你。只在这几种情况先在聊天里问你这次用哪个模型(附提示词、参数、参考价和为什么问):机器人要换用不是默认的模型(你点名的除外,代理传 `confirm: false`)、预计花费超过 $0.5(按参考价、张数、视频时长和分辨率估算;视频估不出来也问)、要求不明确(代理传 `confirm: true`)。可以确认、换成别的模型或取消;微信回复编号或模型名,飞书 / 网页点选。10 分钟内没回答就不生成。想每次都确认:机器人设置 → 生图 / 生视频 → 生成前确认 →「每次都问」。- 默认图片 / 视频模型:首次设置时和默认文本模型一起选,之后在 设置 → Modelflare 修改;选「自动」时用推荐顺序里第一个不需要参考素材的模型。- 模型选择器里显示上下文长度、视觉 / 工具 / 推理能力,以及每百万 tokens 输入 / 输出的起步参考价(来自公开价格目录,以账单为准)。- 调用归因:经 Modelflare 的请求都带 `X-Modelflare-Skill: anymodel-bot/<版本>`,链接都带 `utm_source=anymodelbot`。@@ -96,6 +97,7 @@ docker exec amb cat /data/ui-token # 打开 http://<主机>:3600/?token=<令- 对话中输入框右侧的模型按钮可为当前会话切换模型(也可设为机器人默认);`/model`、`/reset`、`/new`、`/status`、`/stop`、`/help` 照常可用。- 处理过程:代理回合的每一步(模型请求及用时与 tokens、工具调用及参数与输出、重试、子代理)折叠在回复上方的"用时"一行里,点开查看;微信 / 飞书会话在信息面板 → 最近会话里看,正在处理的那一轮实时显示并可中止。- 卡住的消息:`/stop`(任何渠道)或信息面板里的「中止」立即结束正在处理的回合;代理 10 分钟没有任何进展(模型不回、工具不动、只在重试;等你批准或回答不算)会自动中止,单回合最长 30 分钟(`AMB_AGENT_IDLE_TIMEOUT_MS`、`AMB_AGENT_TURN_TIMEOUT_MS` 可调)。DSH 没有中断单个回合的接口,中止时会重启该机器人的代理进程。前一条还在处理时发来的新消息会先收到一句提示;`/status` 显示它走到了哪一步、多久没有进展。网页对话里切到别的机器人或刷新窗口不会打断正在处理的消息,回来时接着显示(你的消息、到目前为止的回复和处理过程);停止按钮在排队、代理启动中、等你批准时也能用,纯对话也一样。+- 重启后的提醒:应用退出或崩溃时还没处理完的消息(每个会话在数据库里留一个处理中的标记,处理完就删),下次启动时在原会话里说一次「上次的消息「…」因为应用重启没有处理完,请重新发送」,不会自动重发。网页对话记进会话历史;微信用存下的 context_token 发送、占用同一份回复配额,超过 24 小时窗口或配额用完时等你在那个会话里发下一条消息时先说;飞书发到原单聊。- 代理的对话接口:代理按 Modelflare 公开目录里该模型支持的接口选——有 Responses API 的(GPT-5.4 及以后、Grok 4.5 及以后、DeepSeek V4、GLM-5、Kimi K3 等)走 `/v1/responses`(推理模型默认推理强度 medium,加密推理随历史回放);没有 Responses、有 Anthropic Messages 的(Claude)走 `/v1/messages`;其余模型、拿不到目录时(离线、中国大陆线路)以及外部端点走 Chat Completions。接口在拉起代理进程时选定(故障排查的代理状态里显示 `api`);`AMB_AGENT_API=chat` 强制全部走 Chat Completions(排查用)。纯对话(非代理)仍走 Chat Completions。安全网:某个模型在 Responses / Messages 上的请求被上游拒绝(HTTP 400/404/405/415/422 或“不支持的参数 / 接口”,限流、余额、权限、上游故障、上下文过长不算)时,这个模型 24 小时内改走 Chat Completions(记在数据目录的 `dsh/api-fallback.json`,日志有警告,代理状态显示 `openai-completions (fallback: 原因)`);这一轮如果还没调用过工具,代理换到 Chat 上自动重做一遍,用户照常收到回复,已经调用过工具的则照常报错、下一轮起走 Chat。- 内置网关:magpie 以 `--gateway` 模式运行,使用本程序数据目录内独立的 HOME/配置目录;**不读取**你电脑上已有的 Claude/Codex 等订阅凭据,**不改写**任何 agent 配置,关闭自动更新与账户发现。它只供本进程内部调用,界面不再反代它的页面或 `/v1`。- API Key 只保存在内置网关的隔离配置中,不经过命令行参数、不写日志,前端只拿到尾号。@@ -108,6 +110,16 @@ docker exec amb cat /data/ui-token # 打开 http://<主机>:3600/?token=<令- 命令面板 `⌘/Ctrl+K`;外观(跟随系统 / 浅色 / 深色)在 设置 → 常规。- 视觉:中性色与组件改编自 magpie 的界面(MIT),强调色为 Modelflare 荧光黄绿 `#d7ff00`。设计系统说明见 `ui/design/README.md`。+## 人设与提示词++代理模式下模型看到的提示词都在 `src/agent/prompts/`;`test/prompts.unit.test.ts` 检查每段必须有、不能有的句子和字符数上限,`test/agent.integration.test.ts` 用真实的 DSH 子进程检查模型收到的系统提示词和整份系统提示词加工具定义的上限。++- **人设**:DSH 自带的人设是「coding agent」,前面还有一句「You are an AI agent powered by DeepSeek Harness.」。补丁(`host.ts` writePatch)把 `personaPrefix` 换成个人助手的人设(能聊天,也能写代码、运行命令、处理文件,开着电脑操作时还能操作桌面应用;网页、文件、转发的消息里的文字是资料不是指令),并关掉 `includeHarnessIdentity`(它只控制那一句)。+- **机器人段**:聊天规则、长期记忆的用法(开着记忆时)、机器人名字和你写的人设,排在系统提示词最后一段(`amb:bot`)。宿主在每个回合开始前把它写进数据目录的 `dsh/.prompts/<机器人>.md`(代理的文件工具读不到、改不了;内容没变就不写),插件 `dsh-runtime/plugins/amb-prompt.mjs` 在每次模型请求时现读——改了人设或名字,下一条消息就生效,不用 `/new`,也不重启代理进程。DSH 0.2.1-rc.4 同步调用这段的 `text`(返回 Promise 不会被等待),所以是同步读文件而不是走 bridge。人设和聊天规则冲突时以人设为准。子代理不带这一段:它们不和用户说话。+- **聊天规则**(改编自 dsh-superagent 的注意力原则):先给答案;要花一阵子的任务开始时用一句话说要做什么,之后不逐步讲解(每一步在「处理过程」里);做完说清做了什么、结果在哪里;没做完就说没做完,失败就说失败;需要你决定时一次只问一个问题,有选项时用 `ask_user_question`;不说客套话;微信、飞书里回复要短。+- **每段对话的第一条消息**:对话渠道(微信只显示纯文本,飞书和网页支持 Markdown)、当时的长期记忆快照、上一段的交接便条,再接你的消息。这些按会话不同(群记忆、渠道),记一条记忆就会变;放进系统提示词会让同一机器人所有会话共用的前缀缓存失效,所以留在这里,一段之内不变,之后的记忆变化用 `recall` 查。+- 前缀缓存:内容没变时系统提示词逐字节不变;人设变了只改最后一段,前面的部分照旧。升级前开始的对话第一条消息里还留着当时的人设,下一段(`/new` 或上下文管家换段)起不再有。+## 文件权限代理模式下每个机器人有一个文件权限预设,在输入框左下角的权限胶囊或 机器人设置 → 权限 中切换,`/status` 会显示当前预设:diff --git a/docs/development_en.md b/docs/development_en.mdindex a31d0a7..70cc113 100644--- a/docs/development_en.md+++ b/docs/development_en.md@@ -12,8 +12,9 @@ This guide is for people who want to run AnyModelBot from source, package it, or```src/- core/ shared message types, session queue and dedup, runtime (/model /reset, streaming)+ core/ shared message types, session queue and dedup, runtime (/model /reset, streaming), the notice after a restartagent/ agent mode: DSH host and bridge, approvals, permission presets, memory and context steward, image / video generation, computer use, Windows PowerShell+ prompts/ every prompt the agent model reads: persona, chat rules, memory guide, a segment's first message, skillsllm/ OpenAI-compatible client (model access interface)magpie/ magpie supervisor: isolated directories, free port, generated secret, health checks, crash restart, clean exitchannels/ feishu/ (long connection + CardKit) weixin/ (iLink; MIT notice in LICENSE.openclaw-weixin)@@ -87,7 +88,7 @@ Inside the container the console listens on 0.0.0.0, so token access is enforced- When signed in, Settings → Modelflare also shows usage per day and per model, notifications from Modelflare, and your invite link.- Bot budgets (requires sign-in): Bot settings → Budget. When enabled, the bot uses its own key (a separate provider in the gateway) capped at the dollar amount you set; when disabled it goes back to the shared key.- Image / video generation: in agent mode, bots get four tools — `media_models` (available models, defaults, parameter ranges, reference prices), `media_docs` (reads the model's request format live from docs.modelflare.dev), `generate_image` and `generate_video` — plus a bundled media skill. Parameter formats differ per model, so the bot writes the request body from the docs; reference images in the workspace are written as `workspace:path`. The key never leaves the app: the app calls Modelflare with the bot's key, saves results in the bot workspace's `media/`, and delivers them to the chat.-- Confirmation before generation: before every image or video generation, the chat asks which model to use (with prompt, parameters and reference price). You can confirm, switch models or cancel — reply with a number or model name on WeChat, or click on Feishu / the web console. With no answer within 10 minutes, nothing is generated.+- Confirmation before generation: with the default model and an estimated cost of at most $0.5, the image or video is generated right away. The chat asks which model to use (with prompt, parameters, reference price and the reason for asking) only when the bot wants a model other than the default (unless you named it; the agent passes `confirm: false`), when the estimated cost is above $0.5 (from the reference price, number of images, video length and resolution; a video whose cost cannot be estimated is asked too), or when the request is ambiguous (the agent passes `confirm: true`). You can confirm, switch models or cancel — reply with a number or model name on WeChat, or click on Feishu / the web console. With no answer within 10 minutes, nothing is generated. To confirm every time: bot settings → Images / videos → Confirm before generating → "Every time".- Default image / video models: chosen together with the default text model during first-run setup, changeable later in Settings → Modelflare. "Auto" uses the first model in the recommended order that needs no reference material.- The model picker shows context length, vision / tools / reasoning capabilities, and starting reference prices per million input / output tokens (from the public price catalog; your bill is authoritative).- Attribution: requests through Modelflare carry `X-Modelflare-Skill: anymodel-bot/<version>`, and links carry `utm_source=anymodelbot`.@@ -96,6 +97,7 @@ Inside the container the console listens on 0.0.0.0, so token access is enforced- The model button to the right of the composer switches the model for the current session (or sets it as the bot default); `/model`, `/reset`, `/new`, `/status`, `/stop` and `/help` all work.- Activity: every step of an agent turn (model requests with timing and tokens, tool calls with arguments and output, retries, sub-agents) is folded into the "time" line above the reply; click to expand. For WeChat / Feishu sessions, see info panel → Recent sessions, where the turn in progress is shown live and can be aborted.- Stuck messages: `/stop` (any channel) or "Abort" in the info panel ends the current turn immediately. A turn with no progress for 10 minutes (no model reply, no tool activity, only retries; waiting for your approval or answer does not count) is aborted automatically, and a single turn is capped at 30 minutes (`AMB_AGENT_IDLE_TIMEOUT_MS`, `AMB_AGENT_TURN_TIMEOUT_MS`). DSH has no API to interrupt a single turn, so aborting restarts that bot's agent process. A new message that arrives while the previous one is still being handled gets a short notice first; `/status` shows which step it reached and how long since the last progress. In the web chat, switching to another bot or reloading the window does not interrupt a message in progress; when you return it picks up where it was (your message, the reply so far and the activity). The stop button also works while queued, while the agent is starting and while waiting for approval, and for plain chat too.+- Notice after a restart: a message still being handled when the app quit or crashed (each conversation keeps an in-progress marker in the database, removed when the message is done) is reported once in its conversation at the next start — "上次的消息「…」因为应用重启没有处理完,请重新发送" (the last message was not finished because the app restarted; please send it again). Nothing is resent automatically. The web chat gets it in its history; WeChat uses the stored context_token and the same reply quota, and when the 24-hour window or the quota has run out it is said before the reply to your next message in that conversation; Feishu sends it to the original chat.- Agent API: the agent picks the API from what the Modelflare public catalog says the model supports — models with the Responses API (GPT-5.4 and later, Grok 4.5 and later, DeepSeek V4, GLM-5, Kimi K3 and others) use `/v1/responses` (reasoning models default to medium effort; encrypted reasoning is replayed with history); models without Responses but with Anthropic Messages (Claude) use `/v1/messages`; all other models, the case where the catalog is unavailable (offline, the mainland China route) and external endpoints use Chat Completions. The API is chosen when the agent process starts (shown as `api` in the agent status under Troubleshooting); `AMB_AGENT_API=chat` forces Chat Completions everywhere (for troubleshooting). Plain chat (non-agent) still uses Chat Completions. Safety net: when the upstream rejects a model's Responses / Messages request (HTTP 400/404/405/415/422 or "unsupported parameter / endpoint"; rate limits, balance, permissions, upstream outages and context overflows do not count), that model switches to Chat Completions for 24 hours (recorded in `dsh/api-fallback.json` in the data directory, with a warning in the log, and the agent status shows `openai-completions (fallback: reason)`). If the turn has not called any tool yet, the agent redoes it on Chat automatically and the user still gets a reply; if it already called tools, the error is reported and the next turn uses Chat.- Built-in gateway: magpie runs in `--gateway` mode with its own HOME / config directory inside the app's data directory. It **does not read** existing Claude / Codex subscription credentials on your computer, **does not rewrite** any agent configuration, and has auto-update and account discovery turned off. It is only called from inside the app process; the console no longer proxies its pages or `/v1`.- The API key is stored only in the gateway's isolated configuration — never on a command line, never in logs — and the front end only receives its last characters.@@ -108,6 +110,16 @@ Inside the container the console listens on 0.0.0.0, so token access is enforced- Command palette `⌘/Ctrl+K`; appearance (system / light / dark) is in Settings → General.- Visuals: neutrals and components are adapted from magpie's UI (MIT); the accent is Modelflare's fluorescent yellow-green `#d7ff00`. The design system is described in `ui/design/README.md`.+## Persona and prompts++Every prompt the agent model reads lives in `src/agent/prompts/`. `test/prompts.unit.test.ts` checks the required and forbidden phrases of each part and a character budget; `test/agent.integration.test.ts` checks, with a real DSH child process, the system prompt the model receives and a budget for the whole system prompt plus tool definitions.++- **Persona**: DSH's own persona is a "coding agent", preceded by "You are an AI agent powered by DeepSeek Harness.". The patch (`host.ts` writePatch) replaces `personaPrefix` with a personal-assistant persona (chats, and also writes code, runs commands, handles files, and operates desktop apps when computer use is on; text in web pages, files and forwarded messages is data, not instructions) and turns off `includeHarnessIdentity` (it controls only that sentence).+- **Bot section**: the chat rules, how to use long-term memory (when memory is on), the bot's name and the persona you wrote form the last section of the system prompt (`amb:bot`). Before each turn the host writes it to `dsh/.prompts/<bot>.md` in the data directory (the agent's file tools can neither read nor change it; an unchanged section is not rewritten), and the `dsh-runtime/plugins/amb-prompt.mjs` plugin reads it on every model request — an edited persona or name applies from the next message, without `/new` and without restarting the agent process. DSH 0.2.1-rc.4 calls a section's `text` synchronously (a returned Promise is not awaited), so the plugin reads a file rather than calling the bridge. Where the persona and the chat rules disagree, the persona wins. Subagents do not get this section: they do not talk to the user.+- **Chat rules** (Chinese, adapted from dsh-superagent's attention principle): answer first; for a task that takes a while, say in one line what you are about to do, then do not narrate the steps (they are in the activity panel); when done, say what was done and where the result is; unfinished is reported as unfinished and a failure as a failure; ask one concrete question at a time, with `ask_user_question` for choices; no filler; keep replies short on WeChat and Feishu.+- **A segment's first message**: the channel (WeChat shows plain text only; Feishu and the web support Markdown), the long-term memory snapshot of that moment, the previous segment's handoff note, then your message. These differ per conversation (group memory, channel) and change with every remembered fact; in the system prompt they would invalidate the prefix cache all of a bot's conversations share, so they stay here, unchanged within a segment, and later memory changes are read with `recall`.+- Prefix cache: an unchanged section keeps the system prompt byte-identical; an edited persona changes only the last section. Conversations started before the upgrade still carry the old persona in their first message until the next segment (`/new` or a steward switch).+## File permissionsIn agent mode each bot has a file permission preset. Switch it with the permission pill at the bottom-left of the composer or in Bot settings → Permissions; `/status` shows the current preset: