Class LLMSystemPrompt
Each populated section is wrapped in its own XML-style tag
(<Identity>, <Context>, <Capabilities>, <Behavior>,
<Output>) and only included in the final prompt if it was actually set — see
generateSystemPrompt().
Instances are assembled via builder(). Callers who need capability routing
hints compiled from a live set of registered tools must call
generateCapabilities(ArrayList) before generateSystemPrompt();
see that method's docs for why this is a separate step rather than being folded into
construction.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe behavior/constraints section of a system prompt — tone, formatting rules, and other "how to behave" instructions.static classBuilder for assembling anLLMSystemPromptfrom its component sections.static classDefines per-tool usage-routing hints for the<Capabilities>section of a system prompt — i.e.static classA builder for the static-facts<Context>section of a system prompt — things the model should always know (e.g.static final recordThe persona/role block of a system prompt — who the model is and what it's for.static classSpecifies the expected output format for a system prompt's<Output>section — e.g. -
Constructor Summary
ConstructorsConstructorDescriptionLLMSystemPrompt(LLMSystemPrompt.Identity identity, String context, LLMSystemPrompt.Capabilities capabilities, String behavior, LLMSystemPrompt.OutputFormat outputFormat) Constructs a system prompt from its component parts. -
Method Summary
Modifier and TypeMethodDescriptionstatic LLMSystemPrompt.Builderbuilder()Creates a newLLMSystemPrompt.Builderfor assembling anLLMSystemPrompt.voidgenerateCapabilities(ArrayList<Tool> tools) Renders this prompt's currently-set sections into a single system-roleMessage, ready to be sent to Ollama.
-
Constructor Details
-
LLMSystemPrompt
public LLMSystemPrompt(LLMSystemPrompt.Identity identity, String context, LLMSystemPrompt.Capabilities capabilities, String behavior, LLMSystemPrompt.OutputFormat outputFormat) Constructs a system prompt from its component parts. Preferbuilder()over calling this directly.- Parameters:
identity- the persona/role block, ornullto omit itcontext- the pre-built static-context body, ornullto omit itcapabilities- the tool usage-hint definitions, ornullto omit the capabilities section entirelybehavior- the pre-built behavior/constraints body, ornullto omit itoutputFormat- the output-format specification, ornullfor free-text output
-
-
Method Details
-
generateCapabilities
Compiles the<Capabilities>section from the tools currently registered on the givenArrayList<Tool>, using the usage hints defined incapabilities.This is intentionally a separate step from construction rather than something the constructor does automatically: which tools are registered on an
ArrayList<Tool>can change after this prompt is built (tools added/removed at runtime), so the compiled capabilities text needs to be regenerated on demand against whatever the current tool set actually is, not frozen at construction time.For each registered
FunctionTool, this looks up a usage hint by the tool'sClassviaLLMSystemPrompt.Capabilities.getUsageHints(). If no hint was registered for that class, the tool is silently omitted from the compiled output — there is no fallback toFunctionTool.description(), since that text is written to help the model choose a tool mid-conversation, not to explain routing up front in a system prompt; conflating the two would blur what each is for.If
capabilitiesisnull(this prompt doesn't use a capabilities section at all), this clearscompiledCapabilitiestonulland returns without inspectingollamaObject.- Parameters:
tools- the object whose currently-registered tools should be inspected
-
generateSystemPrompt
Renders this prompt's currently-set sections into a single system-roleMessage, ready to be sent to Ollama.Each section —
identity,context,compiledCapabilities,behavior,outputFormat— is wrapped in its own XML-style tag and appended in that fixed order. A section is included only if it is non-null (and, for capabilities, non-blank); sections that were never set or never compiled are simply skipped rather than emitted as empty tags.Note that
compiledCapabilitiesreflects whatever tool set was live the last timegenerateCapabilities(ArrayList)was called — call that first if the registered tools may have changed since.- Returns:
- a new
Messagewith roleMessage.Role.SYSTEMcontaining the compiled prompt text
-
builder
Creates a newLLMSystemPrompt.Builderfor assembling anLLMSystemPrompt.- Returns:
- a fresh, empty
LLMSystemPrompt.Builder
-