Why this matters
The next thing customers ask for after chat is for the model to consult the application's own logic —
look up a customer, price an order, query a device — and reason over what comes back. In .NET that
orchestration layer is Microsoft Semantic Kernel. Nothing equivalent has existed for Delphi.
Orchestrate answers one request at a time. Nothing carries over between calls, which is exactly what
you want when each request stands on its own — "summarise this order using live data from my
database". When the user is holding a conversation, or a task takes several steps, that is
AI4Delphi Agents.
Start here without risk. RegisterFunction is the same call in both packs, so a
prototype built here moves to
Agents by changing the constructor and swapping
InvokePrompt for
Run. If you later outgrow Orchestrate you pay only the
$100.00 difference — you never pay twice for the
same capability.
How it works
The Delphi wrapper uses the auto-dispatch bridge style (TCoreClrGenericImport over an
ICoreClrInstance) — the same mechanism the production CrystalNet.Linq wrapper uses to pass
TClrFunc<...> predicates and selectors into .NET. Your anonymous Delphi function is marshalled to a
.NET Func<string,string> on that proven path, not through bespoke callback plumbing.
What you get
TKernelHost over OpenAI and Azure OpenAI chat connectors, plus 'ollama' and any other OpenAI-compatible server via a custom endpoint.
RegisterFunction(name, description, handler) — Delphi-implemented kernel functions with automatic function calling (FunctionChoiceBehavior.Auto).
InvokePrompt(prompt) — blocking invocation returning the final answer, after however many tool calls the model chose to make.
Running against a local model
The kernel runs against a local model — still calling your Delphi functions — with no key and no cloud:
KernelOllama.dpr
Kernel := TKernelHost.Create(CN_SK_PROVIDER_OLLAMA, '', 'llama3.1', '');
This deliberately reuses the OpenAI connector pointed at the local server rather than Semantic Kernel's
native Ollama connector, which is alpha-only, needs an SKEXP0070 suppression, enlarges the deployed
dependency closure, and is unreliable at exactly the automatic function invocation that is the whole point
of this pack. Reusing the OpenAI connector adds zero new packages.
Worth knowing up front: automatic function calling needs a tool-calling-capable model such as
llama3.1 or qwen2.5. Smaller local models will answer without ever invoking your function —
a quiet failure mode rather than a loud one.
Deployment notes
- Deployment is a folder, not a DLL. The facade pulls the full Semantic Kernel dependency closure (around 35 DLLs / 11 MB in the reference build). Ship the whole bin output including
.deps.json.
- Core edition: .Net 8 or later only — Semantic Kernel does not support net6 or net7. Framework edition: .NET Framework 4.5 or later.
- Requires a dotNetCore4Delphi licence (Core edition), or a .Net Runtime Library for Delphi licence for the Framework edition.