Skip to content

Conversation

@angelplusultra
Copy link
Contributor

@angelplusultra angelplusultra commented Oct 3, 2025

Pull Request Type

  • ✨ feat
  • πŸ› fix
  • ♻️ refactor
  • πŸ’„ style
  • πŸ”¨ chore
  • πŸ“ docs

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

  • A new default_system_prompt setting is stored in the system_settings table
  • When a new workspace is created (Workspace.new()), the system checks for a custom default system prompt
  • If a custom prompt is configured, it's applied to the new workspace's openAiPrompt field
  • If no custom prompt is set, the workspace uses the "sane default" system prompt:
    Given the following conversation, relevant context, and a follow up question, reply with an answer to the current question the user is asking. Return only your response to the question given the above information following the users instructions as needed.
    

API Endpoints

Two new endpoints have been added to /system:

  1. GET /system/default-system-prompt

    • Returns the current default system prompt and the sane default
    • Available to all authenticated users in multi-user mode
    • Response includes:
      • defaultSystemPrompt: The custom prompt (or sane default if not set)
      • saneDefaultSystemPrompt: The built-in default for reference
  2. POST /system/default-system-prompt

    • Updates the default system prompt
    • Admin-only in multi-user mode
    • Accepts defaultSystemPrompt in request body
    • Returns success/failure message

Multi-User Mode Permissions

Who Can See This Feature?

In multi-user mode, access is role-based:

  • Admins: Full access - can view and modify the default system prompt
  • Managers: Read-only - can fetch the default prompt but cannot modify it
  • Default Users: Read-only - can fetch the default prompt but cannot modify it

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

  1. Log in as an admin user
  2. Click on the Settings button (gear icon)
  3. In the sidebar, expand the Admin section
  4. Click on Default System Prompt

Step 2: Configure Your Custom Prompt

  1. Click into the System Prompt text area to begin editing
  2. Enter your desired default system prompt
  3. The prompt will be highlighted with any system prompt variables you use (e.g., {date}, {time}, {user.name})
  4. Click Save Changes when finished

Step 3: Supported Variables

You can enhance your system prompt with dynamic variables:

  • System variables: {time}, {date}, {datetime}
  • User variables (multi-user mode only): {user.id}, {user.name}, {user.bio}
  • Custom variables: Create your own at Settings β†’ Tools β†’ System Prompt Variables

Click on the system prompt variables link on the settings page to see all available variables.

Example Custom Prompt

You are a helpful AI assistant for our company. Today's date is {date} and the time is {time}.
You are chatting with {user.name}. Always be professional, concise, and accurate in your responses.
When providing code examples, use markdown formatting. If you're unsure about something, say so.

How to Restore to the Sane Default

  1. Navigate to Settings β†’ Admin β†’ Default System Prompt
  2. Clear the entire text field (delete all text)
  3. Click Save Changes
  4. The system will automatically use the sane default for all new workspaces
  5. The text area will display the sane default prompt for reference

Important Notes

Scope of Changes

  • βœ… Only affects NEW workspaces created after setting the custom prompt
  • ❌ Does NOT modify existing workspaces automatically
  • βœ… Each workspace can still override its prompt in Workspace Settings β†’ Chat Settings

Workspace-Specific Customization

Even after setting a global default, individual workspaces can be customized:

  1. Navigate to the specific workspace
  2. Click Settings (gear icon)
  3. Go to Chat Settings
  4. Click "Restore to Default" to use the global default, or customize further

Use Cases

This feature is particularly useful for:

  • Standardizing AI behavior across your organization
  • Enforcing company policies in AI responses (e.g., tone, formatting, disclaimers)
  • Reducing setup time when creating multiple workspaces
  • Maintaining consistency in multi-tenant or multi-team environments
  • Injecting dynamic context like current date/time or user information

Technical Details

Database Schema

The custom prompt is stored in the system_settings table:

  • Label: default_system_prompt
  • Value: The custom prompt text (or NULL if using sane default)

Code Changes

Backend:

  • server/endpoints/system.js: New GET/POST endpoints
  • server/models/systemSettings.js: Added saneDefaultSystemPrompt constant and default_system_prompt to supportedFields
  • server/models/workspace.js: Modified new() method to check for custom default prompt

Frontend:

  • frontend/src/pages/Admin/DefaultSystemPrompt/index.jsx: New settings page
  • frontend/src/models/system.js: New API methods fetchDefaultSystemPrompt() and updateDefaultSystemPrompt()
  • frontend/src/components/SettingsSidebar/index.jsx: Added menu item for admins
  • frontend/src/pages/WorkspaceSettings/ChatSettings/ChatPromptSettings/index.jsx: Added "Restore to Default" functionality

Additional Information

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated
  • I have tested my code functionality
  • Docker build succeeds locally

- Introduced a new route for fetching and updating the default system prompt in the backend.
- Added a new Admin page for managing the default system prompt, including a form for editing and saving changes.
- Updated the SettingsSidebar to include a link to the new Default System Prompt page.
- Implemented fetching of available system prompt variables for use in the prompt editor.
- Enhanced the ChatSettings and ChatPromptSettings components to support the new default system prompt functionality.

This commit lays the groundwork for improved management of system prompts across workspaces.
@angelplusultra angelplusultra linked an issue Oct 3, 2025 that may be closed by this pull request
@angelplusultra angelplusultra added the PR:needs review Needs review by core team label Oct 3, 2025
@angelplusultra angelplusultra marked this pull request as draft October 3, 2025 22:54
@angelplusultra angelplusultra removed the PR:needs review Needs review by core team label Oct 3, 2025
@angelplusultra angelplusultra removed the request for review from timothycarambat October 3, 2025 22:54
@angelplusultra angelplusultra marked this pull request as ready for review October 3, 2025 23:21
@angelplusultra angelplusultra added the PR:needs review Needs review by core team label Oct 3, 2025
@timothycarambat timothycarambat mentioned this pull request Oct 7, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR:needs review Needs review by core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Add a Global prompt

3 participants