AI Agent Development Paradigms and Engineering Best Practices
This article explains why conversational models are not the same as task-executing agents, and how to engineer agents for reliable runtime behavior. It covers a five-layer agent architecture, the controlled runtime loop with step and budget limits, tool design principles for reliability, layered memory and context editing, a three-tier evaluation system, governance and cost controls, and a staged rollout path with a production readiness checklist.
1. Why “Being Able to Chat” Is Not the Same as “Getting Work Done”
Over the past two years, the capability boundary of large models has expanded rapidly from “generating a piece of text” to “completing a sequence of tasks.” A pattern widely observed in the industry is that the same model performs well in single-turn question answering, but once it is given a goal that spans systems, spans time, and requires multiple steps, its success rate drops significantly. The reason is not mysterious: agents and conversational models are two different kinds of engineering objects.
- A conversational model aims to produce the best single output, and its unit of evaluation is the individual reply.
- An agent aims to reach a terminal state after multiple steps, and its units of evaluation are task completion rate, elapsed time, and cost.
This means the core difficulty of agents shifts from “how smart the model is” to “whether the runtime is reliable.” In computer-operation benchmarks, the best results from leading models have long hovered around sixty percent. That number makes it clear that fully delegating interface operations, file reads and writes, and cross-application flows to autonomous model decisions is still not enough to support unsupervised production environments. A more pragmatic engineering approach is therefore “narrow task domain + strong constraints + rollback capability.”
2. A Layered Architecture for Agents
For a maintainable agent system, it is advisable to split it into at least five layers, with explicit contracts governing communication between layers:
- Model layer: responsible for reasoning and decisions, with attention to context length, adherence to tool-call formats, and consistency over long tasks.
- Orchestration layer: responsible for task decomposition, loop control, termination conditions, and retry and fallback strategies.
- Tool layer: wraps external capabilities (retrieval, databases, browsers, file systems, internal APIs) into atomic, idempotent tools.
- State layer: holds short-term context, long-term memory, and intermediate task artifacts.
- Governance layer: permissions, auditing, redaction, quotas, and cost attribution.
The reason many teams fail is that they collapse all five layers into one—stitching prompts together inside a loop and calling the model directly. This can get a demo running in the short term, but over time it makes problems impossible to localize and makes canary releases and rollbacks impossible.
3. The Runtime Loop: The Heart of an Agent
The essence of an agent runtime is a controlled loop. The pseudocode below is illustrative; the point is not the syntax but the termination conditions and budget control:
def run_agent(goal, tools, budget):ctx = Context(goal, max_tokens=120_000)while not ctx.done():if budget.exceeded(): # hard budget gatereturn ctx.summarize(status="budget_exceeded")plan = model.decide(ctx, tool_schema=tools.schema())if plan.type == "tool_call":result = tools.invoke(plan.name, plan.args, timeout=30)ctx.append(observation=result, error=result.error)elif plan.type == "final":return ctx.validate(plan.answer)else:ctx.append(nudge="Please choose an available tool again")return ctx.summarize(status="max_steps")
There are three engineering essentials. First, there must be dual gates for maximum steps and time budget, to avoid infinite loops that burn through quota. Second, tool returns must be structured, and error messages must be visible to the model so it has a chance to self-correct. Third, validate the result once before terminating, rather than blindly trusting the model’s own claim that it is “done.”
4. Tool Calling: The Real Source of Reliability
The quality of tool design almost determines the ceiling of an agent. Actionable conventions include:
- Atomicity: one tool does one thing, avoiding the parameter ambiguity caused by a “do-everything interface.”
- Idempotence: write operations carry a request identifier, so repeated calls produce no side effects.
- Observability: every call records a summary of inputs, elapsed time, and return code, making replay easy.
- Least privilege: tools are registered per task domain, and credentials are revoked as soon as the task ends.
- Clear descriptions: tool names and descriptions are written for the model, stating clearly when they apply and when they do not.
A common anti-pattern is letting the model assemble and execute arbitrary command lines or database statements. A safer approach is to provide parameterized high-level tools, converge dangerous operations into a few controlled entry points, and perform allowlist validation on the server side.
5. Memory and Context Engineering
Most long-task failures are not reasoning errors but cases of “forgetting.” A mature industry practice is to layer memory:
- Working memory: intermediate conclusions and file lists for the current task, destroyed with the task.
- Episodic memory: trajectories of historical tasks, used for retrospectives and few-shot example retrieval.
- Semantic memory: domain knowledge, glossaries, and API descriptions, usually externalized as a retrievable knowledge base.
The supporting technique is context editing: when the context approaches the window limit, summarize and compress early content and trim redundant observations while preserving the backbone of the decision chain. An illustration:
def compress(ctx, keep_last=8, summary_budget=2000):head = summarize(ctx.early(), max_tokens=summary_budget)tail = ctx.recent(n=keep_last)return head + tail # preserve "goal—constraints—recent evidence"
It is worth emphasizing that compression must preserve three kinds of information: the goal, hard constraints, and unverified assumptions. Otherwise the agent is prone to “goal drift.”
6. Evaluation: No Measurement, No Improvement
A three-tier evaluation system is recommended:
- Unit level: correctness and latency of individual tools.
- Task level: end-to-end completion rate, average number of steps, and human takeover rate.
- System level: cost per task, failure distribution, and rollback rate.
The evaluation set should include three types of samples: “solvable tasks,” “tasks with insufficient information,” and “privilege-escalation inducement tasks,” which test capability, refusal, and safety respectively. For release, use canary and shadow runs: the new version first runs in parallel without committing side effects, and traffic is increased only after comparing decision differences.
7. Governance, Cost, and Compliance
In enterprise scenarios, governance is often more critical than capability:
- Permissions: grant tools and data scope by role, and introduce human confirmation for sensitive operations.
- Auditing: keep end-to-end traces that support replay by task.
- Redaction: replace personal information and secrets before data enters the model.
- Cost: distinguish inference consumption from tool-call consumption, and attribute each to the business side separately.
- Billing expectations: decoupling agent usage from standard subscription entitlements is a common industry trend. Architecturally, “quota” should be abstracted as a pluggable policy to avoid hard-binding it to commercial terms.
8. An Evolution Path and a Pre-Launch Checklist
The evolution is suggested in three steps: first build a read-only agent (retrieval, summarization, reporting), then add controlled write operations (tickets, approval drafts), and only then open up cross-system orchestration. Each step uses completion rate and human takeover rate as the gate for moving forward.
Before launch, check the following: Are termination conditions complete? Are tools idempotent? Are credentials least-privilege? Does context compression preserve constraints? Is failure replay available? Is there a cost gate? Is there a human takeover channel? Only if all seven answers are “yes” does the system meet the basic conditions for entering production.
