AI Agent Architecture: From Q&A to Execution in Practice
This article explains how AI agents evolve from answering questions to executing real tasks, and how to build them reliably. It covers a five-layer reference architecture, structured intent contracts, voice interaction compliance, hallucination control with retrieval-augmented generation, content repurposing pipelines, note and knowledge management, and engineering governance for observability, cost, security, and safe rollout. Readers will find practical design principles for keeping side effects under confirmation and idempotency controls while grounding factual answers in citable sources.
1. Requirements Have Changed: From “Tell Me How” to “Do It for Me”
Traditional information tools follow an interaction pattern of “ask a question, get a list of candidate links, filter them manually, and execute the task yourself.” This flow leaves the most time-consuming judgment and operational cost with the user. The goal of a new generation of intelligent services is to compress the flow into “express intent, confirm key parameters, complete the call, and return a result,” leaving only the final confirmation and payment actions to the user.
It is worth emphasizing that capabilities such as “order coffee with one sentence” or “book a trip with one sentence” are not fundamentally about language models becoming smarter. Rather, the model has been connected to an external world that can be invoked. The language model maps natural language to structured intent, while the execution layer maps structured intent to real side effects. Missing either one degrades the system into something that “seems to understand you but cannot get things done.”
2. Capability Layers: A Practical Reference Architecture for Agents
It is advisable to split the system into five layers that communicate through explicit contracts, avoiding the temptation to cram all logic into prompts.
- Interaction layer: a unified entry point for text, voice, and multimodal input, responsible for session state and timeout control.
- Cognition layer: intent recognition, slot extraction, and context rewriting (completing “what about tomorrow” into a full semantic expression).
- Planning layer: task decomposition and tool selection, deciding call order, concurrency, and rollback strategy.
- Execution layer: tool registry, authentication, rate limiting, idempotency, and retries, connecting to capabilities such as orders, payments, calendars, and navigation.
- Governance layer: logging, monitoring and alerting, auditing, cost tracking, and a channel for human takeover.
The key design principle is “externalize side effects and confirm before acting.” Any action involving money, privacy, or irreversible state must go through explicit secondary confirmation and be initiated by the execution layer rather than directly by the model.
3. From Intent to Invocation: Structured Contracts Are the Foundation of Stability
Do not let the model freely generate the final request body. Instead, have it output a constrained intermediate representation that deterministic code then validates and assembles.
{"intent": "book_flight","slots": {"origin": "BJS","destination": "SHA","date": "2026-09-12","passenger": 1},"constraints": ["non_stop", "max_price_cny=1500"],"need_confirm": true}
Engineering essentials:
- Constrain output with JSON Schema or an equivalent mechanism; on validation failure, fall back to clarification rather than guessing.
- When slots are missing, ask follow-up questions first; do not mask uncertainty with default values.
- Declare preconditions, timeouts, and idempotency keys for each tool; retries must carry the same idempotency key.
- Deploy high-risk and low-risk tools in separate domains, with automatic execution disabled by default in the high-risk domain.
4. Voice Interaction: Human-Like Does Not Mean Hiding Identity
A voice pipeline typically consists of four stages: speech recognition, semantic understanding, dialogue management, and speech synthesis. End-to-end latency is mainly determined by first-packet synthesis time and network jitter. In engineering, streaming recognition, sentence-level synthesis, silence detection, and interruption handling can bring perceived latency into an acceptable range.
Compliance boundaries must be clear: when making proactive outbound calls, the service should be identifiable as automated. Recording, identity verification, and retention of call content require authorization and must follow the principle of minimum necessity. Treating “the other party cannot tell” as a product goal is neither compliant nor sustainable. The correct goal is “smooth communication, accurate information, and disclosable identity.”
5. Hallucination Control: Search Augmentation and Knowledge Base Constraints
General-purpose generative models fabricate entities, dates, and numbers on factual questions. Factual queries should therefore follow a “retrieve, rerank, cite, generate” pipeline:
- Query rewriting: resolve references, split compound questions, and generate multiple recall terms.
- Hybrid recall: run keyword retrieval and vector retrieval in parallel to balance exact matching and semantic similarity.
- Reranking and deduplication: order results by authority, timeliness, and source credibility.
- Constrained generation: allow answers only based on retrieved snippets, annotate sources sentence by sentence, and output “not found” when there is no basis.
- Evaluation loop: use a fixed question set to measure citation accuracy and unsupported rate, and keep running regression checks.
If an organization already has internal material, it can be chunked and indexed into a private knowledge base, giving answers traceable first-hand evidence. This reduces error rates more effectively than simply scaling up the model.
6. Content Repurposing: Turning One Document into Multiple Outputs
Converting a long document into a mind map, brief, script, quiz cards, or slides is technically a “parse, structure, render from template” pipeline:
def render_outputs(doc, templates):outline = structure(doc) # heading hierarchy, key concepts, logical relationsfacts = extract_claims(outline) # extract verifiable facts and bind them to source locationsreturn {name: tpl.render(outline, facts) for name, tpl in templates.items()}
The key is to decouple “fact extraction” from “style rendering”: the fact layer ensures nothing is distorted, while the template layer handles length, tone, and layout. When exporting images or slides, hand the work to a deterministic rendering engine; do not let the model produce binary content directly.
7. Notes and Knowledge Management: Making Context Reusable
The value of meeting notes, lecture handouts, and interview transcripts lies in being reused repeatedly. A workable approach is to standardize them into “atomic notes plus bidirectional links plus a tagging system,” then aggregate them semantically through a retrieval layer. On write, automatically extract people, conclusions, to-dos, and dates into queryable structured fields; on read, inject context on demand, avoiding stuffing in overly long text all at once, which amplifies noise and raises costs.
8. Engineering Governance and Selection Advice
- Observability: record trace IDs, latency, success rate, and token consumption for every tool call, and configure threshold-based alerts.
- Cost control: route across model tiers, sending simple intents to small models and complex planning to large models; cache high-frequency queries.
- Security: apply least privilege on the tool side, use key management, filter both input and output, and guard against prompt injection and unauthorized calls.
- Gradual rollout and takeover: run new tools in shadow mode first, and automatically degrade to a human agent on anomalies.
- Cloud support: container platforms can host elastic scaling of the execution layer, message queues can decouple asynchronous tasks, object storage can hold raw material, and logging and monitoring services can handle auditing and inspection. Baidu AI Cloud can serve as a foundation for such general capabilities; refer to the official documentation for specific specifications.
9. Conclusion
The dividing line between answering questions and getting things done lies not in model parameters but in “controllable execution.” Structure intent, cage side effects behind confirmation and idempotency, and hand facts to citable first-hand material. Only then does an agent deserve to be called a “digital twin.”
