Engineering AI Agents in Production: A Practical Guide to Building Reliable Agentic LLM Systems
This article explores the practical engineering required to deploy next-generation agentic large models beyond simple text generation. It covers shifting from answer generation to deliverable execution, enforcing local permission boundaries with least-privilege policies, processing complex engineering drawings via multimodal parsing, managing state for dynamic dashboards, generating structured reports in chunks, and governing token costs through budgeting and caching. Readers will learn how to build auditable, repeatable, and budgetable pipelines by combining model capabilities with deterministic scripts.
1. From Answering to Delivering: The Capability Shift
Early conversational models focused on generating text: answering questions, rewriting content, and producing code snippets. The key difference with next-generation agentic models is that they extend “generation” into “execution plus artifacts.” Instead of just telling you the steps, these models plan the steps, call tools, write files, and check the results themselves.
This workflow can be abstracted into a closed loop:
Goal input -> Task decomposition -> Tool selection -> Sandbox execution -> Artifact generation -> Validation feedback -> Delivery
The real engineering challenge is not generating a result once, but making the loop repeatable, auditable, and rollback-capable. Therefore, when evaluating these models, it is recommended to break metrics into three layers: result correctness, process controllability, and unit cost.
2. Local Execution and Permission Boundaries: Keeping Actions in a Cage
Web interfaces are typically limited by sandboxes and struggle to access local files and local toolchains; only local application forms can achieve full execution capabilities. However, “being able to operate the computer” must come with a permission model, otherwise the risks are uncontrollable.
Recommended least-privilege practices:
- Tiered approval: Automatically allow reading files; require manual confirmation for writing files, installing dependencies, and accessing the network.
- Path whitelisting: Only allow reading and writing within the project root directory and designated temporary directories.
- Command whitelisting plus parameter validation: Prohibit high-risk combinations like wildcard concatenation and pipe chaining.
- Full auditing: Record the input, output, duration, and artifact hash of every tool call.
Illustrative policy configuration (pseudocode):
policy:read: autowrite: manual_approvalinstall_dependency: manual_approvalnetwork: manual_approvalallowed_roots: ["./workspace", "./tmp"]forbidden_patterns: ["rm -rf", "curl | sh"]
3. Handling Complex Engineering Drawings: Multimodal Parsing and Toolchain Generation
The difficulty with drawing-based tasks lies in the simultaneous existence of primitive semantics, layer structures, annotation standards, and dimensional constraints. A feasible path is “parse—intermediate representation—generate—render and validate.”
- Parsing: Extract primitives, layers, and text annotations to form a structured intermediate representation (JSON).
- Semantic completion: Identify missing constraints, such as unannotated tolerances, materials, and assembly relationships, and explicitly list assumptions.
- Generation: The model outputs parameterized scripts that call the local drawing toolchain to produce files.
- Validation: Read back the artifacts and compare whether the number of primitives, key dimensions, and layer names are consistent.
Intermediate representation example:
{"layers": [{"name": "outline", "visible": true}],"entities": [{"type": "line", "layer": "outline", "start": [0,0], "end": [120,0]}],"constraints": [{"kind": "distance", "value": 120, "tolerance": 0.5}]}
Key engineering point: Treat “model output” as untrusted input and use deterministic scripts for validation, rather than letting the model evaluate itself.
4. Dynamic Visualization Pages: State Model Before Visuals
The difficulty with complex pages is not layout, but linkage: filtering, linked refreshes, real-time map updates, and charts and tables sharing the same state. It is recommended to define the state and data flow first, then generate the interface.
const state = { region: null, timeRange: "24h", metrics: {} };function recompute(next) {state.metrics = aggregate(state.region, next);render(state); // A single data source drives all components}
Engineering constraints: single data source, idempotent refresh, failure degradation (display cached data and prompts when data is unavailable), and accessibility (keyboard reachability, contrast, semantic labels). These pages are suitable for “model generates skeleton + human defines style,” avoiding one-time generation of giant files that are hard to maintain.
5. Structured Reports and Long Document Layout: Templating and Chunked Generation
Text-dense report documents most test layout and consistency. One-time generation often times out and is hard to fine-tune, so a chunked pipeline is recommended:
- Outline: First produce the chapter tree and key points for each chapter, confirm manually, then expand.
- Chunked generation: Generate each chapter independently, controlling single-context length.
- Template application: Unify the master template, font size hierarchy, chart numbering, and citation rules.
- Automated validation: Check table of contents page numbers, continuity of chart numbering, and terminology consistency.
- Manual refinement: Only perform partial rewrites on conflicting paragraphs.
Pseudocode:
outline = plan(topic)for section in outline:draft = generate(section, style=template)assert check_numbering(draft)render(section, template)
6. Cost and Quota Governance: Turning Uncertainty into a Budgetable Item
Long tasks and multi-turn tool calls quickly consume quotas, which is a practical constraint for agent deployment. Governance measures include:
- Upfront budgeting: Set maximum tool call counts, maximum duration, and maximum output length for a single task.
- Caching and reuse: Persistently cache parsing results, retrieval results, and template rendering results.
- Tiered models: Use strong models for planning, and lightweight models or deterministic scripts for mechanical execution.
- Observability: Instrument tracking to count tokens, tool calls, and failure rates for each task type, forming a cost dashboard.
- Checkpoint resumption: Persist intermediate artifacts to disk, and continue from the latest checkpoint after a timeout.
7. Quality Evaluation: Do Not Trust Self-Assessment
It is recommended to establish three layers of evaluation: unit-level (whether script artifacts can be correctly opened by tools), task-level (whether explicit constraints are met), and regression-level (rerunning a fixed test case set with every release). Treat “number of manual approvals,” “rework rate,” and “cost per task” as first-class metrics, on par with accuracy.
8. Conclusion
The value of next-generation agentic models lies not in a single stunning demo, but in turning complex tasks into orchestrable, approvable, verifiable, and budgetable pipelines. The correct approach on the engineering side is: give capabilities to the model, determinism to scripts, risks to permissions and auditing, and costs to budgets and caching. For enterprise-level deployment, you can combine general capabilities such as Baidu AI Cloud’s container platform, object storage, log service, and monitoring alerts to build a complete execution sandbox and observability system.
