mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-21 08:15:23 -04:00
[PR #301] [MERGED] fix: apply custom prompts to new sessions #306
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/vxcontrol/pentagi/pull/301
Author: @mason5052
Created: 5/6/2026
Status: ✅ Merged
Merged: 5/21/2026
Merged by: @asdek
Base:
feature/next-release← Head:codex/issue-300-custom-prompts📝 Commits (3)
08c050cfix: apply custom prompts to new sessions3278c62fix(controller): avoid JSON round-trip and N+1 prompter loads19b63c5Merge branch 'feature/next-release' into codex/issue-300-custom-prompts📊 Changes
5 files changed (+306 additions, -12 deletions)
View changed files
📝
backend/pkg/controller/assistant.go(+17 -2)📝
backend/pkg/controller/flow.go(+9 -3)➕
backend/pkg/controller/prompter.go(+50 -0)➕
backend/pkg/controller/prompter_test.go(+209 -0)📝
backend/pkg/templates/templates.go(+21 -7)📄 Description
Summary
Custom system prompts saved via the Settings -> Prompts UI are now applied to newly created assistant and flow sessions. Prior to this change, every session creation path used
templates.NewDefaultPrompter()(with a leftover TODO comment), so user customizations never reached the agents and Langfuse traces always showed the default templates.Problem
backend/pkg/controller/assistant.go(NewAssistantWorker,LoadAssistantWorker) andbackend/pkg/controller/flow.go(NewFlowWorker,LoadFlowWorker) all built the prompter fromtemplates.NewDefaultPrompter()and ignored the per-userpromptstable that the Prompts UI persists. The Custom badge in the UI was therefore decorative -- saved overrides had no effect on subsequent sessions.Solution
Introduce a small controller-side helper,
newUserPrompter, which:database.Querier.GetUserPrompts.templates.LoadDefaultPromptsMap()(a new helper that returns the embedded defaults as aPromptsMapdirectly, avoiding a JSON round-trip) and overlays each non-empty user override onto the resulting map.templates.NewFlowPrompter(merged)so prompt types the user never customized continue to resolve to the defaults.A database error fails session creation explicitly (
wrapErrorEndSpanon the existing langfuse span) instead of silently falling back to defaults. Empty bodies are skipped because the UI uses delete (or reset, which writes the default body back) to remove a customization, so an empty row is unexpected and would otherwise surface asErrTemplateNotFounddeep inside agent rendering.The helper lives in
pkg/controllerrather thanpkg/templatesto avoid creating a newtemplates -> databaseimport edge.To avoid an N+1 pattern on flow load,
assistantWorkerCtxcarries an optionalprompterfield.LoadFlowWorkerbuilds the user prompter once for the flow and reuses it across every assistant in that flow;LoadAssistantWorkerfalls back to building its own prompter when invoked outside a flow load.Lifecycle Semantics
NewFlowWorker,LoadFlowWorker,NewAssistantWorker, standaloneLoadAssistantWorker).User Impact
PromptTypethe user has overridden.Test Plan
go test ./pkg/controller/... ./pkg/templates/...(passes locally on Go 1.24)backend/pkg/controller/prompter_test.gocover:GetUserPrompts-> wrapped error propagated, nil prompter returnednewUserPrompterend-to-end with a fakedatabase.QuerierFollow-ups
backend/cmd/ftester/worker/tester.gocarries the same TODO and was intentionally left alone here -- it is a developer harness rather than a session creation path. Happy to fold it in if reviewers prefer one place.Closes #300
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.