AI Agent Development in Practice: From Architecture to Prompt Engineering
This article walks through the practical side of building AI agents, covering what distinguishes an agent from a simple chat interface, the main agent types and core modules, proven design patterns such as ReAct and Plan-and-Execute, the common pattern for connecting large models and tool calls, two development paths, prompt engineering frameworks, and the engineering pitfalls that decide whether an agent survives in production.
1. What an AI Agent Really Is, and Where the Boundaries Lie
An AI Agent is not a chat interface. It is an autonomous system with a large model as its cognitive core, tool calling as its ability to act, and memory plus planning as its continuity. Compared with the traditional input-output question-answering model, the key difference is a goal-oriented loop: perceive the environment, build a plan, execute actions, observe results, and revise the strategy.
1.1 Types of Agents
By level of autonomy, agents are usually divided into three categories:
- Reactive: no internal state; maps the current input directly to an action. Low latency, but weak at long-horizon tasks.
- Deliberative: explicitly maintains a world model and task state. Strong at complex planning, but expensive to reason over.
- Hybrid: layered design, with slow planning on the upper layer and fast execution on the lower layer. This is the mainstream choice in real engineering work.
By capability, agents can also be single-modal task agents, multi-modal perception agents, or multi-agent collaborative systems. A multi-agent architecture improves robustness on complex tasks through role separation (planner, executor, reviewer), but it also introduces communication overhead and consistency problems.
1.2 Core Modules
A working agent contains at least five modules:
- Reasoning engine: intent understanding, task decomposition, and decision making.
- Memory system: a short-term context window plus long-term vectorized storage.
- Tool layer: function calls, retrieval, code execution, and integration with external systems.
- Planner: turns a vague goal into a verifiable sequence of subtasks.
- Interaction layer: exchanges structured information with the user or external systems.
1.3 Common Design Patterns
Patterns that repeatedly prove effective in practice include ReAct (alternating reasoning and acting), Plan-and-Execute (plan first, then execute), Reflection (self-review and retry), and Router (route intent to different processing chains). The core criteria for choosing a pattern are how decomposable the task is and how costly an error is: high-error-cost scenarios need review and rollback, while latency-sensitive scenarios should compress the number of reasoning rounds.
2. A Common Pattern for Connecting Large Model Capabilities
Whatever model service you choose, the integration is conceptually the same: submit a chat request over HTTP carrying the model identifier, the message list, sampling parameters, and tool definitions; the server returns either text or a structured tool-call intent.
# Illustrative code: general LLM chat and tool-calling flowresp = client.chat(model="<model identifier>",messages=[{"role": "system", "content": "You are a rigorous technical assistant"},{"role": "user", "content": "Check the status of order ORD-1024"}],tools=[{"type": "function","function": {"name": "query_order","description": "Look up the shipping status of an order by order ID","parameters": {"type": "object","properties": {"order_id": {"type": "string"}},"required": ["order_id"]}}}],temperature=0.2)
The important point: function calling does not mean the model actually executed code. The model outputs a structured call intent; the host program parses it, executes it, and feeds the result back as a new message, closing the loop. Only by understanding this can you handle timeouts, exceptions, and retries correctly.
On the cloud, this is usually combined with object storage (for documents and artifacts), a message queue (for peak shaving and asynchronous tasks), a container platform (to host the execution sandbox), and logging plus monitoring and alerting (to trace the chain and the cost). General-purpose cloud product categories from providers such as Baidu AI Cloud can serve as the infrastructure underneath this stack.
3. Two Paths for the Development Environment
Path 1: an online low-code platform. Major cloud providers and large platforms generally offer visual agent orchestration. The advantages are zero operations and fast validation, and it lets business people take part. The limitation is constrained deep customization and version governance.
Path 2: local, code-based development. Build with an open-source orchestration framework plus a model API. This gives the most control. The base environment usually includes a runtime (a recent Python version), dependency and virtual environment management, local injection of secrets (never hardcode them), and observability components.
Recommended order to start: validate whether the requirement is real on a low-code platform first, then migrate the stable chain to a code implementation, so you avoid getting stuck in framework details too early.
4. Prompt Engineering: The Real Lever for Agents
4.1 Role, Task, and Constraints
A high-quality prompt states three things clearly: the role (the professional perspective to answer from), the task (a verifiable deliverable), and the constraints (format, length, prohibited actions). Without constraints, output stability drops noticeably.
4.2 Comparing the Main Frameworks
- ICIO: Instruction-Instruction Context-Output. The simplest structure, good for a quick start.
- CRISPE: emphasizes experimentation and iteration on top of role and style; suited to creative tasks.
- BROKE: adds goal decomposition and continuous optimization; suited to long chains.
- CO-STAR: Context-Objective-Style-Tone-Audience-Response; aimed at enterprise-grade standardized output.
The value of a framework is not the name but that it forces developers to make implicit assumptions explicit.
4.3 Structured Output and Validation
Production systems should not rely on parsing natural language. A workable approach is to require the model to return strict JSON and to validate against a schema on the host side, retrying on failure:
{"action": "query_order", "params": {"order_id": "ORD-1024"}, "confidence": 0.86}
5. Implementation Essentials and Common Pitfalls
- Context budget: cap historical messages, retrieved fragments, and tool results, and compress them with summaries.
- Idempotency and rollback: tool calls must be re-entrant, and write operations need a second confirmation.
- Least privilege: separate the execution sandbox from credentials, and grant the minimum permission per task.
- Evaluation first: build a regression set that includes boundary samples, and measure iterations by pass rate rather than subjective feeling.
- Cost control: split work between large and small models, cache frequent requests, and set limits on rounds and tokens.
An agent’s competitiveness ultimately does not depend on stacking up model parameters; it depends on the quality of the engineering constraints you design. Confining uncertainty inside a cage that is observable, rollback-able, and testable is the key step from demo to production.
