[chat] Custom system prompts with save/switch (#923) #930

Closed
sleepy wants to merge 0 commits from feat/custom-system-prompts-923 into dev
Owner

Summary

Implements #923 — custom system prompts with save, switch, and manage templates.

Changes

Settings (src/settings.py)

  • system_prompt_mode: "default" | "append" | "replace" — controls how custom prompt is applied
  • custom_system_prompt: inline custom prompt text
  • saved_prompts: name→content dict of saved prompt templates
  • active_prompt: name of the currently active saved prompt

Prompt Assembly (src/agent/system_prompt.py)

  • New _apply_custom_prompt() function applies custom text after the built-in prompt is fully assembled
  • Active saved prompt takes precedence over inline custom_system_prompt
  • Graceful fallback: if custom text is empty, built-in prompt is returned unchanged

API Endpoints (routes/settings_routes.py)

  • GET /api/auth/prompts — list saved prompts, active prompt, and mode
  • POST /api/auth/prompts — save/update a prompt (body: {name, content})
  • DELETE /api/auth/prompts/{name} — delete a prompt (auto-deactivates if active)
  • POST /api/auth/prompts/activate — set active prompt (body: {name} or {name: ""} to deactivate)

Tests (tests/test_custom_prompts.py)

  • 32 tests covering CRUD, activate/deactivate, all 3 modes, prompt assembly, route auth

Test Results

  • 1152 passed (1120 baseline + 32 new), same 9 pre-existing failures
  • No regressions
## Summary Implements #923 — custom system prompts with save, switch, and manage templates. ### Changes **Settings (src/settings.py)** - `system_prompt_mode`: "default" | "append" | "replace" — controls how custom prompt is applied - `custom_system_prompt`: inline custom prompt text - `saved_prompts`: name→content dict of saved prompt templates - `active_prompt`: name of the currently active saved prompt **Prompt Assembly (src/agent/system_prompt.py)** - New `_apply_custom_prompt()` function applies custom text after the built-in prompt is fully assembled - Active saved prompt takes precedence over inline `custom_system_prompt` - Graceful fallback: if custom text is empty, built-in prompt is returned unchanged **API Endpoints (routes/settings_routes.py)** - `GET /api/auth/prompts` — list saved prompts, active prompt, and mode - `POST /api/auth/prompts` — save/update a prompt (body: {name, content}) - `DELETE /api/auth/prompts/{name}` — delete a prompt (auto-deactivates if active) - `POST /api/auth/prompts/activate` — set active prompt (body: {name} or {name: ""} to deactivate) **Tests (tests/test_custom_prompts.py)** - 32 tests covering CRUD, activate/deactivate, all 3 modes, prompt assembly, route auth ### Test Results - 1152 passed (1120 baseline + 32 new), same 9 pre-existing failures - No regressions
- Add 4 new settings keys: system_prompt_mode, custom_system_prompt,
  saved_prompts, active_prompt
- Add _apply_custom_prompt() to system_prompt.py that applies custom
  text in append/replace/default modes after the built-in prompt
- Add API endpoints: GET/POST/DELETE /api/auth/prompts,
  POST /api/auth/prompts/activate
- Saved prompts stored as name→content dict in settings.json
- Deleting active prompt auto-deactivates it
- 32 tests covering CRUD, mode switching, prompt assembly, routes
sleepy closed this pull request 2026-06-04 13:51:35 +02:00

Pull request closed

Sign in to join this conversation.
No description provided.