Jelajahi Sumber

docs: plan tool mode UI and session restore

Problem: invocation mode is backend-only, snapshots/session loads do not restore it, and persisted messages omit assistant tool calls/tool replies required for direct-mode reconnect transcripts.

Risk: SQLite migration and history restoration must preserve old sessions and avoid duplicating current-turn messages or contaminating dual-mode history.
zhenyu.hu 2 minggu lalu
induk
melakukan
ccddb33f7c
2 mengubah file dengan 70 tambahan dan 1 penghapusan
  1. 69 0
      docs/plans/todo-49-tool-mode-ui-session-restore.md
  2. 1 1
      docs/plans/todos.md

+ 69 - 0
docs/plans/todo-49-tool-mode-ui-session-restore.md

@@ -0,0 +1,69 @@
+# Todo 49 Tool Mode UI and Session Restore Plan
+
+**Status:** in_progress
+
+## Goal
+
+Make invocation mode and batch configuration visible/configurable in the debug UI, and restore a persisted direct-mode conversation with a provider-valid assistant/tool transcript.
+
+## UI
+
+- Add a mode selector with:
+  - `Dual Agent — fast reply + EventAgent` (default);
+  - `ChatAgent Tools — native provider tools`.
+- Add concise mode help/applicability text:
+  - dual mode: EventAgent model/system/extra-body may be used for missing argument fallback;
+  - direct mode: ChatAgent proposes provider-resolved arguments, so EventAgent model prompt settings are inactive; enabled tools, loop budget, batch concurrency, and timeout still apply.
+- Add `max_parallel_events` and `batch_timeout_seconds` controls.
+- Include mode and new settings in WebSocket requests and workspace snapshots.
+- Restore them from workspace snapshots and persisted session config, with backward-compatible defaults.
+- When loading a session, fetch `/api/sessions/{id}` together with replay/audit/usage and apply its saved config to the UI.
+- New manually created sessions save the current workspace config.
+
+## Persisted Transcript
+
+- Persist assistant `tool_calls` as JSON alongside role/content/name/tool-call ID.
+- Add a safe SQLite migration for existing databases.
+- Return `tool_calls` from the messages API and reconstruct `ChatMessage` values for Runtime session restoration.
+- On reusable session start with an existing `session_id`, load prior user/assistant/tool messages into active history after current system/pre-message context.
+- Persist direct-mode tool replies as messages; dual mode continues to persist only user-visible conversational history and summaries, not provider tool protocol messages.
+- Validate restored transcript ordering/IDs before the next provider call through existing client validation.
+
+## Boundaries
+
+- Do not change result-policy behavior or batch scheduling.
+- Do not migrate historical rows into synthetic tool calls; old rows default to `[]`.
+- Do not expose internal tool messages as normal assistant chat bubbles beyond the existing tool replay style.
+- Comparison metrics remain Todo 50.
+
+## Files
+
+- Modify: `src/agent_lab/infrastructure/sqlite_store.py`
+- Modify: `src/agent_lab/application/runtime.py`
+- Modify: `src/agent_lab/presentation/static/index.html`
+- Modify: `src/agent_lab/presentation/static/app.js`
+- Modify: `src/agent_lab/presentation/static/styles.css` only if mode help layout needs it
+- Modify: `tests/test_sqlite_store.py`
+- Modify: `tests/test_debug_runtime.py`
+- Modify: `tests/test_websocket_api.py`
+
+## Requirement Execution Loop
+
+### Plan
+
+1. Add RED persistence/migration tests for assistant tool calls and tool replies.
+2. Add RED Runtime reconnect tests proving the next direct provider request receives restored valid transcript.
+3. Add RED static/request/snapshot/session-load tests for mode and batch config.
+4. Implement the smallest schema migration, restore helper, and UI controls.
+5. Run Python, JS syntax, full tests, and a local browser/static check if layout changes materially.
+
+### Observe / Update
+
+Add `49.x` rows for review findings. Mark complete only when old sessions remain loadable and direct-mode restored transcripts pass provider validation.
+
+## Verification
+
+- `UV_CACHE_DIR=.uv-cache uv run pytest tests/test_sqlite_store.py tests/test_debug_runtime.py tests/test_websocket_api.py -q`
+- `node --check src/agent_lab/presentation/static/app.js`
+- `UV_CACHE_DIR=.uv-cache uv run pytest`
+- `git diff --check`

+ 1 - 1
docs/plans/todos.md

@@ -92,6 +92,6 @@
 | 48.1 | done | `docs/plans/todo-48.1-batch-canonical-replay-and-terminal-safety.md` | Canonicalize batch keys, make replay atomic and bounded, guarantee terminal grace after sibling timeout, enforce async timeout around sync handlers, and ensure termination has a farewell. | Canonical/in-flight replay, terminal grace, sync timeout responsiveness, farewell, and search two-answer regressions pass. |
 | 48.2 | done | `docs/plans/todo-48.2-outcome-cache-and-sync-resource-lifecycle.md` | Preserve full replay outcomes, generation-scope cleanup, invalid-key isolation, sync worker resource leases, and deduplicated result correlation/policy cardinality. | Outcome cache, scope invalidation, deferred sync resource leases, correlation, and single policy messages pass. |
 | 48.3 | done | `docs/plans/todo-48.3-strict-canonical-types-and-scope-token-cleanup.md` | Align canonical-key equality with strict JSON types and replace retained generation tombstones with unique releasable scope tokens. | Strict nested JSON types and 1000-cycle scope cleanup pass; final bounded gate APPROVED. |
-| 49 | pending | `docs/plans/todo-49-tool-mode-ui-session-restore.md` | Add UI mode selection, workspace/session restoration, and clear EventAgent applicability feedback. | Static/WebSocket tests prove requests, snapshots, loaded sessions, and audit context preserve the selected mode. |
+| 49 | in_progress | `docs/plans/todo-49-tool-mode-ui-session-restore.md` | Add UI mode selection, workspace/session restoration, and clear EventAgent applicability feedback. | Static/WebSocket tests prove requests, snapshots, loaded sessions, and audit context preserve the selected mode. |
 | 50 | pending | `docs/plans/todo-50-comparable-model-tool-metrics.md` | Record mode-aware model/tool spans and include EventAgent usage so both architectures can be compared fairly. | Persistence/API tests report agent, call kind, tokens, TTFT, tool latency, fallback usage, and total turn wall time without double counting. |
 | 51 | pending | `docs/plans/todo-51-comparison-matrix-closeout.md` | Add repeatable comparison fixtures, update project documentation, and close the experimental implementation. | Both modes pass the same scenario matrix; full tests, JS syntax, app import, and documentation checks pass. |