Make the prompts in research tool managed by AI delegate and editable

Dimitrije Jankovic
2026-03-22T13:46:52Z

## Summary Research tool prompts should be managed by AI delegate and editable. Add an Edit Prompts button in the top right, to the right of the Session History button. This should open the dialog to edit those prompts, just like in other pages. ## Is this a new feature? - [x] Yes, this is a new feature - [ ] No, this is a change to existing functionality ## Description of new functionality Instead of being hardcoded, prompts should be managed by AI delegate. Edit Prompts button opens the prompt list dialog that allows the user to edit the prompt for each purpose. ## Description of existing functionality Open Research Tool page. Interact with the tool. The system sends prompts to AI Delegate for aligning on the topic, summarizing a document, generating the research report, performing the web search etc. ## Recommended approach or architecture Follow the same pattern as in other pages in the app where we use AI Delegate and prompt editing. ## Implementation Plan ### Current State The research prompts are already well-structured — the worker tasks (`research-chat.ts`, `research-discovery.ts`, etc.) already use `ctx.appendPrompt('research-*', params)` to retrieve and render prompts at runtime. The 5 prompt definitions live in `ratings-worker/src/lib/prompts.ts`. So the runtime plumbing is already correct. What's **missing** is the UI-side registration and editor access. ### Changes Needed #### 1. Move/duplicate prompt registrations to the UI service **File:** `ratings-ui-demo/src/services/prompts.ts` Add the 5 research prompt `PromptRegistration` objects (currently only in `ratings-worker/src/lib/prompts.ts`) to the `promptRegistrations` array in the UI service, tagged with e.g. `['research']`: - `research-conversation` (light) — planning assistant system prompt - `research-discover` (light) — search query generation - `research-score` (light) — resource relevance scoring - `research-summarize` (moderate) — document summarization - `research-synthesize` (moderate) — report synthesis with propositions These are already parameterized with `{question}`, `{context}`, `{resources}`, etc. — no template changes needed. #### 2. Remove hardcoded model overrides from the Research Tool component **File:** `ratings-ui-demo/src/pvcomponents/pv-research-tool.tsx` (~lines 111-127) The `PROMPT_DEFAULTS` map hardcodes model IDs. These should be removed — model selection would come from the prompt's `weight` field (editable in the prompt editor), matching how Legislature works. Note: `research-web-search` is listed in `PROMPT_DEFAULTS` but has **no corresponding prompt definition** anywhere — that needs to either be defined or removed. #### 3. Add "Edit Prompts" button to the Research Tool UI **File:** `ratings-ui-demo/src/pvcomponents/pv-research-tool.tsx` Add a button similar to Legislature's (`pv-legislature.tsx:146`): ```typescript openPromptEditor(['research'])}>Edit Prompts ``` #### 4. Ensure prompts are registered on init **File:** `ratings-ui-demo/src/services/ai-service.ts` No changes needed here — `ensureAiDelegateInitialized()` already calls `AiDelegate.registerPrompts(promptRegistrations)` on the full array from `prompts.ts`. Adding prompts to that array is sufficient. #### 5. Deduplicate worker-side registrations **File:** `ratings-worker/src/lib/prompts.ts` The worker also registers these prompts. Decision needed: - **Keep both** (worker and UI register the same prompts — PromptManager handles this gracefully if versions match) - **Remove from worker** (if the worker can rely on prompts already being in the store from UI registration) Keeping both is safer since the worker can run independently. ### Summary | Step | File | Effort | |------|------|--------| | Add 5 prompt registrations | `services/prompts.ts` | Copy/adapt from worker's `prompts.ts` | | Remove `PROMPT_DEFAULTS` hardcoding | `pv-research-tool.tsx` | Delete ~15 lines | | Add "Edit Prompts" button | `pv-research-tool.tsx` | ~3 lines | | Handle `research-web-search` gap | Both files | Define prompt or remove reference | The heaviest part is step 1 — copying/adapting the 5 prompt templates (~280 lines) into the UI service with appropriate tags. The rest is straightforward wiring.