Architecture and Engineering Practices for LLMs Serving Complex Agents
Evaluation criteria for large language models are shifting from fluent single-turn answers to verifiable task outcomes. This article covers how to turn reasoning into reliable execution for complex agents, including task-tiered test-time compute, edge-cloud processing, long-context management, sub-agent orchestration, recoverable long-running workflows, external checks for coding and multimodal work, and cost, safety, and rollout constraints.
1. From Dialogue Generation to Task Execution: Evaluation Criteria Are Changing
Traditional conversational applications usually treat a single-turn answer as the main deliverable. They focus on whether the content is accurate, the wording is clear, and the response is timely. In complex agent workflows, the system must deliver a verifiable task result: completing a code change, organizing source material, generating a business document, or carrying out a sequence of actions within an authorized scope.
These tasks typically include understanding the goal, breaking it into steps, calling tools, checking results, and correcting deviations. A failure in any step can cause the overall task to fail. Model answer quality alone is therefore not enough to judge reliable task execution.
A code-change task, for example, may produce a syntactically valid patch while still missing a caller, breaking compatibility, or failing to cover abnormal inputs. A document-analysis task may summarize most of the material correctly while overlooking a constraint that determines the conclusion. What developers need is a closed loop from input to result, not a process description that merely sounds reasonable.
Release dates, internal test comments, and performance-improvement ratios in source material cannot be treated as technical conclusions when test conditions and sources cannot be verified. The more useful discussion is the general engineering problem behind them: how to turn reasoning ability into stable execution, and how to keep a sustainable balance among quality, latency, cost, and safety.
2. Test-Time Compute: Spend Extra Computation Where It Matters
Test-time compute means improving result quality by spending more computation while a request is being handled. Common approaches include longer reasoning, multiple candidate answers, self-checks, or filtering results with an external verifier. It is a family of methods, not a single fixed model architecture.
Its core value is allocating resources according to task difficulty. Simple classification, information extraction, and format conversion usually do not need extensive exploration. Multi-constraint planning, complex code repair, and cross-document analysis may need more thorough reasoning and verification.
More computation does not automatically raise accuracy. A model may keep elaborating a wrong assumption, or produce more candidates that contradict one another. A reasoning budget therefore has to be tied to verifiable signals.
2.1 Establish a Task-Tiering Mechanism
The system can choose different paths based on task risk, input size, the number of constraints, and whether the result can be checked automatically.
Low-risk tasks with clear rules are suitable for direct generation. Complex but verifiable tasks fit a generate–check–revise loop. Tasks involving funds, permissions, or important business changes need human confirmation before critical actions.
Task tiering should not rely only on the model’s judgment of its own ability. Input length, the number of files involved, the expected number of tool calls, and historical failure types can all inform scheduling.
2.2 Use Verification Results to Decide Whether to Continue
Useful extra computation should answer a specific question: why a test failed, which constraint is still unmet, or whether pieces of evidence conflict.
If the system only asks the model to “think again” without new evidence or a check standard, it tends to repeat the same reasoning. A more reliable strategy is to set stop conditions: the result has passed verification, the budget is exhausted, several consecutive rounds show no meaningful progress, or the user must supply critical information.
3. Edge-First: Prefer Local Processing, Not Local Completion of Every Task
Edge-first is a deployment and data-handling strategy. Its usual goals are to reduce unnecessary data transfer, lower interaction latency, and improve privacy control. It does not mean that full complex reasoning must run on the endpoint device.
Endpoint devices are limited by memory, power, heat, and compute. For long text, multimodal input, or complex tasks, fully local execution may not balance speed and quality. A more realistic approach is edge–cloud collaboration.
3.1 Keep Lightweight Processing on the Device
Steps that fit local execution include input cleanup, sensitive-field detection, simple intent judgment, cache lookup, and some lightweight inference.
For example, the system can first decide locally whether a request needs external material before sending it to a remote service. For repeated requests, it can prefer a validated local cache and avoid recomputation.
3.2 Transmit Only What the Task Requires
When remote processing is needed, send only the information required for the task rather than uploading the original material in full. Field trimming, partial extraction, or redaction can be used, but their effect on task quality must be assessed.
Redaction does not automatically equal anonymization. Combinations of role, place, time, and event in text can still be identifying. Enterprise applications should also define retention, access rights, and deletion.
3.3 Include Real Device Behavior in Evaluation
An edge design should not be judged only by model file size. Measure cold-start time, sustained latency, peak memory, power use, and thermal throttling. Smooth performance in a short test does not necessarily represent stability during continuous task processing.
4. Long-Context Management: Capacity Is Not Reliable Use
A context window describes how much input a model can receive at once. It is not a direct guarantee of effective understanding. The key question in long-text tasks is whether the model can find relevant evidence, retain constraints, and cite that information correctly when generating a result.
As context grows, the system is more easily distracted by repeated content, outdated versions, and irrelevant detail. Putting all history into the input can raise cost without improving task completion.
4.1 Separate Source Material from Task State
Source material can stay in external storage. The current context should mainly keep the goal, key constraints, completed steps, and necessary evidence.
This separation limits dialogue-history growth and makes recovery after interruption easier. The system does not need the model to reread every historical message to understand progress; it can continue from structured state.
4.2 Keep Source and Version Information with Evidence
Long-text summaries should retain, as far as possible, the source location, version, and conditions attached to a conclusion. Otherwise a summary may compress “true under specific conditions” into “generally true,” and later decisions lose their boundaries.
When sources conflict, do not force them into a single conclusion. Record the conflict and what still needs to be checked.
4.3 Test Effective Context with Targeted Tasks
Evaluation should cover cases where a key constraint sits in the middle of a document, multiple versions coexist, reasoning spans passages, and a high share of the input is irrelevant. The point is not whether the model can find one isolated fact, but whether it can keep using the correct evidence through a complete task.
5. Sub-Agent Orchestration: Clear Responsibilities Matter More Than More Agents
Sub-agents can take on retrieval, solution design, code changes, and result review. A sensible split can improve parallelism and make responsibilities clearer, but more agents also add communication cost, conflicting conclusions, and state-synchronization problems.
5.1 Define Inputs, Outputs, and Responsibility Boundaries
Each subtask should have a clear goal, allowed resources, and a delivery standard. A verification sub-agent, for example, should return check results and evidence, not modify production state directly.
Splitting too finely can make coordination cost more than it returns. Splitting too coarsely makes failures hard to locate. A useful unit usually has its own inputs, a clear artifact, and a verifiable completion condition.
5.2 Use a Shared State Record
Sub-agents should not report progress to one another only in free text. The system needs a shared task state: current stage, dependencies, confirmed facts, open issues, and remaining budget.
When sub-agents contradict each other, resolve the conflict with evidence and verification results rather than simply taking the majority view.
5.3 Isolate Execution Privileges
Analytical ability is not operational permission. A sub-agent may propose a change, but writes, deletions, and submissions should pass through a unified execution layer. That reduces the risk of duplicate actions or unauthorized changes during parallel execution.
6. Long-Running Tasks: Recoverability Determines Whether the System Can Deliver
Long-running tasks may span multiple stages and depend on external services, human feedback, or asynchronous jobs. Reliability cannot rest on one continuous generation. It needs an explicit state machine, checkpoints, and recovery.
A practical execution flow can be represented as:
Task intake → goal confirmation → plan generation → authorization check → stepwise execution → result verification → delivery
After a failure, the system should not restart unconditionally. Depending on the failure type, it should retry, replan, request missing information, or hand control to a person.
6.1 Define Measurable Progress
“No progress” may mean repeated tool calls, repeated edits to the same content, or continued plan generation without an artifact.
Judge progress by actual state change: new valid evidence, a test that passed, or a backlog step completed—not by reply length.
6.2 Prevent Retries from Repeating Side Effects
Writes and submissions should consider idempotency control. When the outcome is unclear, check the target state before retrying, so the system does not create duplicate records or trigger the same business action twice.
For actions that are hard to undo, prepare a compensation plan or a human handling path in advance.
6.3 Give Human Takeover the Information It Needs
A human takeover should not receive only “execution failed.” The system should provide the task goal, steps already run, the failure reason, relevant evidence, and a suggested next step, so a person can judge quickly instead of reconstructing the full history.
7. Coding and Multimodal Ability: Check Generated Results with External Evidence
The quality of a coding task cannot be judged from generated text alone. A more reliable flow is to confirm the requirement and the scope of change, generate a candidate change, then run static checks, tests, and diff review.
A passing test is not an absolute guarantee. Coverage may be insufficient, or the tests may not match real business conditions. Boundary inputs, compatibility, error handling, and access to sensitive information still need review.
Multimodal tasks also need to separate understanding from generation. Reading text in an image or explaining a chart trend is a different capability from producing visual content that meets a specification. Performance on one does not imply performance on the other.
In practice, the system can first produce structured observations—visible text, layout relationships, key values, and uncertain regions—and then analyze from those observations. For blurry screenshots, occluded content, or charts missing units, uncertainty should be stated explicitly so that inference is not treated as fact.
8. Cost and Safety: Put Constraints at the Workflow Level
The cost of a complex agent comes from inputs, outputs, tool calls, verification, retries, and state storage together. A low price per call does not mean a low total cost to finish the task.
A more meaningful metric is cost per accepted task:
Cost per accepted task = total related cost in the measurement period ÷ number of tasks that pass acceptance
Success rate, retry ratio, tail latency, and human-takeover rate should be watched at the same time. Only together do these metrics show whether the system is actually fit for business use.
8.1 Set Budgets at Several Levels
Budgets should cover a single step, the whole task, and concurrent resources. When a limit is reached, the system can reduce processing complexity, ask the user to narrow the scope, or move to a human process, rather than continuing to consume resources without a bound.
Caching, targeted retrieval, and structured state compression can reduce repeated input, but stale results must be avoided, as must incorrectly sharing data across users with different permissions.
8.2 Separate Content Safety from Operational Safety
Content filtering addresses only part of the risk. Task execution also needs identity checks, least privilege, parameter validation, operation audit, and confirmation for high-risk actions.
External documents, web content, and tool return values should be treated as data, not as instructions that automatically gain authority. Even if that text asks the system to change its rules or export material, it must not bypass the existing authorization boundary.
9. Rollout: From an Evaluation Loop to Continuous Improvement
Complex agents are better validated first in read-only scenarios, then gradually given controlled write capability. Before launch, build an evaluation set that covers real tasks, including normal inputs, boundary conditions, permission conflicts, tool failures, and mid-task recovery.
Evaluation should record not only success and failure, but where the failure occurred: goal understanding, plan decomposition, retrieval, tool parameters, state recovery, or result verification. Otherwise a change in the overall score is hard to turn into an actionable improvement.
During a gradual rollout, monitor quality and operational risk together, and keep degradation and rollback paths ready. When failure rate, cost, or abnormal operations rise sharply, the system should be able to narrow its capability scope promptly rather than relying on the model to correct itself.
For large models aimed at complex agents, the lasting advantage is not only a longer context or more reasoning steps. It is the ability to complete acceptable tasks reliably under explicit permissions, a finite budget, and real business constraints. For developers, an engineering loop of evidence, state, verification, and recovery does more to determine practical value than chasing model specifications alone.
