Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
AIDelphiTech Partner

Five Open-Source Delphi Libraries for AI Applications

Five Open Source Delphi Libraries for AI Applications

Here’s a guest blog post by Marco Geuze, Embarcadero MVP and founder of GDK Software.

Over the past six months, we built an AI platform called Codolex AI entirely in Delphi. WebStencils on the frontend, HTMX for dynamic updates, PostgreSQL on the backend, cross-compiled to Linux. Along the way, we kept hitting problems that had no good Delphi solution: executing AI-generated code, reading Office documents without COM, connecting to Microsoft 365, and optimizing data for LLM APIs.

So, we built our own libraries and open-sourced all of them. Here are the five, what they do, and why you might need them.

JavaScript4D: Run JavaScript inside Delphi

LLMs can write Delphi, but they’re far more reliable when you ask them to produce JavaScript. When we needed AI-generated code to run inside our application, embedding a JavaScript engine was the pragmatic choice. We just didn’t want to depend on Node.js or a browser.

JavaScript4D is a complete ECMAScript 5.1 interpreter written in pure Delphi. It follows a classical compiler pipeline: lexer, parser, AST, tree-walking interpreter. Over 11,000 lines of code.

It supports closures, higher-order functions, try/catch/finally, and 59 built-in methods across Array, String, Math, JSON, Object, Date, and RegExp. No DLLs, no external dependencies. Just add the units to your project.

Beyond AI, JavaScript4D is useful anywhere you need user-configurable logic: report formulas, data transformation rules, or plugin scripts.

GitHub: github.com/GDKsoftware/Javascript4D

OfficeXML4D: Read and write .docx and .xlsx without Office

Our platform runs on Linux. Users upload Word and Excel files in chat conversations. We needed to parse and generate Office documents without Microsoft Office installed.

OfficeXML4D reads and writes Office Open XML documents using only System.Zip and built-in XML units. It handles the full OOXML package structure: content types, relationships, shared strings, styles.

For Word documents, you get paragraphs with formatting (bold, italic, font size, color), tables, hyperlinks, headers, footers, lists, and page settings. For Excel, you get multiple sheets, cell styles, formulas, merged cells, number formats, and automatic shared string deduplication.

The API is interface-based, so it’s straightforward to mock in unit tests. 135 tests in the suite. Works from Delphi 10.3 Rio onwards.

GitHub: github.com/GDKsoftware/OfficeXML4D

Microsoft365-4D: Graph API with proper OAuth2

There is no official Microsoft Graph SDK for Delphi. You can wire up REST calls yourself, but there was no single library that gave you typed access to mail, calendar, contacts, and SharePoint with proper OAuth2 handling.

Microsoft365-4D provides four typed clients that share a single HTTP connection:

Mail: search, read, compose, send, manage attachments and folders, shared mailbox support.
Calendar: create, update, delete events, check availability across schedules.
Contacts: full CRUD with search.
SharePoint: browse sites, search files, download content.

The OAuth2 implementation includes PKCE code generation, state parameter validation, token refresh with thread-safe storage, and a 5-minute expiry window. Only depends on System.Net.HttpClient.

GitHub: github.com/GDKsoftware/Microsoft365-4D

Toon4D: Spend 30-60% less on LLM tokens

Every token you send to an LLM costs money and adds latency. When you’re passing structured data to an API, standard JSON wastes tokens on repeated keys and punctuation. Multiply that across thousands of daily requests and it adds up.

Toon4D converts JSON to TOON (Token-Oriented Object Notation), a compact format that LLMs parse just as well. Arrays of objects with identical keys become CSV-style tables. Repeated structure gets folded. Unnecessary syntax disappears.

The library implements the TOON v2.0 specification with 340+ conformance tests. It auto-detects tabular arrays, handles nested objects, and degrades gracefully when data doesn’t fit the compact format.

In our production environment, Toon4D reduces prompt sizes by 30-60%, which translates directly to lower API costs and faster response times.

GitHub: github.com/GDKsoftware/Toon4D

Delphi MCP Server: Connect AI assistants to your tools

The Model Context Protocol (MCP) is a standard that lets AI assistants interact with external systems through a unified interface. Instead of building custom integrations for every AI tool, you expose your functionality as MCP tools and any compatible assistant can use them.

Our MCP framework handles protocol negotiation, JSON-RPC 2.0 messaging, tool registration, and HTTP serving. You define a tool by creating a class and the framework discovers it via RTTI:

We use this framework in production with MCP servers for Odoo, Jira, Microsoft 365, Slack, databases, and more. Each server is a standalone Delphi executable that runs on both Windows and Linux.

GitHub: github.com/GDKsoftware/delphi-mcp-server

Common design principles

All five libraries share a few things:

  • Zero external dependencies. They use only Delphi RTL units. No third-party packages to manage, no DLLs to deploy.
  • Interface-based APIs. Clean contracts that make testing and mocking straightforward.
  • Tested in production. These run in Codolex AI, handling real workloads every day.
  • MIT-licensed. Use them however you want.
  • Delphi 12 Athens or later (OfficeXML4D works from Delphi 10.3 Rio).

All libraries are available on GDK Software’s GitHub. Questions, issues, or pull requests are welcome.

RAD Studio 13.1 Florence Now Available See What's New in RAD Studio 13.1 Delphi is 31 - Webinar Replay

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.

Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES