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
Edit existing agents from main chat: <agent> container gains optional <agent_id> sub-tag for create-vs-edit branching
claw2074c3f75a8f1
diff --git a/src/main/features/group_chat/bus.ts b/src/main/features/group_chat/bus.tsindex 9557fe9e..f11c812a 100644--- a/src/main/features/group_chat/bus.ts+++ b/src/main/features/group_chat/bus.ts@@ -999,7 +999,7 @@ async function runTurn(state: CidState, w: WorkerState, item: QueueItem): Promis// failed) live in plan_executor.onTurnFinished.let workingText = finalText || '';let form: ChatFormPayload | undefined;- let createdAgent: { agent_id: string; name: string } | undefined;+ let createdAgent: { agent_id: string; name: string; kind: 'created' | 'updated' } | undefined;if (actor.kind === 'agent' && workingText) {const r = extractFormFromFinal(workingText, actor.id);@@ -1017,18 +1017,46 @@ async function runTurn(state: CidState, w: WorkerState, item: QueueItem): Promisconst r = extractAgentFieldBlocks(workingText);if (Object.keys(r.fields).length) {workingText = r.cleanText;+ // `<agent_id>` present → edit an existing custom agent;+ // absent → create a new one. Same `<agent>` container shape;+ // the dispatch decision is single-bit.+ const editId = r.fields.agent_id;try {- const ag = await agentsFeat.createAgentFromBlocks(r.fields);- if (ag) {- createdAgent = { agent_id: ag.agent_id, name: ag.name };+ if (editId) {+ const target = await agentsFeat.getAgent(editId);+ if (!target) {+ workingText = `${workingText}\n\n<span style="color:var(--danger)">⚠️ 智能体编辑失败:找不到智能体 (id=${editId})。</span>`;+ } else if (target.source !== 'custom') {+ // Built-in agent — read-only here; the dev-mode inline edit chat+ // remains the only path that can mutate builtins (per §6).+ workingText = `${workingText}\n\n<span style="color:var(--danger)">⚠️ 内置智能体不能在主对话里改;请在右侧详情面板里 fork 一份再改。</span>`;+ } else if (agentsFeat.isCliAgent(target)) {+ // CLI-backed agent — runtime / model / args are owned by the+ // create-modal + edit-form, not the LLM. Same constraint as+ // chat_agent_setup_cli.md applies to the commander flow.+ workingText = `${workingText}\n\n<span style="color:var(--danger)">⚠️ 外接智能体只能在右侧详情面板里改。</span>`;+ } else {+ const updated = await agentsFeat.updateCustomAgent(editId, r.fields);+ if (updated) {+ createdAgent = { agent_id: updated.agent_id, name: updated.name, kind: 'updated' };+ } else {+ workingText = `${workingText}\n\n<span style="color:var(--danger)">⚠️ 智能体更新失败。</span>`;+ }+ }} else {- // Append failure marker to text — onTurnFinished will surface- // it as a normal `persist` outcome.- workingText = `${workingText}\n\n<span style="color:var(--danger)">⚠️ 智能体创建失败:缺少必要字段(name / workflow)。</span>`;+ const ag = await agentsFeat.createAgentFromBlocks(r.fields);+ if (ag) {+ createdAgent = { agent_id: ag.agent_id, name: ag.name, kind: 'created' };+ } else {+ // Append failure marker to text — onTurnFinished will surface+ // it as a normal `persist` outcome.+ workingText = `${workingText}\n\n<span style="color:var(--danger)">⚠️ 智能体创建失败:缺少必要字段(name / workflow)。</span>`;+ }}} catch (err) {- log.error(`create-agent failed cid=${cid}: ${(err as Error).message}`);- workingText = `${workingText}\n\n<span style="color:var(--danger)">⚠️ 智能体创建失败:${(err as Error).message}</span>`;+ const verb = editId ? '编辑' : '创建';+ log.error(`${editId ? 'edit' : 'create'}-agent failed cid=${cid}: ${(err as Error).message}`);+ workingText = `${workingText}\n\n<span style="color:var(--danger)">⚠️ 智能体${verb}失败:${(err as Error).message}</span>`;}}}diff --git a/src/main/features/group_chat/plan_executor.ts b/src/main/features/group_chat/plan_executor.tsindex f1f4c44e..4fc9ff29 100644--- a/src/main/features/group_chat/plan_executor.ts+++ b/src/main/features/group_chat/plan_executor.ts@@ -121,9 +121,12 @@ export interface TurnFinishedEvent {form?: ChatFormPayload;/** Files written via local-exec tools during this turn. */produced: string[];- /** Quick-create agent meta extracted from `<agent>...</agent>` (commander- * only). When present, executor records but doesn't drive on it. */- createdAgent?: { agent_id: string; name: string };+ /** Agent created or updated from `<agent>...</agent>` (commander only).+ * `kind: 'created'` is the original quick-create flow; `kind: 'updated'`+ * means an existing custom agent was patched in place — same chip slot,+ * different label on the renderer side. Executor records but doesn't+ * drive on it. */+ createdAgent?: { agent_id: string; name: string; kind: 'created' | 'updated' };/** What kind of trigger caused this turn. Drives the state transition. */trigger: TurnTrigger;/** Number of non-error, non-final, non-done events the LLM stream emitted.@@ -142,7 +145,7 @@ export interface TurnFinishedEvent {* turn produces no user-visible output.*/export type TurnOutcome =- | { kind: 'persist'; text: string; form?: ChatFormPayload; produced?: string[]; createdAgent?: { agent_id: string; name: string } }+ | { kind: 'persist'; text: string; form?: ChatFormPayload; produced?: string[]; createdAgent?: { agent_id: string; name: string; kind: 'created' | 'updated' } }| { kind: 'silent' };export interface ReconcileCtx {diff --git a/src/main/prompts/chat_commander.md b/src/main/prompts/chat_commander.mdindex d31315bf..de70474f 100644--- a/src/main/prompts/chat_commander.md+++ b/src/main/prompts/chat_commander.md@@ -222,11 +222,14 @@ The bus asks the user the question in your voice; once the user replies, step 2----## Creating an agent+## Creating or editing an agent-When the user explicitly says "help me crystallize / create / refine an agent from this conversation", base it on the **whole conversation history** in **one shot**, distill "what the user has been doing repeatedly", emit one `<agent>...</agent>` container in this turn and end; do NOT call `dispatch_to`.+Both flows emit ONE `<agent>...</agent>` container in this turn and end (do NOT call `dispatch_to`). The container shape is identical; whether the system creates a new agent or patches an existing one is decided by a single optional first child:-### Field design+- **No `<agent_id>`** → create a brand-new agent from the supplied fields. Triggered when the user says "help me crystallize / create / refine an agent from this conversation"; base it on the **whole conversation history** in **one shot**, distilling "what the user has been doing repeatedly".+- **With `<agent_id>X</agent_id>`** → patch the existing custom agent X. Sub-tags you emit replace; sub-tags you omit are preserved. Triggered when the user says "把 X 的工作流改成…" / "给 X 加一个输入字段叫 Y" / "X 的描述太啰嗦,改清楚一点" etc.++### Field design (applies to both)- **workflow** steps split into "input → action → output"; for each step, write "what to read / which tool/skill to call / what to output / how to handle common pitfalls".- **Prefer built-in tools** (file IO, bash, KB search, PDF render, image gen, web search) — write the tool name directly; don't force-wrap it as a skill. An empty `<skills></skills>` is legal and common.@@ -237,6 +240,7 @@ When the user explicitly says "help me crystallize / create / refine an agent fr```<agent>+<agent_id>(omit when creating; required when editing)</agent_id><name>A short unquoted name</name><description_zh>中文简介:这个智能体做什么 / 什么时候用(按"派活选中"三段式:功能 + 适合用户问法 + 触发词)</description_zh><description_en>English description: what it does / when to use (same three-part formula: function + sample user phrasings + triggers)</description_en>@@ -257,16 +261,42 @@ skill_id_b</agent>```-- Missing `<name>` / `<workflow>` causes the server to treat it as a failure; all other sub-tags are recommended.+- **Creating** (no `<agent_id>`): missing `<name>` / `<workflow>` causes the server to treat it as a failure; all other sub-tags are recommended.+- **Editing** (with `<agent_id>`): every sub-tag except `<agent_id>` is optional; emit only the ones you're changing.- **`<name>` must be written in the user's current UI language** — short, descriptive, no quotes. Chinese UI → Chinese name (e.g. `需求挖掘者`); English UI → English name (e.g. `requirements-miner`). The name is rendered as `@<name>` chips in the conversation and shown in dropdowns / lists, so a name in the wrong language looks alien to the user. The system prompt's trailing language directive carries the active UI language; pick accordingly. **Don't** auto-romanize Chinese into pinyin or auto-translate Chinese to English — match the user's actual locale.- **Both `<description_zh>` and `<description_en>` must be provided** — the commander injects the description in the user's current UI language when dispatching; providing only one means users in the other UI language see an empty description in their list (likely missed in selection). Write the two independently in the three-part form, **don't direct-translate**; each one should appeal to the real phrasings of users in that language. **Do not** use a single `<description>` tag.- `<skills>`: one `skill_id` per line, listing only those that the workflow actually invokes + hard dependencies; the closure is expanded server-side. The `skill_id` must come from the "Available skills (skills)" section; built-in tool names (`read_file` / `bash` / etc.) are NOT `skill_id`s.- `<inputs>` is a JSON array; if no parameters, `[]`; on parse failure the server drops `inputs` but other fields still take effect.- `<interactive>` only accepts the literals `true` / `false`; omitted = `false`.+### Editing an existing agent — required loop++When `<agent_id>` is the right move (the user is asking to change an agent that already exists), follow this loop **before** emitting the container — skipping any step risks silent data loss:++1. **Find the agent's id**. The `agents_index` block above does NOT carry ids — **don't fabricate**. Use `search_files` for an `agent.json` whose `name` matches under `$custom_agents_dir/`, or an equivalent `bash` grep; the directory segment after `$custom_agents_dir/` IS the agent_id.+2. **Read the current spec**: `read_file($custom_agents_dir/<agent_id>/agent.json)`. Never rewrite from memory — `agents_index` only carries a slim view of `inputs_schema`, with no workflow / description / skill_list. Skipping this step ⇒ silently wiping fields you didn't intend to touch.+3. **Confirm the agent is editable here**:+ - `source !== 'custom'` (built-in agent, lives under `$builtin_agents_dir/`) → reply with one prose line "这是内置智能体,不能在主对话里改 —— 你可以在右侧详情里 fork 一份再改" / English equivalent — and stop. **Do not emit `<agent>`**.+ - `runtime.kind === 'cli'` (external CLI agent: claude code / codex / openclaw / opencode / hermes — they bring their own prompt; the runtime / model / args are owned by the create-modal + edit-form, not the LLM) → reply "这是外接智能体,只能在右侧详情面板里改 cwd / 模型 / 启动参数;名字 / 描述也在那里改。" / English equivalent — and stop. **Do not emit `<agent>`**.+4. **Emit `<agent>` with `<agent_id>` first**, and only the sub-tags you're changing. Absent sub-tags preserve the current value. Empty body (e.g. `<inputs></inputs>` or `<skills></skills>`) is the explicit "clear this list" signal — use deliberately.+5. **`<inputs>` is full-list replace, NOT per-id merge**. If the user is "adding a new input field", you must emit the entire updated list (every existing input + the new one). Emitting only the new one wipes the rest. Same rule for `<skills>`.++Example (only the workflow changes):++```+读了一下 X 现在的工作流,把第二步改成先调 kb_search 再 web_search。++<agent>+<agent_id>e81dc193ed6c</agent_id>+<workflow>+... 改写后的完整 workflow markdown ...+</workflow>+</agent>+```+### The conversation prose outside the container is what the user sees-Only talk about "what this agent does / when to use it / what you adjusted this round". **The conversation prose must NOT contain** any of: `interactive` / `inputs` / `skills` / `workflow` / `description` / `name` / `<agent>` / any `<xxx>` tag / `schema` / `closure` / "closure" / `select` / `multiselect` / `default` / `required` / "field" / "config" / "id".+Only talk about "what this agent does / when to use it / what you adjusted this round". **The conversation prose must NOT contain** any of: `interactive` / `inputs` / `skills` / `workflow` / `description` / `name` / `<agent>` / `<agent_id>` / any `<xxx>` tag / `schema` / `closure` / "closure" / `select` / `multiselect` / `default` / `required` / "field" / "config" / "id" / any hex string that looks like an agent_id.When you need to express the corresponding concept, phrase it like this:- `interactive=true` → "It will chat with you back and forth."diff --git a/src/renderer/modules/conversation.js b/src/renderer/modules/conversation.jsindex d39d58a3..e093d307 100644--- a/src/renderer/modules/conversation.js+++ b/src/renderer/modules/conversation.js@@ -937,6 +937,11 @@ function _renderMessageProducedHtml(absPaths) {function _renderMessageCreatedAgentHtml(payload) {if (!payload || !payload.agent_id) return '';const name = payload.name || payload.agent_id;+ // Label is intentionally neutral ("查看详情 / Open: …") — works for both+ // `kind: 'created'` and `kind: 'updated'`; the commander's surrounding+ // prose tells the user which one happened. Don't split the i18n key just+ // to track the verb — the chip is a CTA into the agent panel, not a+ // status badge.return `<div class="chat-msg-created-agent"><span class="chat-msg-created-agent-chip" data-agent-id="${escapeHtml(payload.agent_id)}" title="${escapeHtml(name)}"><span class="chat-msg-created-agent-icon">◆</span>