Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
docs: swap visibility slicing for context budget and memory
cxwc467a3d84111
diff --git a/README.md b/README.mdindex 859b982a..d0e6d2b2 100644--- a/README.md+++ b/README.md@@ -167,16 +167,33 @@ The Commander is the only actor holding dispatch tools — workers and agents haThe Commander has to name its concrete next action *before* it may choose `dispatch_to`; if all that remains is restating the agent's reply, the rule forces `hand_off_to`. That single constraint is what stops a multi-agent chat from ending in a redundant re-summary of what you already read. Emitting several `run_worker` calls in one response runs them concurrently.-### Visibility slicing: no agent reads the whole conversation--The conversation is one canonical jsonl. You and the Commander read it in full; **every agent gets only a slice** — the messages where it appears in `from`, `to`, or `mentions` ([`visibility.ts`](./src/main/features/group_chat/visibility.ts)). The slice is an authorization boundary rather than a replay buffer: agents pull what they need through scope-bounded history tools instead of replaying someone else's context. Fewer tokens, and one agent's private context never leaks into another's.-### One runtime, bounded fan-outEach conversation has a single FIFO runtime, and top-level turns run through it serially; parallelism happens *inside* a turn as nested in-process dispatch ([`bus.ts`](./src/main/features/group_chat/bus.ts)). Two separate semaphores bound it — `globalSlots = 10` across all users, and `dispatchSlots = 4` for nested dispatches (`ORKAS_MAX_DISPATCH_CONCURRENCY`).Nested runs deliberately skip `globalSlots`: the parent turn already holds a slot, so a nested acquire would deadlock as parent-waits-on-child. That shortcut is safe only because dispatch tools belong to the Commander alone, so the semaphore is never acquired re-entrantly — the deadlock is ruled out by construction, not by a timeout.+### Context budget: derived from the model, not a fixed number++Compaction used to fire at fixed token counts — 18K within a turn, 12K across turns — tuned back when 200K was the ceiling. That number meant nothing to a 1M-window model, and it was actively dangerous on a 32K one: its ~25K of usable input never reached an 18K trigger with enough room left to act, so the guard failed exactly the model that needed it most. The budget is now derived top-down ([`context-budget.ts`](./src/core-agent/src/agent/context-budget.ts)):++```+usableInput = contextWindow − maxOutputTokens − safety+messageBudget = max(usableInput × 0.2, usableInput − systemPrompt − toolDefs)+```++Every trigger is a share of `messageBudget` — 0.3 for the in-turn layer, 0.2 for cross-turn history, 0.1 for one round's inline tool results — and everything else derives from its trigger, so the shares are the only tunable surface. They sum to well under 1, leaving room for injected runtime state and for the growth that happens between a trigger firing and its summary landing. The `max` is a fuse: when a large tool set would otherwise swallow the window, messages keep a floor share instead of computing a negative budget.++There is deliberately **no cap on how many times a run may compact successfully**. That ceiling existed twice and failed the same way both times: once reached, context can only grow, the inline-result allowance falls to zero, and the agent keeps calling tools whose output it can no longer see — silently, until the request finally overflows. What gets bounded instead is wasted work: a fingerprint check refuses to compact identical state twice, a minimum-savings threshold rejects passes that would free too little, and three consecutive failures stop LLM-backed compaction.++Summarization loses detail, so what an agent must not forget is kept as structure rather than prose. A workspace ledger of files written, files read, and commands run survives compaction ([`workspace-state.ts`](./src/core-agent/src/agent/workspace-state.ts)), and a spin detector — two or more compactions plus 75% of the tool budget consumed — nudges the agent once to re-anchor on that ledger instead of re-deriving work it just summarized away.++### Memory: hybrid retrieval over a local index++A knowledge base is a SQLite index built on your machine — FTS5 for full text, stored vectors for similarity ([`memory/`](./src/core-agent/src/memory)). Documents are chunked at 512 lines with 64 lines of overlap; a query runs both ways and the two ranked lists merge by reciprocal rank fusion, weighted 0.7 vector to 0.3 keyword. Agents reach it through `memory_search` and `memory_read`, over stored documents and past sessions alike.++Embeddings are computed **on device** by a bundled ONNX model (`bge-small-zh-v1.5`, ~95 MB, fetched once during install), so indexing a knowledge base sends nothing anywhere. Cloud embedding providers — OpenAI, Gemini, Voyage, Mistral — are available if you prefer them.+### Four independent runaway guards- **Turn ceiling** — `MAX_WORKER_TURNS = 100` counts turns, not wall-clock time, so a slow-but-progressing model isn't killed.diff --git a/README.zh-CN.md b/README.zh-CN.mdindex b9ecced3..d65b810e 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -167,16 +167,33 @@ run.cmd # Windows指挥官必须**先**说出自己具体的下一步动作,才可以选 `dispatch_to`;如果剩下的事只是复述智能体的回复,规则就强制它改用 `hand_off_to`。正是这一条约束,让多智能体对话不会以"把你刚读过的内容再总结一遍"收尾。在同一次回复里发出多个 `run_worker` 调用,它们会并发执行。-### 可见性切片:没有智能体能读到完整对话--对话是一份规范的 jsonl。你和指挥官读到全文;**每个智能体只拿到一个切片** —— 即它出现在 `from`、`to` 或 `mentions` 中的那些消息([`visibility.ts`](./src/main/features/group_chat/visibility.ts))。切片是授权边界而非重放缓冲:智能体通过限定作用域的历史工具按需取用,而不是重放别人的上下文。既省 token,也让一个智能体的私有上下文不会泄漏给另一个。-### 单一运行时,有界扇出每个对话只有一个 FIFO 运行时,顶层回合串行通过它;并行发生在回合**内部**,以进程内嵌套派发的形式([`bus.ts`](./src/main/features/group_chat/bus.ts))。两个独立的信号量为它设界 —— 跨所有用户的 `globalSlots = 10`,以及用于嵌套派发的 `dispatchSlots = 4`(可用 `ORKAS_MAX_DISPATCH_CONCURRENCY` 覆盖)。嵌套运行刻意跳过 `globalSlots`:父回合已经占着一个槽位,嵌套获取会造成"父等子"的死锁。这个捷径之所以安全,只因为派发工具专属于指挥官,信号量不可能被重入获取 —— 死锁是被构造排除的,而不是靠超时兜底。+### 上下文预算:由模型推导,而不是写死一个数++压缩过去按固定 token 数触发 —— 回合内 18K、跨回合 12K —— 这些数字是在 200K 还是上限的年代调出来的。对 1M 窗口的模型它毫无意义;而对 32K 窗口的模型它是真有害:那约 25K 的可用输入根本到不了 18K 触发点、也就没有余量再做处置,于是最需要保护的模型恰恰没被保护。现在预算改为自顶向下推导([`context-budget.ts`](./src/core-agent/src/agent/context-budget.ts)):++```+usableInput = 上下文窗口 − 最大输出 token − 安全余量+messageBudget = max(usableInput × 0.2, usableInput − 系统提示 − 工具定义)+```++每个触发阈值都是 `messageBudget` 的一个份额 —— 回合内层 0.3、跨回合历史 0.2、单轮内联工具结果 0.1 —— 其余参数都由触发阈值派生,因此这几个份额是唯一的可调面。它们的总和远小于 1,留出的余量用于回灌的运行时状态,以及"触发发生到摘要落地"之间仍在继续的增长。那个 `max` 是保险丝:当工具集大到会吃掉整个窗口时,消息仍保有一个底线份额,而不是算出一个负预算。++**一次运行成功压缩的次数刻意不设上限。** 这个上限存在过两次,两次都以同样的方式失效:一旦触顶,上下文只会继续增长,内联结果额度归零,智能体继续调用那些它已经看不到输出的工具 —— 全程无报错,直到请求真正溢出。真正需要设界的是无效功,而那些守卫另有其人:指纹校验拒绝对同一状态重复压缩,最小收益阈值拒绝那些释放太少的压缩,连续三次失败则停止 LLM 压缩。++摘要必然丢细节,所以智能体绝不能忘的东西不交给散文承载。一份记录"写过哪些文件、读过哪些文件、跑过哪些命令"的工作台账会以结构形式挺过压缩([`workspace-state.ts`](./src/core-agent/src/agent/workspace-state.ts));另有一个空转检测 —— 压缩两次以上且工具预算已消耗 75% —— 会提醒智能体一次,让它回到台账重新锚定,而不是把刚被摘要掉的工作再推导一遍。++### 记忆:本地索引上的混合检索++资料库是一份构建在你本机的 SQLite 索引 —— 用 FTS5 做全文、用存储的向量做相似度([`memory/`](./src/core-agent/src/memory))。文档按 512 行切块、块间重叠 64 行;一次查询两路并发,两个排序结果用 reciprocal rank fusion 融合,权重为向量 0.7、关键词 0.3。智能体通过 `memory_search` 与 `memory_read` 访问它,检索范围同时覆盖存入的文档和历史会话。++嵌入向量**在本机计算**,由随包的 ONNX 模型完成(`bge-small-zh-v1.5`,约 95 MB,安装时下载一次),因此建立资料库索引不会把任何内容发出去。如果你更愿意用云端嵌入服务,OpenAI、Gemini、Voyage、Mistral 也都支持。+### 四道互相独立的失控保护- **轮次上限** —— `MAX_WORKER_TURNS = 100` 计的是回合数而非墙钟时间,因此一个慢但在推进的模型不会被误杀。