TOTVS has re‑engineered its enterprise data layer to serve token‑intensive AI agents. By weaving a data mesh with low‑latency databases, adding semantic ontologies, and selecting Model Context Protocol (MCP) tools dynamically, the company reduces the number of tokens required to convey transactional context while keeping deterministic logic where precision and security matter.
Data Mesh and Low‑Latency Storage
The new layout treats each domain as a mesh node, exposing data close to the point of consumption. Low‑latency database architectures keep round‑trip times short, which is critical when AI agents request fresh transactional records within tight context windows.
Semantic Ontologies for Context
Semantic models describe relationships and meanings across the mesh, allowing agents to construct richer prompts without inflating token counts. The ontologies act as a deterministic layer that guides LLMs, helping maintain precision and limiting exposure of raw data.
Dynamic MCP Tool Selection
Instead of a static protocol, the system picks the appropriate MCP implementation per request. This flexibility lets engineers match the protocol’s token‑packing strategy to the size and sensitivity of the data, directly influencing cost and security posture.
Related CloudNinjas coverage: AI engineering.
What This Means For Practitioners
Engineers should evaluate their own data‑mesh topology, latency characteristics, and semantic modeling practices when integrating AI agents. Consider introducing a configurable MCP selection mechanism to tune token usage per workload. Monitoring token consumption alongside latency and security metrics will reveal trade‑offs and guide further optimisation.



