Class LLMSystemPrompt

java.lang.Object
me.neurodock.core.LLMSystemPrompt

public class LLMSystemPrompt extends Object
Compiles a structured system prompt for an LLM out of discrete, reusable pieces — identity, static context, tool-usage capabilities, behavior rules, and output format — instead of hand-writing and concatenating prompt strings inline.

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:
  • 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. Prefer builder() over calling this directly.
      Parameters:
      identity - the persona/role block, or null to omit it
      context - the pre-built static-context body, or null to omit it
      capabilities - the tool usage-hint definitions, or null to omit the capabilities section entirely
      behavior - the pre-built behavior/constraints body, or null to omit it
      outputFormat - the output-format specification, or null for free-text output
  • Method Details

    • generateCapabilities

      public void generateCapabilities(ArrayList<Tool> tools)
      Compiles the <Capabilities> section from the tools currently registered on the given ArrayList<Tool>, using the usage hints defined in capabilities.

      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's Class via LLMSystemPrompt.Capabilities.getUsageHints(). If no hint was registered for that class, the tool is silently omitted from the compiled output — there is no fallback to FunctionTool.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 capabilities is null (this prompt doesn't use a capabilities section at all), this clears compiledCapabilities to null and returns without inspecting ollamaObject.

      Parameters:
      tools - the object whose currently-registered tools should be inspected
    • generateSystemPrompt

      public Message generateSystemPrompt()
      Renders this prompt's currently-set sections into a single system-role Message, 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 compiledCapabilities reflects whatever tool set was live the last time generateCapabilities(ArrayList) was called — call that first if the registered tools may have changed since.

      Returns:
      a new Message with role Message.Role.SYSTEM containing the compiled prompt text
    • builder

      public static LLMSystemPrompt.Builder builder()
      Creates a new LLMSystemPrompt.Builder for assembling an LLMSystemPrompt.
      Returns:
      a fresh, empty LLMSystemPrompt.Builder