Sfoglia il codice sorgente

docs: record queue runtime todo

zhenyu.hu 3 settimane fa
parent
commit
0752d5adfd
2 ha cambiato i file con 111 aggiunte e 3 eliminazioni
  1. 105 0
      docs/plans/todo-9-explicit-runtime-queues.md
  2. 6 3
      docs/plans/todos.md

+ 105 - 0
docs/plans/todo-9-explicit-runtime-queues.md

@@ -0,0 +1,105 @@
+# Todo 9 Explicit Runtime Queues Plan
+
+**Status:** done
+
+## Result
+
+Implemented by subagent and committed as `b2bba51 Add explicit runtime queues`.
+
+Main-session verification:
+
+```bash
+uv run pytest tests/test_debug_runtime.py
+uv run pytest
+```
+
+Results:
+
+- runtime queue tests: `5 passed in 0.06s`
+- full suite: `19 passed, 1 warning in 0.25s`
+
+## Goal
+
+Refactor the runtime internals to use explicit input, output, and event queues while preserving the existing WebSocket stream contract.
+
+## Why
+
+The MVP works, but the original requirement describes three data-exchange channels:
+
+- input queue: WebSocket/user input and EventAgent replies feed ChatAgent;
+- output queue: ChatAgent stream output feeds WebSocket downlink;
+- event queue: ChatAgent events feed EventAgent.
+
+The current `DebugRuntime.run()` performs these steps directly. This todo introduces the queue structure now, without changing HTTP/WebSocket payloads.
+
+## Scope
+
+This todo covers:
+
+- Runtime-local `asyncio.Queue` objects for input, output, and events.
+- A small queue/session abstraction in the application layer.
+- Tests proving queue ownership and order.
+- Keeping `DebugRuntime.run()` as the public async generator consumed by FastAPI.
+
+This todo does not cover:
+
+- Redis/NATS/external queues.
+- Multiple concurrent browser sessions beyond one runtime instance per WebSocket request.
+- Tool registry changes.
+- UI changes.
+
+## Files
+
+- Create: `src/agent_lab/application/queues.py`
+- Modify: `src/agent_lab/application/runtime.py`
+- Modify/add tests, preferably `tests/test_debug_runtime.py`.
+- Do not modify: `docs/plans/todos.md`.
+
+## Design
+
+Add a `RuntimeQueues` dataclass:
+
+```python
+@dataclass
+class RuntimeQueues:
+    input: asyncio.Queue[ChatMessage]
+    output: asyncio.Queue[dict[str, Any]]
+    events: asyncio.Queue[ToolCallEvent]
+```
+
+`DebugRuntime.run()` should:
+
+1. Build initial conversation from system prompts and pre-messages.
+2. Put the current user message on `input`.
+3. Drain input into conversation before each ChatAgent call.
+4. Stream ChatAgent items into `output`.
+5. Put tool-call events on `events`.
+6. Let EventAgent consume `events` and put tool replies back on `input`.
+7. Yield only from `output` so the WebSocket contract stays unchanged.
+
+Keep the implementation single-process and deterministic. Use sentinel-free sequential draining for this MVP; do not introduce background tasks unless needed by the tests.
+
+## Steps
+
+1. Add failing tests for:
+   - runtime exposes or injects `RuntimeQueues`;
+   - tool-call events are put on the event queue before EventAgent replies return to the input queue;
+   - yielded output message order remains unchanged from current tests.
+2. Implement `RuntimeQueues`.
+3. Refactor `DebugRuntime.run()` to use the queues internally.
+4. Run:
+
+```bash
+uv run pytest tests/test_debug_runtime.py
+uv run pytest
+```
+
+5. Evaluate whether Todo 10 still starts with tool registry management or should be adjusted based on the queue abstraction.
+
+## Verification
+
+Expected result:
+
+- Existing WebSocket/runtime behavior remains compatible.
+- Tests prove all three queues are part of the runtime flow.
+- Full suite passes.

+ 6 - 3
docs/plans/todos.md

@@ -11,9 +11,8 @@
 ## Current State
 
 - Branch: `codex/agent-lab-mvp`.
-- Repo started with only `README.md`, `LICENSE`, and `.gitignore`.
-- Existing uncommitted setup from earlier false start: `pyproject.toml`, `uv.lock`, and tests under `tests/`.
-- Temporary browser companion files exist under `.superpowers/` and should not become product code.
+- MVP committed at `6babafa` with FastAPI, WebSocket, static UI, OpenAI-compatible streaming, EventAgent handoff, provider-compatibility guards, and tests.
+- Post-MVP work now evolves toward the original queue/event-driven debugging-console requirements.
 
 ## Todos
 
@@ -27,3 +26,7 @@
 | 6 | done | `docs/plans/todo-6-cleanup-closeout.md` | Clean temporary/generated files, update contributor docs, and run final verification. | Git status contains only intended source/docs files; `uv run pytest` passes. |
 | 7 | done | `docs/plans/todo-7-provider-compatibility.md` | Fix review findings for real Chat Completions compatible providers: default model fallback, role-aware message serialization, and configurable usage streaming. | Tests prove provider payload shape and full suite passes. |
 | 8 | done | `docs/plans/todo-8-tool-pre-message-guard.md` | Prevent manually configured pre-messages from producing invalid provider `tool` payloads without `tool_call_id`. | Tests prove invalid tool pre-messages are rejected and UI no longer exposes `tool` role. |
+| 9 | done | `docs/plans/todo-9-explicit-runtime-queues.md` | Refactor runtime internals to explicit input, output, and event queues while preserving the WebSocket stream contract. | Tests prove ChatAgent consumes input queue, EventAgent consumes event queue, and output queue drives streamed responses. |
+| 10 | pending | `docs/plans/todo-10-tool-registry-management.md` | Replace the single hardcoded EventAgent tool checkbox with a backend tool registry and UI-managed loaded tools. | Tests prove available tools are listed by API and selected tools control EventAgent behavior. |
+| 11 | pending | `docs/plans/todo-11-prompt-workspace.md` | Improve prompt/pre-message editing with browser-side persistence and reusable prompt sets. | UI tests or focused JS tests prove prompts persist and can be restored. |
+| 12 | pending | `docs/plans/todo-12-round-stats.md` | Move round statistics to structured backend events for token counts, cached tokens, TTFT, elapsed time, and per-turn summaries. | Tests prove backend emits deterministic stats events and UI renders them. |