Skip to content / 跳转到内容
Back to Notes
2 min read

From Fixed Tool Chains to Sandboxed Document Agents and Safe AI Templates

Engineering notes from building an enterprise AI knowledge base on LightRAG: Docker sandboxes, three-layer document verification, and an evaluation-free Word template engine.

AI AgentLightRAGDockerDocument Engineering
Table of contents

Limits of Fixed Tool Chains

The first version of our knowledge-base writing assistant used fixed tool calls: retrieve context, emit a structured JSON schema, and render Word, Excel, or PowerPoint files on the server. That worked for greenfield drafts, but broke down as soon as users uploaded real enterprise documents with headers, footers, embedded images, and complex tables expecting surgical edits.

Decoupling Method from Execution

I shifted the architecture to a clear split: let the model choose the method, and let the service own execution and delivery. The agent inspects outlines and styles, loads versioned format skills, and writes targeted Python scripts when needed. Meanwhile, SQLite persists runs, leases, and sequenced event streams independently of any single HTTP stream so refreshes and disconnects resume cleanly from the last sequence number.

Sandboxed Execution in Docker

Once a model can write scripts, isolation is non-negotiable. Every task runs inside a dedicated Docker container as a non-root user with networking disabled, a read-only root filesystem, and strict CPU, memory, process, and time caps. Only the task workspace is mounted—host source code, model keys, and other sessions stay out of reach, and the service fails fast rather than falling back to host execution.

Three-Layer Verification and Baseline Safety

A second lesson was never trusting a model that says 'Done'. Before publishing, every candidate passes three checks bound to SHA-256 hashes of the file and rendered pages: structural OOXML integrity, semantic coverage verified from actual read-back, and visual layout inspection by a VLM over rendered PDF pages, with up to three repair rounds. Before replacing an active file, the service also checks the ONLYOFFICE edit baseline and saves a downloadable conflict copy instead of overwriting manual edits.

Evaluation-Free AI Template Library

For recurring contracts and forms where layout cannot drift at all, I built a Word template library with AI-assisted marking. Users upload an ordinary document, the LLM suggests variable spans across long-document windows, and a human confirms the fields in a review screen. Because uploaded files are untrusted input, the filler avoids Jinja or any expression evaluator and performs plain single-pass run-level {{key}} substitution, keeping formatting intact byte for byte.