Assistants and models
An application can have more than one assistant: a general one on the main form, and an expert on the form of an important function - order entry, planning - that knows that function in depth, has its own name, its own instructions, its own part of the manual and its own actions. Each assistant, in turn, can offer the user more than one model to answer with: the cloud service of Anthropic, Google's Gemini, a model running on the user's own PC.
Three names, for three different things:
| Name | Where | What it is |
|---|---|---|
AssistantName | component, or the configuration | What the user reads in the header of the panel: "Giulio", "Alice". Empty = the localized "Assistant" |
Profile | component | The technical key that ties a component to its section of the configuration. Never shown, never translated: renaming "Giulio" must not break the tie |
Models | configuration | The models the user may switch between in the panel |
Several assistants
Drop a component on each form that deserves an assistant, and give each a Profile:
// uOrderForm.dfm
object HelpChat: TVclHelpChatAI
Active = True
Profile = 'Orders'
AssistantName = 'Giulio'
endEach one lives on the form that owns it: its bubble is there, and F1 goes to the assistant of the active form - on a form that has none (a dialog, a print preview) to the one whose form was active last, the expert of the window the user came from. Several can be active at once; TVclHelpChatAI.CurrentAssistant says which one F1 would reach now. See F1 and the screen context.
Each assistant keeps its own conversation, its own model and language choice and its own window position: the files are named after the profile (helpchatai-conversation-Orders.json, helpchatai-state-Orders.json, helpchatai-ui-Orders.json). The default assistant - no profile - keeps the names without a suffix.
One profile, one assistant, however many windows show it. Two order windows open at once are two components with the same profile, and they talk to the same expert: one engine, one conversation, the manual loaded once. What each window may do is its own - the actions are registered on the component of that form, and an action the model calls from the panel of one window fills that window. The engine goes away with the last component of its profile.
The configuration: a root and the profiles
One helpchatai.json serves every assistant. The root holds what they share; Profiles holds, under the name of each profile, what one assistant changes. A profile has the same keys as the root:
{
"Language": "auto",
"DocIndexFile": "Help\\help-index.json",
"DocFolder": "Help",
"Claude": { "ApiKey": "sk-ant-..." },
"OpenAI": { "BaseUrl": "http://localhost:11434/v1" },
"Models": [
{ "Name": "Claude", "Provider": "claude", "Model": "claude-haiku-5-5" },
{ "Name": "Gemma (local)", "Provider": "openai", "Model": "gemma4:12b" }
],
"Profiles": {
"Orders": {
"AssistantName": "Giulio",
"Expertise": "order management and shipping",
"Instructions": "Help the user enter orders, their lines, discounts and shipping.",
"Models": ["Claude"]
}
}
}The order, from the weakest to the strongest: the defaults of the library, the properties of the component, then for each configuration file its root and then its profile. A profile that no file mentions is not an error: the root and the component apply. It is what a misspelt Profile looks like, though, so the configuration check of the component editor reports it as a warning.
| Key | What it does for an assistant |
|---|---|
AssistantName | Its name in the panel; prevails over the property of the component, so a deployment can rename it |
Expertise | The field it knows beyond the manual: it opens the system prompt, with the rule that keeps the procedures to the manual (below) |
Instructions | What it does in detail: added to the system prompt after the built-in rules, whatever model answers |
SystemPrompt | The rules of the assistant, the library's by default: change them with care, they carry the rules about the excerpts and the citations. The other texts of the prompt are below |
DocAreas | The areas of the manual it knows - one manual, one index, an area per expert |
DocIndexFile | A whole index of its own, when its manual is really another one |
Models | The models it offers: a name is a model of the catalogue (the Models of the root), an object defines a new one |
AllowedActions | The actions it may use, among those its component registers and the shared ones |
| any other key | As at the root: Greeting, Language, Provider, a provider section... |
Expertise, Instructions and SystemPrompt belong to the assistant, not to a provider: switching from Claude to a local model must not turn the expert into somebody else.
The multi-assistant edition of the CRM demo puts all of this in one unit: two assistants on two windows, an area of the manual each, and an action only one of them may use.
What an assistant knows
A manual says how the application works; it rarely says what the work is. The manual of an accounting program shows where to post an invoice, not how VAT is computed; the one of a CRM shows the columns of the board, not when a lead should be considered lost. The built-in rules tell the model to answer only from the manual, so without more it says "the documentation does not cover this" - which is right, and of no help.
Expertise is the field the assistant is an expert of. It is the first thing the model reads after its name, and it comes with a rule the library adds by itself:
- the expertise is there to understand what the user means (month-end, open items) and to explain the concepts and the good practice of the field, said to be general practice;
- how to do something in this application still comes from the manual only: no screen, field, report or automatic feature it does not describe; when the application lacks what the user needs, the assistant says so and offers the closest thing it has;
- a question outside the field and the application is declined in a sentence.
"Profiles": {
"Accounting": { "Expertise": "general accounting and VAT" },
"Warehouse": { "Expertise": "warehouse management: stock, picking, inventory" }
}Keep the two apart: Expertise says what the assistant knows, Instructions says what it does - its tasks, its tone, what it must not do. Either may be used without the other. A field written into Instructions does not work the same: it comes after the rules, and the rules win.
That is measured, not guessed. Test\LLMBench has a suite of twelve questions the manual of the CRM demo does not answer and an expert would (VAT on a proposal, the value of a pipeline, a follow-up, a forecast, a reminder the application does not have), every answer graded by a judge model against the whole manual. A field declared without its rule changed nothing; with the rule the capable models answered three to five more of the twelve, and invented no more features than before. The smaller models (gemini-3.5-flash-lite, gpt-6-luna) did not benefit.
The CRM demo shows both cases. The plain edition has one assistant that does all the manual describes: it has an Expertise and no Instructions, because the built-in rules already say everything it must do. The multi-assistant edition divides the work, and that is what Instructions are for: the general assistant is told to send the user to the Sales assistant for a proposal, and the Sales assistant what its job is.
The texts of the prompt
Every sentence the library writes into the system prompt is a property of Settings, whose default is the text of the library. Leave it alone and it follows the library when a new version improves it: a text equal to the default, or empty, is not written into the form file nor by SaveToJSON. Change it and it is yours, in the component, at the root of a file or in a profile, like any other key.
The prompt is written in this order:
| Property | Default | Values | |
|---|---|---|---|
| 1 | IdentityRule | Your name is %0:s. | the name of the assistant |
| 2 | ExpertiseIntro | Your field of expertise is %s. | Expertise; only when there is one |
| 3 | SystemPrompt | the rules about the excerpts and the citations | - |
| 4 | ExpertiseRule | the rule that keeps the procedures to the manual | -; only with an Expertise |
| 5 | Instructions | (empty) | - |
| 6 | LanguageRule | The language of this chat is %0:s. Reply in %0:s, even when the user writes in another language. | the language of the chat |
| 7 | DocLanguageRule | the rule that keeps the names of the screens as the manual spells them | the language of the manual, the one of the chat; only when DocLanguage differs |
Then, when the application registers actions, the rule about them. And what changes with every question: now (NowRule, Now it is %s., the date, the time and the time zone), the screen the user is on and the excerpts of the manual, whose labels are messages of the library (changing a message). These three travel with the question, not in the system prompt, so that the system prompt stays the same and the prompt cache of the service keeps it. Until 1.12 IdentityRule said now as well (%1:s): a text written that way still gets it, and NowRule is not added - but the system prompt then changes every minute. The rule about the actions cannot be changed, nor can the two sentences the model reads when the user refuses an action: they are what keeps a tool from being called because a text asked for it, and what ends a plan the user said no to.
A text takes its values with Format: %0:s, %1:s where the table says. A text that does not fit them - a %d where a name goes, a value more than it receives - is not an error at run time: the text of the library is used instead, and the configuration check says so.
{
"IdentityRule": "You are %0:s, the assistant of Acme CRM.",
"NowRule": "Today is %s.",
"Profiles": {
"Sales": { "LanguageRule": "Always reply in %0:s, in a friendly tone." }
}
}The Prompt page of the configuration editor lists these settings in this order, with the prompt they build beside them.
The last word: OnBuildSystemPrompt
When a text is not enough, OnBuildSystemPrompt on the component receives the system prompt of each request, already built, and may change it or replace it. With claude, openai and gemini that is the part that does not change - name, field, rules, Instructions, language: now, the screen and the excerpts travel with the question (prompt caching) and do not pass through the handler; the screen is still in AContext.
procedure TMainForm.HelpChatAIBuildSystemPrompt(Sender: TObject;
const AContext: THelpChatContext; const ALanguage: THelpChatLanguage;
var APrompt: string);
begin
// AContext: the screen the question comes from; ALanguage: the language of the reply.
if AContext.ScreenName = 'InvoiceForm' then
APrompt := APrompt + ' Amounts on this screen are in euro, VAT excluded.';
end;It runs on the worker thread that is about to call the model, like OnDecryptSecret, and calls are serialized: build the text and return, never show anything. The rule about the actions is added after it, so a handler cannot remove it. It does not run inside the IDE, so the preview and the Prompt page show the prompt without it.
Every system prompt also opens with the name of the assistant - the one the panel shows, the default "Assistant" in the language of the chat when it has none. Now - date, time and time zone - travels with each question (NowRule): a document the model writes is dated, and "is it too late to call New York?" has an answer.
The models of an assistant
Models is the list the user may switch between; SelectedModel names the one in use at start:
{
"SelectedModel": "Claude",
"Models": [
{ "Name": "Claude", "Provider": "claude", "Model": "claude-haiku-5-5" },
{ "Name": "Gemini", "Provider": "gemini", "Model": "gemini-3.5-flash-lite" },
{ "Name": "Gemma (local)", "Provider": "openai", "Model": "gemma4:12b" },
{ "Name": "GPT-OSS (local)", "Provider": "openai", "Model": "gpt-oss:20b" },
{ "Name": "Qwen Coder (local)", "Provider": "openai", "Model": "qwen3-coder:30b" }
],
"Claude": { "ApiKey": "sk-ant-..." },
"Gemini": { "ApiKey": "..." },
"OpenAI": { "BaseUrl": "http://localhost:11434/v1" }
}| Key | Description |
|---|---|
Name | What the panel calls it. Unique in the list |
Provider | claude, openai, gemini, or a provider of yours. Empty = the Provider of the configuration |
Model | Empty = the model of the provider's section |
BaseUrl | Empty = the endpoint of the provider's section |
ApiKey | Empty = the key of the provider's section, as long as the model is served by the same host (below) |
ApiKeyEncrypted | The same key encrypted by the application: the second node of every secret |
Icon | Empty = deduced (see below); otherwise one of the icon ids |
The keys and the endpoints stay in the sections Claude, OpenAI and Gemini: a model repeats them only when it needs a different one. One section per provider would not have been enough - three local models on one Ollama are three models on openai.
A file that names Models replaces the list of the files read before it; one that does not leaves it alone. In a profile, an entry that is just a name picks that model of the catalogue at the root, with everything the catalogue says about it. The catalogue is kept apart from the list a profile narrows it to: it is the Models of the last root that had one, so the profile of a file read later - the per-user one, after the one the application ships - can still name any model of it. A name the catalogue does not have is refused with an error, not skipped. With no list nothing changes: Provider is the one model, and the user cannot switch.
A model that names no Provider runs on the one the configuration names. While a model that does name one is in use, Settings.Provider reads as the provider of that model, and Settings.ConfiguredProvider is what the configuration said: a switch is an override, never a change of the configuration.
The key of a model
A key belongs to a service, so it never follows a model to another host. A model with no ApiKey of its own uses the key of its provider's section - or the environment variable - only while it is served by the endpoint of that section. When its BaseUrl is on another scheme, host or port, it is called with no key at all: otherwise the key of OpenAI would be handed to whatever answers at the new address. The same host with another path - a gateway in front of the same service - keeps the key of the section.
What an entry therefore needs:
{
"OpenAI": { "ApiKey": "sk-..." },
"Models": [
{ "Name": "GPT", "Provider": "openai" },
{ "Name": "Llama (Groq)", "Provider": "openai", "Model": "llama-3.3-70b-versatile",
"BaseUrl": "https://api.groq.com/openai/v1", "ApiKey": "gsk_..." },
{ "Name": "Gemma (local)", "Provider": "openai", "Model": "gemma4:12b",
"BaseUrl": "http://localhost:11434/v1" }
]
}A model on Groq, OpenRouter or any other service than the one of the section carries its own BaseUrl and its own key; a local Ollama or LM Studio names its BaseUrl and no key, because it needs none. In the examples above the OpenAI section itself points at Ollama, so the local models need neither.
From 1.7
Assistants is now Models and Assistant is now SelectedModel; SystemPrompt moved from the provider sections to the root (or to a profile). A file that still uses the old keys is refused with an error that names the new ones, instead of being silently ignored.
What the user sees

