Understanding System Prompts in ChocolateLMLite: Implementation and Usage
System prompts in ChocolateLMLite are composite, persona-aware instruction sets that combine static text files, global application settings, and dynamically generated context—including memory entries, project files, and conversation summaries—to define the AI's behavior and personality for each chat session.
System prompts serve as the foundational instructions that guide language model behavior in the gpsnmeajp/chocolatelmlite repository. These prompts are not static strings but dynamic constructs assembled at runtime from multiple sources. Understanding how ChocolateLMLite builds and applies these system prompts is essential for customizing AI personas and controlling model outputs.
What Are System Prompts in ChocolateLMLite?
System prompts in this framework are structured instructions stored as text files within persona directories. Each persona maintains its own system_prompt.txt file that defines baseline behavior. However, the actual prompt sent to the LLM is a composite assembly created by merging this base file with global settings and real-time conversation data.
The architecture allows developers to layer context dynamically. When EnableMemory is active, the system injects <memory> tags containing relevant past interactions. Similarly, EnableProject triggers the inclusion of <project_files> tags listing available project resources. Recent conversation history may also be compressed into a <summary> tag when summaries exist.
How ChocolateLMLite Constructs System Prompts
The construction process follows a specific pipeline implemented in SystemPrompt.BuildSystemPrompt() within src/SystemPrompt.cs【SystemPrompt.cs†L13-L55】.
-
Load the persona-specific base file via
FileManager.GetSystemPromptFromActivePersona()【FileManager.cs†L2-L5】. -
Append global instructions from
GeneralSettings.GlobalSystemPrompt, applying application-wide defaults to every conversation. -
Conditionally inject dynamic sections:
- Memory entries wrapped in
<memory>XML tags when memory features are enabled - Project file listings within
<project_files>tags for context-aware coding assistance - Conversation summaries inside
<summary>tags to maintain long-term context without exceeding token limits
- Memory entries wrapped in
Loading the Persona-Specific File
The FileManager class handles filesystem operations for persona management. The base prompt retrieval occurs through a dedicated method that reads the active persona's directory structure.
// fileManager is an instance of FileManager
string rawPrompt = fileManager.GetSystemPromptFromActivePersona();
Console.WriteLine(rawPrompt);
Source: FileManager.GetSystemPromptFromActivePersona()【FileManager.cs†L2-L5】
Appending Global Settings
After loading the base file, the builder concatenates the GeneralSettings.GlobalSystemPrompt value. This ensures administrators can enforce universal behavioral constraints—such as safety guidelines or response formatting rules—across all personas without duplicating text in every file.
Injecting Dynamic Context
The system evaluates three boolean flags during construction. When enabled, the builder queries conversation history, memory databases, and project indices to generate XML-tagged content segments. These segments provide the LLM with grounded, session-specific information that improves response relevance.
Implementing System Prompts in Code
Once constructed, the prompt must be formatted as a system role message for the LLM client.
Building the Complete Prompt
The SystemPrompt class centralizes prompt construction logic, returning a fully assembled string ready for transmission.
// Build the full prompt including global settings, memory, project info, etc.
string fullPrompt = SystemPrompt.BuildSystemPrompt(fileManager);
Console.WriteLine(fullPrompt);
Source: SystemPrompt.BuildSystemPrompt【SystemPrompt.cs†L13-L55】
Sending to the LLM Client
The assembled prompt becomes the first message in the chat history, assigned the ChatRole.System role. This placement ensures the model processes these instructions before any user inputs.
var chatMessages = new List<ChatMessage>
{
new ChatMessage
{
Role = ChatRole.System,
Contents = [new TextContent(fullPrompt)]
},
// …add user messages afterwards
};
var response = await chatClient.GetStreamingResponseAsync(
chatMessages,
new ChatOptions { Temperature = 0.7f, MaxOutputTokens = 1024 },
cancellationToken);
Source: LLM.talkEntryListToChatMessageList creates the system message with the built prompt【LLM.cs†L11-L21】
Editing via the Web Interface
ChocolateLMLite provides a web-based UI for prompt management. The System Settings page (static/system.htm) loads current configurations through /api/setting and /api/persona endpoints. JavaScript handlers in static/js/system.js transmit modifications via POST requests to persist changes back to the persona file.
// Example snippet from static/js/system.js
async function saveSystemPrompt(personaId, newPrompt) {
await fetchJson(`/api/persona/${personaId}/system_prompt`, {
method: "POST",
body: JSON.stringify({ prompt: newPrompt })
});
}
The backend receives these requests through FileManager.SaveSystemPromptToActivePersona【FileManager.cs†L22-L25】, writing the updated text to the persona's system_prompt.txt file.
Key Source Files
Understanding system prompts requires familiarity with these implementation files in the gpsnmeajp/chocolatelmlite repository:
-
src/SystemPrompt.cs— Contains theBuildSystemPromptmethod that orchestrates prompt assembly from multiple sources【SystemPrompt.cs†L13-L55】. -
src/FileManager.cs— ImplementsGetSystemPromptFromActivePersona(lines 2-5) andSaveSystemPromptToActivePersona(lines 22-25) for filesystem operations【FileManager.cs†L2-L5】【FileManager.cs†L22-L25】. -
src/LLM.cs— Integrates the built prompt into chat message lists and handles LLM client communication【LLM.cs†L11-L21】. -
static/system.htm— HTML interface for editing system prompts through the browser. -
static/js/system.js— Frontend logic for loading and saving prompt modifications via REST API calls. -
src/Persona.cs— Defines persona objects that reference associated system prompt files.
Summary
System prompts in ChocolateLMLite function as dynamic, multi-layered instruction sets rather than static configuration strings. Key implementation details include:
- Persona-specific base prompts stored as
system_prompt.txtfiles in individual persona directories - Global prompt appending via
GeneralSettings.GlobalSystemPromptfor application-wide behavior control - Runtime injection of
<memory>,<project_files>, and<summary>XML tags when respective features are enabled - Centralized construction logic in
SystemPrompt.BuildSystemPrompt()that assembles the final instruction string - Persistence layer managed by
FileManagermethods that read from and write to persona directories - Web interface integration allowing real-time prompt editing without restarting the application
Frequently Asked Questions
Where are system prompt files stored in ChocolateLMLite?
Each persona maintains its own directory containing a system_prompt.txt file. The FileManager.GetSystemPromptFromActivePersona() method retrieves the currently active persona's file path and reads its contents, returning the raw text that serves as the behavioral baseline【FileManager.cs†L2-L5】.
How do I modify the global system prompt applied to all personas?
Update the GeneralSettings.GlobalSystemPrompt property in your application configuration. This string automatically appends to every persona-specific prompt during the construction phase within SystemPrompt.BuildSystemPrompt(), ensuring universal instructions apply across all AI interactions【SystemPrompt.cs†L13-L55】.
Can I include conversation history in the system prompt?
Yes. When EnableMemory is activated, the system queries historical exchanges and injects them as <memory> XML tags into the constructed prompt. Similarly, recent conversation threads may be compressed into a <summary> tag to provide context without consuming excessive tokens【SystemPrompt.cs†L13-L55】.
What happens when I save a system prompt through the web UI?
The JavaScript frontend in static/js/system.js sends a POST request to /api/persona/{id}/system_prompt. The backend routes this to FileManager.SaveSystemPromptToActivePersona(), which writes the new text directly to the persona's system_prompt.txt file (lines 22-25 in FileManager.cs), making changes persistent and immediately effective for subsequent chat sessions【FileManager.cs†L22-L25】.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →