AI Agent Development in Practice: From Architecture to Production
This article breaks down the engineering practices required to build AI agents that perform actions rather than just generate text. It presents a four-layer reference architecture covering perception, planning, tool invocation, and memory, then explains how to design for controllability through least-privilege access, sandboxed execution, risk labels, and audit logs. It also outlines an observability and evaluation loop based on decision traces and a three-tier testing structure, and closes with common pitfalls and a pragmatic path to production. The discussion on compute portability is kept vendor-neutral and focused on architecture-level design choices.
1. From Chatting to Acting: The Technical Divide for Agents
One of the most discussed directions in the industry right now is the AI agent: a system that can write code, access the network, and operate application interfaces. This is fundamentally different from earlier conversational models. A chat system outputs text; an agent outputs a sequence of actions. That difference creates a new engineering problem: how to make a component driven by a probabilistic model complete tasks in a real environment in a way that is stable, reproducible, and rollback-capable.
Traditional software follows deterministic logic: the same input always produces the same output. Agents work the opposite way. Their decisions depend on sampling and are inherently non-deterministic. So the engineering focus is no longer writing longer prompts. It is constraining uncertainty within acceptable boundaries, which requires building a full set of guardrails around the model.
2. A Four-Layer Reference Architecture for Agents
A deployable agent can usually be abstracted into four layers.
The perception layer converts environment state into context the model can understand: user instructions, interface structure, file contents, API responses. The most common mistake here is dumping raw data into the context in full, which lets noise drown out the information that matters. A better approach is structured extraction first. For example, describe a UI as a node tree with semantic labels and keep only the branches relevant to the current subgoal.
The planning layer handles task decomposition. The common pattern in the industry is a loop of plan, execute, then reflect: break a large goal into subtasks, run them one by one, and revise the remaining plan based on execution results. Illustrative pseudocode:
plan = planner.decompose(goal) # goal -> list of subtasksfor step in plan:observation = env.observe() # get current environment stateaction = policy.decide(step, observation, memory)result = executor.run(action) # sandboxed executionmemory.write(step, result)if verifier.reject(result):plan = planner.replan(goal, plan, result) # replan on failure
The critical piece is verifier. Without verification, an agent turns a single failure into a collapse of the entire chain.
The tool invocation layer defines the boundary of capability. The practical recommendation is to describe tools as an interface inventory with type signatures and side-effect notes, clearly separating read-only operations from write operations. Write operations should include a second confirmation step or a human approval node. Irreversible operations must have a corresponding compensating action.
The memory layer splits into working memory and long-term memory. Working memory holds intermediate conclusions for the current task. Long-term memory is typically implemented with vector retrieval, recalling past experience by similarity. One thing to watch: retrieved results must carry their source and a timestamp, otherwise the model easily treats stale information as current fact.
3. Controllability Design: Sandboxes, Permissions, and Least Privilege
Since an agent has to “control applications,” it has to answer the permissions question. The workable principle is least privilege: deny by default, request on demand, revoke when done. The execution environment should sit in an isolated container with a restricted filesystem write scope, limited network egress, and a constrained set of available system calls, plus caps on resource consumption to avoid infinite loops.
A practical technique is to attach a risk label to every action and let the policy layer adjudicate centrally:
| Risk level | Typical actions | Handling strategy |
|---|---|---|
| Low | Queries, reads, retrieval | Execute directly and log |
| Medium | Writing drafts, changing configuration items | Execute, then alert; support undo |
| High | Deleting data, publishing externally, payments | Execute only after human confirmation |
At the same time, every action should be written to an audit log, forming a complete chain of who did what, when, based on which context, and with what result. This is both the basis for troubleshooting and the foundation for compliance.
4. Observability and the Evaluation Loop
Debugging an agent system is far harder than debugging an ordinary service, because the same input can produce different trajectories. So observability has to capture more than latency and error rates. It also has to capture the decision trace: the input context at each step, the candidate actions, the reason for the choice, and the execution result. Only with traces can you attribute failures.
Evaluation is best structured in three tiers. First, tool-level unit tests that verify correct API calls and exception handling. Second, a task-level offline evaluation set that measures completion rate and average step count against fixed cases. Third, a production canary release that observes behavior under real traffic distribution with a small share of users. Beyond success rate, the metrics should also cover average interaction turns, human takeover rate, and cost per task. These three directly determine whether the product can scale.
5. The Compute Foundation: Why Training-Chip Portability Matters
An agent’s capability ceiling is set by the underlying model, and model training depends heavily on compute supply. In recent years, the share of models trained on domestically produced chips in China has kept rising. The significance shows up on three levels. On supply continuity, a diverse compute base reduces the risk of relying on a single source. On cost structure, once the hardware and its supporting software stack mature, unit training cost has room to fall. On ecosystem coordination, joint optimization across chips, compiler frameworks, and operator libraries can deliver better real throughput for the same model.
The practical takeaway for developers is to factor compute portability into architecture design from the start. Avoid deep coupling to a proprietary set of operators or a private format, and prefer open model formats and general parallel strategies, so that switching the underlying stack keeps migration cost manageable.
6. Common Pitfalls and Recommendations for Production
The first pitfall is over-pursuing autonomy. Most production scenarios do not need full autonomy, and handing key nodes to a human for confirmation actually raises overall reliability. The second is neglecting context governance: treating retrieval as a cure-all and pulling in large amounts of irrelevant fragments. The third is building the interface before building evaluation, which leaves you unable to tell whether a change is an improvement or a regression.
The pragmatic path forward is to pick one scenario with clear boundaries that is verifiable and cheap to fail, close the loop there, and make the tool interfaces, sandbox, logs, and evaluation set solid first, then gradually expand the action space. An agent is not a one-off model upgrade. It is a continuously evolving piece of infrastructure engineering.
