Procházet zdrojové kódy

docs: record tool registry todo

zhenyu.hu před 3 týdny
rodič
revize
258705ce4c
2 změnil soubory, kde provedl 111 přidání a 1 odebrání
  1. 110 0
      docs/plans/todo-10-tool-registry-management.md
  2. 1 1
      docs/plans/todos.md

+ 110 - 0
docs/plans/todo-10-tool-registry-management.md

@@ -0,0 +1,110 @@
+# Todo 10 Tool Registry Management Plan
+
+**Status:** done
+
+## Result
+
+Implemented by subagent and committed as `43b0cc8 feat: add tool registry management`.
+
+Main-session verification:
+
+```bash
+uv run pytest tests/test_event_agent.py tests/test_debug_runtime.py tests/test_websocket_api.py
+uv run pytest
+```
+
+Results:
+
+- focused EventAgent/runtime/WebSocket tests: `20 passed, 1 warning in 0.26s`
+- full suite: `23 passed, 1 warning in 0.27s`
+
+## Goal
+
+Replace the single hardcoded EventAgent tool checkbox with a backend tool registry and UI-managed loaded tools.
+
+## Why
+
+The original requirement says the debug page must manage which tools are loaded in EventAgent. The MVP has only one hardcoded `handoff_note` checkbox and duplicated tool schema logic in runtime. This todo makes tools a backend-owned registry so UI and runtime share the same source of truth.
+
+## Scope
+
+This todo covers:
+
+- A backend registry for available EventAgent tools.
+- An API endpoint that lists available tools and their schema/description.
+- Runtime tool schema lookup through the registry.
+- EventAgent execution through registered handlers.
+- Static UI rendering tool checkboxes from the API.
+- Tests for listing tools, selected-tool behavior, and UI request payload.
+
+This todo does not cover:
+
+- User-authored Python tool plugins.
+- Persistent tool configuration.
+- Hot-reloading tools from files.
+- Adding tools beyond the existing `handoff_note`.
+
+## Files
+
+- Create: `src/agent_lab/application/tools.py`
+- Modify: `src/agent_lab/application/event_agent.py`
+- Modify: `src/agent_lab/application/runtime.py`
+- Modify: `src/agent_lab/presentation/web.py`
+- Modify: `src/agent_lab/presentation/static/index.html`
+- Modify: `src/agent_lab/presentation/static/app.js`
+- Modify/add tests in `tests/test_event_agent.py`, `tests/test_debug_runtime.py`, and `tests/test_websocket_api.py`.
+- Do not modify: `docs/plans/todos.md`.
+
+## Design
+
+Create a small registry in application layer:
+
+- `ToolDefinition`: name, description, parameters, handler.
+- `ToolRegistry.available_tools()`: returns serializable public tool metadata.
+- `ToolRegistry.chat_tools(enabled_names)`: returns OpenAI-compatible tool definitions for selected names.
+- `ToolRegistry.handle(event)`: executes a registered tool and returns payload dict.
+
+`handoff_note` remains the only registered MVP tool. Unknown or disabled tools should still produce tool replies with explicit JSON errors, preserving current runtime behavior.
+
+`DebugRuntime` should accept an optional registry, defaulting to the built-in registry. `EventAgent` should also receive that registry. The runtime should stop building tool schemas manually.
+
+`GET /api/tools` returns:
+
+```json
+[
+  {
+    "name": "handoff_note",
+    "description": "Send a note to the event agent.",
+    "parameters": { "type": "object", "properties": { "message": { "type": "string" } }, "required": ["message"] }
+  }
+]
+```
+
+The static UI should fetch `/api/tools` on load, render a checkbox per tool, and send selected names in `event_agent.enabled_tools`.
+
+## Steps
+
+1. Add failing tests for:
+   - `GET /api/tools` returns `handoff_note` metadata.
+   - Runtime passes selected tool schemas from registry into ChatAgent.
+   - EventAgent returns disabled/unknown errors through the registry path.
+   - Static HTML/JS no longer hardcodes a `tool-handoff-note` checkbox dependency.
+2. Implement `application/tools.py`.
+3. Refactor `EventAgent` and `DebugRuntime` to use `ToolRegistry`.
+4. Add `GET /api/tools`.
+5. Update static UI to render tool checkboxes dynamically and preserve default checked state.
+6. Run:
+
+```bash
+uv run pytest tests/test_event_agent.py tests/test_debug_runtime.py tests/test_websocket_api.py
+uv run pytest
+```
+
+## Verification
+
+Expected result:
+
+- Tool metadata comes from backend API.
+- Runtime and EventAgent use the same registry.
+- UI selected tool list still drives `event_agent.enabled_tools`.
+- Full suite passes.

+ 1 - 1
docs/plans/todos.md

@@ -27,6 +27,6 @@
 | 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. |
+| 10 | done | `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. |