LLM and Agent Engineering: From Classroom Practice to Production Scale
This article explains how to move large language model (LLM) and agent applications from demonstrations to production systems. It covers task-boundary selection, layered architecture, governance of prompts, skills, tools, and knowledge, verification loops for AI-assisted coding, non-functional readiness, workload-based capacity planning, teaching practices, and incremental rollout. The central argument is that reliable LLM systems do not come from longer prompts or more agents alone; they come from controlled execution, traceable assets, verifiable results, and the ability to stop safely when something goes wrong.
1. From “the model can answer” to “the system can deliver”
LLMs have lowered the barrier to natural language interaction, knowledge retrieval, and code generation. But model capability is not the same as business delivery capability. A demonstration system can rely on a small set of samples, manual checks, and temporary configuration. A production system must handle continuous requests, permission isolation, changing data, exception recovery, and cost constraints.
Consider AI-assisted programming. Generating a plausible-looking patch completes only part of the task. The system also needs to understand the problem boundary, locate the relevant code, reproduce the failure, run tests, and confirm that the change does not introduce regressions. Without a reliable execution environment and verification mechanism, faster generation may simply accumulate more changes waiting for review.
Therefore, the core of LLM application engineering is not endlessly lengthening prompts or simply stacking multiple agents. It is establishing a closed loop:
Requirement definition → context preparation → model inference → controlled execution → result verification → operational feedback.
This loop applies to enterprise applications and university teaching alike. The main differences lie in business scale, data sensitivity, and reliability requirements, not in the basic method.
2. Define task boundaries before deciding whether to introduce agents
An agent generally refers to a software system that can pursue a goal, choose steps under constraints, call tools, and continue executing based on feedback. Compared with a single model Q&A interaction, it emphasizes action and feedback. At the same time, it introduces a longer execution chain and more complex failure modes.
Not every task needs an agent. Before technical selection, distinguish among three types of problems.
1. Problems that fixed rules can solve
For format conversion, field validation, deterministic calculation, and similar tasks, prefer conventional programs. Such tasks require stable results and explicit processes. Introducing a generative model may not add value and may increase latency and uncertainty.
2. Problems with a fixed workflow and localized need for understanding
For example, extracting information from unstructured documents and then entering a defined approval workflow. A suitable approach is a deterministic workflow with model nodes: the program controls the main flow, while the model handles semantic understanding, classification, or content generation.
This architecture makes it easier to trace the source of errors and to set human confirmation at critical nodes.
3. Problems with non-fixed paths that require multi-round exploration
Examples include analyzing failure causes, finding code locations to modify, and organizing materials from multiple sources. Such tasks may justify an agent, but stop conditions, tool permissions, and resource budgets must be explicit.
The selection principle is: use the minimum level of autonomy sufficient to complete the task. Do not turn a fixed process that can be executed reliably into an unpredictable autonomous decision chain merely for the appearance of intelligence.
3. Build a layered architecture so business logic is not captured by prompts
A maintainable LLM application can be divided into the following layers by responsibility.
1. Business access layer
This layer handles identity authentication, request validation, user interaction, and result presentation. It must clearly distinguish ordinary users, business administrators, and system maintainers, and avoid exposing backend operation capabilities directly through the conversational entry point.
2. Process orchestration layer
This layer controls task state, execution steps, timeout policies, retry conditions, and human approval. Critical business rules should remain in testable program logic as much as possible rather than existing only in natural language instructions.
For example, “approval is mandatory when the authorized limit is exceeded” should be enforced by the program, not left to the model to understand and follow.
3. Model and context layer
This layer handles model invocation, prompt assembly, information retrieval, and context trimming. It needs to record the model version actually used, the prompt version, and the knowledge sources so that problems can be reproduced.
A long context window can hold more information, but that does not mean the information will be used completely and accurately. Repetitive content, outdated materials, and irrelevant logs can still interfere with judgment. Information should therefore be filtered and organized before it is passed to the model.
4. Tool execution layer
This layer handles actual actions such as file operations, data queries, and test runs. Explicit input and output contracts should limit the scope of invocation, and parameters should be validated before execution.
For high-impact operations such as writes, deletions, and releases, add approval or double confirmation. “The model proposed an operation” must not be treated as “the system is allowed to execute it.”
5. Governance and observability layer
This layer provides unified logging, metrics, auditing, evaluation, and cost accounting. It is not an add-on after launch; it should be included in the design from the prototype stage.
4. Turn prompts, skills, and tools into governed assets
When a team has only one demonstration application, prompts may live in code constants or personal documents. As applications increase, this approach easily leads to duplicated work, behavioral drift, and version inconsistency.
The objects that need governance include not only models but also:
- system instructions and prompt templates;
- domain knowledge and retrieval configuration;
- tool descriptions, input/output constraints, and permission scope;
- agent task flows and stop conditions;
- test datasets, evaluation rules, and release records.
These assets should have clear owners, versions, applicable scope, and dependencies. If a prompt change affects tool selection or output structure, it should be reviewed and tested like a code change.
Each application release can record the following information:
Release recordApplication versionModel version or traceable identifierPrompt versionKnowledge asset versionTool contract versionEvaluation resultsApproval recordsRollback target
The key is not a particular file format. It is making runtime results traceable. If the upstream model service cannot provide a fixed version, record the invocation time and available service identifier, and monitor behavioral changes through continuous evaluation.
Open collaboration also requires this mechanism. When sharing code, teaching samples, or technical materials, specify licenses, contribution processes, and data usage boundaries. “Accessible” must not be interpreted as “usable without restrictions.”
5. Reliability in AI-assisted coding comes from a verification loop
The most common mistake in AI-assisted coding is treating “patch generated successfully” as “problem solved.” In practice, a code change needs to go through at least five stages.
1. Establish a failure baseline
First confirm whether the original problem can be reproduced, and save failure logs, runtime conditions, and relevant test results. Without a baseline, it is difficult to judge whether a change is truly effective.
2. Control the scope of change
Require the system to prioritize the smallest change directly related to the problem and avoid unnecessary refactoring of many files. The larger the change, the higher the review cost and regression risk usually are.
3. Execute in an isolated environment
The test environment should be separated from production, should not contain real business credentials, and should limit network access, writable directories, and resource consumption. External problem descriptions, code comments, and logs should all be treated as untrusted input. Execution permissions must not be relaxed just because they contain instructions.
4. Perform layered verification
First check syntax and static rules, then run targeted tests, and finally run regression tests for affected modules. For sensitive logic such as permission control, financial processing, and data deletion, retain human review.
Passing tests does not mean absolute correctness. Tests themselves may have insufficient coverage, so also check whether the change satisfies the original requirement and whether there is gaming behavior such as bypassing validation or weakening assertions.
5. Set termination conditions
Automated repair cannot loop indefinitely. Limit the number of attempts, cumulative time, and resource budget. When repeated failures, permission conflicts, or requirement ambiguity occur, hand the task over to a human.
The maturity of a system is shown not only in how many steps it can complete when successful, but also in whether it can stop promptly and explain the reason when it fails.
6. From proof of concept to production, fill in non-functional capabilities
A proof of concept answers whether the approach is feasible. A production system must also answer whether it is stable, secure, economical, and maintainable.
1. Establish multidimensional evaluation
Evaluation should not focus only on whether answers are fluent. It should cover:
- Task quality: whether results are correct, complete, and compliant with business constraints;
- Execution reliability: whether tool calls succeed and exceptions are handled properly;
- Security: whether the system exceeds permissions, leaks sensitive information, or performs dangerous actions;
- Efficiency: end-to-end latency, number of calls, and resource consumption;
- Operability: whether failure causes can be located and execution processes traced.
The evaluation set should include normal samples, boundary inputs, insufficient information, unavailable tools, and malicious inducement. Data used for training or tuning should be appropriately separated from final acceptance data to avoid distorted results.
2. Establish end-to-end observability
An agent task may involve multiple rounds of model calls, retrieval, and tool execution. Keeping only the final answer cannot explain what happened in between.
Record task identifiers, step status, tool return codes, latency, and resource consumption. For input and output content, apply minimum necessary logging, redaction, and access control so that the logging system does not become a new channel for sensitive data leakage.
3. Design degradation and recovery
When a model call fails, the system can, where conditions allow, return limited-function results, switch to a fixed workflow, or hand the task to a human. For write operations, confirm the previous execution state before retrying to prevent duplicate submission.
Retry mechanisms must consider idempotency. A network timeout does not mean the operation did not occur. Blind retries may create duplicate records or duplicate deductions.
7. Plan capacity around workload, not model size alone
When deploying an LLM application, model weights are only part of the resource requirement. Context length, concurrency, output length, inference caching, and the load generated by retrieval and tool execution all affect actual resource consumption.
Capacity planning should start from real tasks: measure request size, peak concurrency, acceptable latency, and task types, then validate through stress testing. Do not infer serving capacity directly from the number of model parameters.
Interactive Q&A and long-running background tasks should use different scheduling strategies. Background tasks can enter a queue with concurrency limits and timeout controls, preventing long tasks from continuously occupying resources and affecting online requests.
For enterprises, a more meaningful cost metric is often “the total cost of completing one qualified task,” not the price of a single call. It should include inference, retrieval, tool execution, retries, human review, and operations. If a low-cost model requires many retries, its final cost may not be lower.
8. Make teaching practice closer to real engineering rather than staying at demonstration
The value of combining university practice with industry tasks lies in helping learners understand the full delivery process, not just model invocation methods.
A suitable practical task should meet three conditions: a clear business goal, authorized or de-identified data, and objectively verifiable results. For example, building internal knowledge Q&A, analyzing simulated failure records, and generating test cases can all be designed as projects with clear boundaries.
Teaching can be organized in stages:
- Define users, usage scenarios, and prohibited actions;
- Build a baseline solution without LLMs for comparison;
- Introduce the model and explain its gains and new risks;
- Add permission control, testing, logging, and exception handling;
- Complete acceptance through demonstrations, test reports, and operating instructions.
Evaluation criteria should also expand from “whether the interface is complete” to “whether the problem is defined accurately, whether the solution is reproducible, and whether failures are explainable.” This kind of training helps students develop engineering judgment and makes it easier for enterprises to identify talent capable of handling real projects.
9. Drive scale through incremental delivery
Sustainable LLM adoption is usually not a one-time effort to build a huge system. It starts with high-frequency, low-risk tasks with verifiable results and gradually expands the capability boundary.
In the early stage, establish a quality baseline and a minimum closed loop. In the middle stage, consolidate reusable prompts, tool contracts, test sets, and operating standards. In the later stage, expand scenarios based on stability and cost performance, while retaining human control points for high-risk processes.
From classroom practice to enterprise production, what is truly reusable is not a model name or a successful demonstration, but a set of engineering methods for handling uncertainty: clear task boundaries, controlled execution permissions, verifiable results, traceable issues, and systems that can stop safely.
When these foundations are in place, LLMs and agents can gradually move from local efficiency tools to reliable components of software systems.