The icon of the model in use is the last button on the right of the header. Resting the mouse on it shows the name and the model; with more than one model a click opens the list, each with its icon, name and model, and the one picked answers from the next question on. The arrows move through it, Enter picks, Escape closes it; a list taller than the window scrolls. A reply that is being written keeps the model it started with.
The list offers only the models that could answer. A model whose provider says something is missing - the same question the configuration check asks - is left out: claude and gemini with no key, openai with no key unless its endpoint is on this machine or on a private network (a local Ollama or LM Studio needs none, so it is offered as soon as its BaseUrl is there; Groq or OpenRouter need theirs), docsearch with no index. The catalogue can therefore name every service the application supports, and each user sees the ones they have a key for. The model in use is always listed, whatever it lacks, because the panel shows what is answering; and at start the engine never picks a model that cannot answer while another of the list can - the first that can takes its place, without being remembered, so the one named comes back once its key is there. The page asks for the list again whenever it gets the focus, so a key the application registers while the panel is open shows its model at once.
The choice is remembered per user in helpchatai-state.json (with the profile in its name), next to the saved conversation - never in a configuration file, so the file with the keys is never rewritten. At the next start the remembered model wins, if it is still in the list.
The icons
The icon is deduced from the model first, then from the endpoint, then from the provider: a gemma4 served through openai by Ollama shows the Gemma icon, not the OpenAI one, and an unknown model on Ollama shows the Ollama llama.
| Icon id | Shown for |
|---|---|
claude | claude-*, or the claude provider |
gemini | gemini-*, or the gemini provider |
openai | gpt-*, o1/o3/o4, or the openai provider on its own endpoint |
gemma, qwen, mistral, deepseek, llama, cohere | the model families |
ollama, lmstudio, openrouter, groq, azure | a model nobody recognises, by the service that serves it |
github | only a model that names it in Icon |
docsearch and stub have no icon, and the header shows none for them when they are alone. The icons are the SVG files of lobe-icons (MIT), compiled into the library; the logos themselves are trademarks of their owners. The monochrome ones take the colour of the text, so they follow the theme of the panel.
From code
Everything the list does, the component does too:
var
LInfo: THelpChatModelInfo;
begin
for LInfo in HelpChatAI.Models do
Memo.Lines.Add(Format('%s - %s %s', [LInfo.Name, LInfo.Model,
IfThen(LInfo.Active, '(in use)', '')]));
HelpChatAI.SelectModel('Gemini'); // False if there is no such model; a model
// the list leaves out may still be picked
HelpChatAI.RetryLastQuestion('Claude'); // the last question again, to Claude
end;Models is what the panel offers; HelpChatModelIsConfigured(Settings, AName) (HelpChatAI.Provider) is the test it applies. THelpChatSettings has the rest at the engine level: ResolveModels (the whole list, configured or not), ActiveModelName and ApplyModel(AName), which sets Provider and puts the model, endpoint and key of that model on top of the provider's section without rewriting it - what the Object Inspector and the file show stays what you configured, and ConfiguredProvider still answers with the provider of the configuration.
Checking them
The configuration check of the component editor (and /check in the panel) tests every model of the list, as if it were the one in use: a missing key or a provider whose unit is not linked shows up before the user picks it. A finding about one of them is filed under Model "<name>". The provider it checks first is the one of the model in use, not the bare Provider, which with a list is only what a model that names none falls back on.
It also looks at the assistant itself. DocAreas is compared with the areas the index really has: an area no page belongs to is a warning. The check of the component editor warns about a Profile that no configuration file defines (the assistant would run with the root alone), and reads the same files the application will, the per-user one included. /check, which runs in the application, where the actions are, reports the names of AllowedActions that no registered action answers to.
With a remote engine
The list comes from the server, and the server is everybody's: the panel shows it, but a client cannot switch the model for every other user. The selection answers 403.
The profiles work the same way there: a server whose configuration has a Profiles section answers each component as the assistant its Profile names, with one engine per profile (assistants on a server).
Comparing them
Test\LLMBench in the repository is a console program that asks every model the same questions about the manual of the CRM demo, one model after the other (local models share one GPU), and writes a Markdown report: time to the first token and to the end, whether the answer cites the right page, whether it calls the right action. It is how the system prompt of 1.5.0 was tuned, and how the default models were chosen. The run of 12 November 2026:
| Model | Average time | Right citations | Right facts | Right actions |
|---|---|---|---|---|
| claude-haiku-5-5 (default) | 1.8 s | 8/8 | 11/11 | 8/8 |
| claude-haiku-4-5 | 1.7 s | 8/8 | 11/11 | 8/8 |
| claude-sonnet-5-5 | 2.2 s | 7/8 | 11/11 | 8/8 |
| claude-opus-5-5 | 2.6 s | 7/8 | 11/11 | 8/8 |
| gpt-6-luna (default) | 2.5 s | 7/8 | 11/11 | 8/8 |
| gpt-6.1-sol | 2.8 s | 7/8 | 11/11 | 8/8 |
| gemini-3.5-flash-lite (default) | 1.1 s | 8/8 | 10/11 | 8/8 |
| gemini-3.8-flash | 4.0 s | 7/8 | 11/11 | 8/8 |
| gemini-pro-latest | 6.1 s | 8/8 | 10/11 | 8/8 |
| gemini-4-argon | 7.0 s | 8/8 | 11/11 | 8/8 |
| gemma4:12b (local) | 5.2 s | 8/8 | 11/11 | 8/8 |
| gpt-oss:20b (local) | 3.1 s | 8/8 | 11/11 | 8/8 |
| qwen3-coder:30b (local) | 4.2 s | 6/8 | 11/11 | 6/8 |
Measured on one machine with an RTX 5060 Ti 16 GB: take the shape, not the numbers. On questions this simple the larger models are as accurate and slower. Most of the citations counted as wrong are not: a model that cites the manual after creating a lead, where the benchmark expects no citation at all, or one that cites a page close to the expected one.