How to Integrate AI with T-FLEX: Moving Away from Chatbots to Controlled Agents

LLMs often "hallucinate" in closed systems like T-FLEX CAD, generating syntactically plausible but functionally incorrect code. Engineers created tflex_harness—a framework that abandoned chatbot abstractions in favor of strict control: local API search, C# code generation, pre-execution compilation, and controlled execution in CAD. Result: the agent runs more stably and makes fewer mistakes.

AI-processed from Habr AI; edited by Hamidun News
How to Integrate AI with T-FLEX: Moving Away from Chatbots to Controlled Agents
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Layer 1Language Model—generates a textual description of the task based on the user's request
Layer 2Control Loop—parses the LLM result, validates commands before sending to CAD
Layer 3Local API Documentation Search—the system suggests correct method names and parameter types to the model

Attempts to embed large language models in engineering software like T-FLEX CAD usually end the same way: the process crashes, the license hangs, the project rolls back. Engineers from Habr figured out why this happens and showed a practical way to fix it.

Why LLMs Hallucinate in CAD

T-FLEX is not a web application. It's a closed system that operates through DLL libraries and requires strict session control, precise API method names, and type matching. One mistake—and the system crashes.

LLMs, by their nature, generate probabilistic answers. The model can generate code that looks plausible: the syntax is correct, the logic seems sound. But details matter: there might be an incorrect parameter type, a typo in a method name, or a reference to a structure field that doesn't actually exist.

In a web application, this would display an error on the page. In CAD, it crashes the process. Engineers call this a "hallucination." The model confidently outputs an incorrect answer. And when dozens of such attempts in a row fail, the conventional approach loses meaning.

How tflex_harness Works

Instead of connecting an LLM directly, engineers created the tflex_harness framework. It's not a chatbot. It's a multi-layered control system:

  • Layer 1: Language Model—generates a textual description of the task based on the user's request
  • Layer 2: Control Loop—parses the LLM result, validates commands before sending to CAD
  • Layer 3: Local API Documentation Search—the system suggests correct method names and parameter types to the model
  • Layer 4: C# Code Generation and Compilation—the LLM writes code, the compiler validates it before execution
  • Layer 5: Isolated Execution—code runs in a separate T-FLEX session, errors don't crash the main process

Result: if compilation fails, the model sees the specific error and tries again. The agent learns. Most importantly—only validated, compiled code reaches the CAD system.

Rejecting Abstractions

This is the key difference from typical AI solutions. tflex_harness rejects pretty promises. Instead, the system works more concretely: the model cannot invent methods—it can only use those registered in the API. Code doesn't exist only in the neural network's mind—it actually compiles. Errors are verified mechanically, not statistically. This sounds like a limitation. In practice, it's the only way to trust the result.

What This Means

To integrate LLMs into specialized software, you don't need the largest model or the most elegant interface. You need predictability and control at every step. For CAD systems, CAM software, and engineering tools in general, this approach opens a new scenario: safe automation of engineering tasks without the risk of data loss or license crashes.

Story

Key Questions Answered

Why LLMs Hallucinate in CAD?

T-FLEX is not a web application. It's a closed system that operates through DLL libraries and requires strict session control, precise API method names, and type matching. One mistake—and the system crashes. LLMs, by their nature, generate probabilistic answers. The model can generate code that looks plausible: the syntax is correct, the logic seems sound. But details matter: there might be an incorrect parameter type, a typo in a method name, or a reference to a structure field that doesn't actually exist. In a web application, this would display an error on the page. In C

How tflex_harness Works?

Instead of connecting an LLM directly, engineers created the tflex_harness framework. It's not a chatbot. It's a multi-layered control system: Layer 1: Language Model—generates a textual description of the task based on the user's request Layer 2: Control Loop—parses the LLM result, validates commands before sending to CAD Layer 3: Local API Documentation Search—the system suggests correct method names and parameter types to the model Layer 4: C# Code Generation and Compilation—the LLM writes code, the compiler validates it before execution Layer 5: Isolated Execution—code

What are the key details on Rejecting Abstractions?

This is the key difference from typical AI solutions. tflex_harness rejects pretty promises. Instead, the system works more concretely: the model cannot invent methods—it can only use those registered in the API. Code doesn't exist only in the neural network's mind—it actually compiles. Errors are verified mechanically, not statistically. This sounds like a limitation. In practice, it's the only way to trust the result.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Hands-On AI Engineering · Hamidun Academy

Build & Ship Production AI Agents Without Boilerplate Code

Start your free 72-hour trial at Hamidun Academy (academy.hamidun.com) — interactive lessons on Claude Code & Cursor, live Tech Radar, and production agent templates.

Start 72h Free Trial →Vibe-Coding Intensive
What do you think?
Loading comments…