Custom Default System Prompt #4487
Open
+479
β70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Type
Relevant Issues
resolves #3906
What is in this change?
This PR introduces a new Custom Default System Prompt feature that allows administrators to define a global default system prompt that will be automatically applied to all newly created workspaces. This provides a centralized way to standardize AI behavior across your AnythingLLM instance without needing to configure each workspace individually.
How It Works
Backend Implementation
default_system_promptsetting is stored in thesystem_settingstableWorkspace.new()), the system checks for a custom default system promptopenAiPromptfieldAPI Endpoints
Two new endpoints have been added to
/system:GET
/system/default-system-promptdefaultSystemPrompt: The custom prompt (or sane default if not set)saneDefaultSystemPrompt: The built-in default for referencePOST
/system/default-system-promptdefaultSystemPromptin request bodyMulti-User Mode Permissions
Who Can See This Feature?
In multi-user mode, access is role-based:
The settings page in the UI is only visible to admins through the navigation menu at:
Settings β Admin β Default System Prompt
Single-User Mode
In single-user mode, the feature is available without restrictions since there is no authentication.
How to Set Your Own Custom Default System Prompt
Step 1: Navigate to the Settings Page
Step 2: Configure Your Custom Prompt
{date},{time},{user.name})Step 3: Supported Variables
You can enhance your system prompt with dynamic variables:
{time},{date},{datetime}{user.id},{user.name},{user.bio}Click on the system prompt variables link on the settings page to see all available variables.
Example Custom Prompt
How to Restore to the Sane Default
Important Notes
Scope of Changes
Workspace-Specific Customization
Even after setting a global default, individual workspaces can be customized:
Use Cases
This feature is particularly useful for:
Technical Details
Database Schema
The custom prompt is stored in the
system_settingstable:default_system_promptCode Changes
Backend:
server/endpoints/system.js: New GET/POST endpointsserver/models/systemSettings.js: AddedsaneDefaultSystemPromptconstant anddefault_system_prompttosupportedFieldsserver/models/workspace.js: Modifiednew()method to check for custom default promptFrontend:
frontend/src/pages/Admin/DefaultSystemPrompt/index.jsx: New settings pagefrontend/src/models/system.js: New API methodsfetchDefaultSystemPrompt()andupdateDefaultSystemPrompt()frontend/src/components/SettingsSidebar/index.jsx: Added menu item for adminsfrontend/src/pages/WorkspaceSettings/ChatSettings/ChatPromptSettings/index.jsx: Added "Restore to Default" functionalityAdditional Information
Developer Validations
yarn lintfrom the root of the repo & committed changes