Skip to main content

AI Integration

The DotHRB framework provides a suite of helper classes and utilities designed to streamline the integration of Large Language Models (LLMs) into Harbour applications.

These tools are optimized for a secure, two-step Function Calling (Tool Use) workflowβ€”the industry standard for allowing AI to interact safely with your local application data and business logic.

Implementation Note: Optimization Required

While these components provide the full foundational logic for communication and state management, they are designed as reference implementations and starting points. Because AI outcomes heavily depend on variables like model selection, prompt tuning, temperature settings, and the underlying engine (local vs. cloud), you should expect to customize and tune these classes to achieve your specific business logic and performance goals.


🌎 Core Connectivity and Execution​

These classes function as the primary SDK layer, enabling communication between your Harbour environment and any LLM provider, whether hosted in the cloud or running locally.

ClassPurposeKey Benefit
AIProviderServiceManages providers like Llama.cpp, Ollama, OpenAI, Google.Flexible connectivity: works with Cloud APIs (OpenAI, Azure) or Local Engines (Ollama) for PHI/Sensitive data.
AIToolServiceManages system prompts and tool definitions for any OpenAI-compatible service.Tools are managed as separate json files that can be easily updated and tuned during development but at build time they are embedded in the application to avoid unauthorized updates.
AIChatControllerOrchestrates conversational flows between the user and the LLM.Uses the AIProviderService and AIToolService to provide a clean API for UI interaction and state management.
McpControllerThis template, Implements the Model Context Protocol (MCP) for standardized tool execution.Simplifies the JSON/XML message exchange logic for complex, multi-tool environments.

⚑ Efficiency and Cost Optimization​

Token count directly impacts API cost (for cloud models) and response latency (for local models). These utilities minimize the size of the data payload sent to the LLM.

  • TOON Format Conversion Functions​

    TOON (Token-Oriented Object Notation) is a highly compact data format, offering significant token reduction compared to standard JSON.

    // Convert structured JSON data to compact TOON format
    toon := json2toon(cJson)

    // Convert TOON back to standard JSON
    cJson := toon2json(cToon)

    Benefit: Use TOON to serialize structured results (e.g., admission lists, sales data) before sending them to the LLM, potentially saving 30-60% on token cost and improving local model speed.

  • function jsonTrim(cJson)​

    cJson := jsonTrim(cJson)

    Removes all unnecessary spaces, newlines, and carriage returns from standard JSON strings. This ensures the JSON used for function definitions and data payloads is as compact as possible, maximizing the model's context window.