|
| 1 | +# Ask Assistant — Design |
| 2 | + |
| 3 | +> A fast, read-mostly **sidecar assistant** that rides alongside a running |
| 4 | +> mission. It can read the full mission history, run bash in the live workspace, |
| 5 | +> and answer questions — **without interrupting the main agent's turn loop or |
| 6 | +> queue**. Powered by a configurable fast model (default: Cerebras |
| 7 | +> `gpt-oss-120b`). |
| 8 | +
|
| 9 | +Status: **M1 backend implemented** (store + client + loop + HTTP routes, |
| 10 | +compiles, storage unit-tested). M2–M5 pending. |
| 11 | +Owner: Thomas |
| 12 | +Related: conversation-anchored snapshot (#477, #482), thinking capture (#481), |
| 13 | +Cerebras title fix (#489), `metadata_llm.rs` provider ladder. |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## 1. Goals & non-goals |
| 18 | + |
| 19 | +### Goals |
| 20 | +- Let the operator **chat about what a mission is doing** at any time, in a |
| 21 | + separate lane that never touches the harness lock, the message queue, or the |
| 22 | + mission transcript fed back to the working agent. |
| 23 | +- Give the assistant **real capability**: full read+write `bash` in the live |
| 24 | + workspace plus history retrieval. |
| 25 | +- **Persistent, browsable Ask threads** per mission, clearable, **never merged |
| 26 | + into mission history** (the working agent cannot see the Ask conversation). |
| 27 | +- A **dedicated, configurable Ask model** (separate from the metadata model), |
| 28 | + optimized for *smart + fast + large context*. |
| 29 | +- One **quiet "operator-note"** bridge: when Ask **writes** to the workspace, the |
| 30 | + working agent gets a passive heads-up on its next turn. |
| 31 | +- Works across web, iOS, and Android (shared API). |
| 32 | + |
| 33 | +### Non-goals (v1) |
| 34 | +- No worktree / sandbox-copy mode (usage is read-dominant). |
| 35 | +- No destructive-write confirmation gate. Full bash, no friction; a visual |
| 36 | + "agent idle/working" indicator is informational only. |
| 37 | +- ~~Ask never **starts** a main-agent turn. Strictly non-interrupting.~~ |
| 38 | + **Superseded (v1.1):** the Copilot now has explicit steering tools — |
| 39 | + `stop_agent` (CancelMission, same as the Stop button) and `send_to_agent` |
| 40 | + (a real composer-equivalent UserMessage, optionally interrupting the |
| 41 | + current turn first). The system prompt frames these as interventions to |
| 42 | + use when the operator asks to stop/steer, or in clearly harmful loops; |
| 43 | + the default posture stays read-mostly. |
| 44 | +- Not every harness *heeds* the operator-note identically — delivery is |
| 45 | + harness-agnostic, faithfulness is best-effort (§9). |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## 2. Concept & lanes |
| 50 | + |
| 51 | +Two lanes share one workspace and one mission identity, otherwise isolated: |
| 52 | + |
| 53 | +- **Driver lane** — the working agent: `mission_events`, history, harness lock, |
| 54 | + message queue. |
| 55 | +- **Co-pilot lane** — the Ask assistant: `ask_threads` / `ask_messages` (separate |
| 56 | + `ask.db`), no lock, no queue, its own response path. |
| 57 | + |
| 58 | +Hard rule: **nothing ever reads `ask_*` rows into the working agent's prompt.** |
| 59 | +The only cross-lane bridges are the operator-note (Ask write → working agent, |
| 60 | +passive) and "Send to agent" (manual: Ask answer → real composer). |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## 3. Data model (implemented) |
| 65 | + |
| 66 | +Separate `ask.db` (rusqlite), keyed by `mission_id` (ownership enforced at the |
| 67 | +HTTP layer via the user's per-user mission store). |
| 68 | + |
| 69 | +- `ask_threads(id, mission_id, title, model, created_at, updated_at)` |
| 70 | +- `ask_messages(id, thread_id, seq, role, content, tool_name, tool_call_id, |
| 71 | + metadata, created_at)` — `role ∈ {user, assistant, tool_call, tool_result}`, |
| 72 | + FK → `ask_threads ON DELETE CASCADE` |
| 73 | +- `operator_notes(id, mission_id, body, source_thread_id, created_at, |
| 74 | + flushed_at)` — the M2 bridge buffer |
| 75 | + |
| 76 | +Store: `src/api/ask/store.rs` (`AskStore`). Global singleton via tokio |
| 77 | +`OnceCell` at `<working_dir>/.sandboxed-sh/missions/ask.db`. |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## 4. Backend: the Ask agentic loop (implemented) |
| 82 | + |
| 83 | +`src/api/ask/` — net-new, small, in-process: |
| 84 | +- `store.rs` — persistence (above). |
| 85 | +- `client.rs` — OpenAI-compatible chat client **with tool-calling** (reuses |
| 86 | + `MetadataLlmConfig`; forwards `reasoning_effort` so reasoning models return |
| 87 | + visible content). |
| 88 | +- `mod.rs` — `run_ask_turn`: persist user msg → seed system prompt (recent |
| 89 | + events + summary) → tool loop (≤6 iterations) → persist assistant answer. |
| 90 | +- `http.rs` — handlers. |
| 91 | + |
| 92 | +Tools (read-on-demand so the 128K context ceiling never bites): |
| 93 | +- `bash(command)` → `WorkspaceExec::output(work_dir, "/bin/bash", ["-lc", cmd])` |
| 94 | + — **full** read+write, live workspace, host or nspawn. No gate. |
| 95 | +- `read_history(limit)` → `MissionStore::get_latest_events`. |
| 96 | +- `read_file(path)` → bash `cat`. |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## 5. Model configuration (implemented) |
| 101 | + |
| 102 | +`metadata_llm.rs`: |
| 103 | +- Lifted `resolve_provider_api_key` to module scope. |
| 104 | +- Added `build_assistant_llm_config()` → prefers Cerebras `gpt-oss-120b` |
| 105 | + (`reasoning_effort=low`), overridable via `ASK_ASSISTANT_MODEL` env; falls back |
| 106 | + to the metadata provider ladder. |
| 107 | + |
| 108 | +Cerebras caps context at ~128K regardless of model — seed recent window + |
| 109 | +summary, let the model pull more via grep/`read_history`. (M3 adds a Settings |
| 110 | +picker with a `supports_tools` capability flag.) |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## 6. HTTP API (implemented) |
| 115 | + |
| 116 | +Routes (protected) in `routes.rs`, handlers in `src/api/ask/http.rs`: |
| 117 | + |
| 118 | +``` |
| 119 | +POST /api/control/missions/:id/ask send (returns final answer + messages) |
| 120 | +GET /api/control/missions/:id/ask/threads list threads |
| 121 | +GET /api/control/missions/:id/ask/threads/:tid thread + messages |
| 122 | +DELETE /api/control/missions/:id/ask/threads/:tid clear/delete thread |
| 123 | +``` |
| 124 | + |
| 125 | +These never call `queue_message` or acquire the harness lock. |
| 126 | + |
| 127 | +> M1 returns the final answer synchronously (JSON). Token-level **SSE streaming** |
| 128 | +> (`AgentEvent::Ask*` variants on a separate lane) is folded into M3 when the web |
| 129 | +> panel needs it. |
| 130 | +
|
| 131 | +--- |
| 132 | + |
| 133 | +## 7. Context strategy (the 128K ceiling) |
| 134 | + |
| 135 | +Seed: recent mission events + summary + the thread's prior messages. Then the |
| 136 | +model pulls more via `read_history` / `bash grep`. Keeps every request under |
| 137 | +128K and scales to arbitrarily long missions. |
| 138 | + |
| 139 | +--- |
| 140 | + |
| 141 | +## 8. The quiet operator-note (M2) |
| 142 | + |
| 143 | +Delivery is harness-agnostic; faithfulness is best-effort. |
| 144 | + |
| 145 | +- **Detect** an Ask write by wrapping `bash`: `git status --porcelain` snapshot |
| 146 | + before/after (non-git fallback deferred to M5). On change → |
| 147 | + `enqueue_operator_note`. |
| 148 | +- **Deliver** by prepending a `<operator-note>` block into the working agent's |
| 149 | + **next** `user_message` (all backends take the next turn as a single string: |
| 150 | + Claude Code `--` arg, OpenCode prompt file, Codex `send_message_streaming`). |
| 151 | + Centralized helper `prepend_pending_operator_notes(mission_id, user_message)`. |
| 152 | +- **Invariant:** notes are passive — flushed only when a turn is already about to |
| 153 | + run. Ask can never wake the working agent. |
| 154 | +- **Audit:** a flushed note records an `operator_note` mission event (the *fact* |
| 155 | + of a write touches the mission; the *chat* does not). |
| 156 | + |
| 157 | +Compatibility: all backends *see* the note; Claude Code *heeds* `<…>`-tagged |
| 158 | +blocks best. |
| 159 | + |
| 160 | +--- |
| 161 | + |
| 162 | +## 9. Frontend — web (M3) |
| 163 | + |
| 164 | +Right-side collapsible **Ask panel**: thread switcher, co-pilot styling (distinct |
| 165 | +from the indigo Bot), tool-call rendering, slim composer, informational |
| 166 | +"agent idle/working" banner, per-item "ask about this" spark, "Send to agent" |
| 167 | +bridge. `Ask` button beside Queue/Stop + a keyboard toggle (not a Cmd+W variant). |
| 168 | + |
| 169 | +## 10. Frontend — iOS / Android (M4) |
| 170 | + |
| 171 | +Same endpoints. iOS: `.sheet` with medium/large detents. Android: bottom sheet. |
| 172 | + |
| 173 | +--- |
| 174 | + |
| 175 | +## 11. Milestones |
| 176 | + |
| 177 | +- **M1 — Backend core** ✅ tables + store (unit-tested), Ask loop + tools, |
| 178 | + `build_assistant_llm_config`, routes. Synchronous JSON responses. |
| 179 | +- **M2 — Operator-note bridge** — git-porcelain detection + |
| 180 | + `prepend_pending_operator_notes` in all backend turn-prep + audit event. |
| 181 | +- **M3 — Web panel** — Ask store + (optional SSE), drawer, picker, spark, bridge. |
| 182 | +- **M4 — Mobile** — iOS sheet + Android bottom sheet. |
| 183 | +- **M5 — Polish** — per-thread cost, auto-titling, non-git write detection, |
| 184 | + sandbox-copy mode. |
| 185 | + |
| 186 | +--- |
| 187 | + |
| 188 | +## 12. Verification |
| 189 | + |
| 190 | +- M1 storage: `cargo test --lib ask::store` (thread/message roundtrip, cascade |
| 191 | + delete, operator-note take-once) — passing. |
| 192 | +- M1 end-to-end: deploy to **dev**, then |
| 193 | + `curl -X POST /api/control/missions/<id>/ask -d '{"content":"what is the agent doing?"}'` |
| 194 | + with a Cerebras key configured. (Pending live run.) |
0 commit comments