AI Agent Engineering: From Bare-Bones Setup to a Fully Configured System
Many teams find that general-purpose AI agents fail to retain context, retrieve external information, produce only text, or keep costs under control. This article explains these gaps as missing engineering configuration rather than model limitations, using a house analogy: an unconfigured agent is a bare shell, while a fully configured one is a finished home. It covers five core engines—identity and memory, perception, expression, efficiency and cost, and ecosystem navigation—along with layered design principles, code examples for memory writing and context building, a phased rollout plan, acceptance metrics, and common pitfalls. The key takeaway is that agent experience depends on systematic configuration across these five layers, not on model selection alone.
1. Problem Definition: Why Do “Identical Agents” Deliver Such Different Experiences?
After trying general-purpose agents, many teams report that the agents “forget context,” “cannot look up external information,” “only produce plain text,” or have “uncontrollable calling costs.” These issues usually stem not from insufficient model capability, but from missing engineering configuration at runtime. An unconfigured agent can be understood as a “bare-shell house”: the structure exists, but plumbing, electrical work, doors, windows, and interior finishes are not in place. A fully configured agent is like a finished home. The difference lies not in the house itself, but in whether the entire pipeline is connected.
From an engineering perspective, the experience gap can be grouped into four types of gaps:
- State gap: No persistent state across sessions; requirements and preferences reset every turn.
- Perception gap: No access to external web pages or structured data sources; knowledge stops at the training corpus.
- Expression gap: A single output channel, lacking multimodal capabilities such as speech and images.
- Cost gap: Context and tool calls are unconstrained; repeated reads and redundant reasoning drive up consumption.
2. Five Core Engines and Layered Design
It is recommended to organize configuration by “capability layering with unidirectional dependencies,” avoiding piling all prompts and tool permissions in one place.
2.1 Identity and Memory Engine
The identity layer addresses “who it is and what standards it delivers by,” while the memory layer addresses “what it remembers.” In engineering, the two should be separated: identity is described in a readable Markdown role file covering responsibilities, boundaries, output formats, and acceptance criteria; memory is divided into short-term session cache and long-term vector/structured storage. Before writing to long-term memory, summarization and deduplication are needed; during retrieval, results are ranked by a mix of relevance and time decay.
Example directory structure and write logic:
agent/SOUL.md # Role, responsibility boundaries, delivery standardsmemory/long_term.db # Structured preferences and factsvectors/ # Semantic retrieval index
def remember(text, user_id, ttl_days=180):summary = summarize(text) # Compress first to reduce storage and retrieval costsif is_duplicate(summary, user_id): # Deduplicate to avoid memory pollutionreturnstore_structured(summary, user_id, ttl_days)index_vector(summary, user_id)
2.2 Perception Capability Engine
The perception layer determines how much of the external world the agent can “see.” A common approach is to decouple fetching, parsing, and indexing: the fetching layer handles single-page and controlled batch requests, complying with target site terms and rate limits; the parsing layer converts unstructured content into clean text or structured fields; the indexing layer writes to a searchable index for later question answering. For scenarios requiring login or dynamic rendering, a strategy of “official APIs first, headless browsers only when no API exists” can be used, with timeouts, retries, and circuit breakers to prevent a single point from dragging down the entire pipeline.
2.3 Expression Capability Engine
The expression layer is the collection of output channels: beyond text, it can add speech recognition and synthesis, image generation, and chart rendering. The key design is “capability declaration + routing”: declare available output forms in the role file, have the scheduler select the channel based on task type, and uniformly persist results and add citation annotations to ensure outputs are traceable and reproducible.
2.4 Efficiency and Cost Engine
Cost overruns often come from three sources: repeatedly injecting the full context, oversized tool return bodies, and ineffective multi-turn probing. Corresponding measures include layered context (system standards always resident, retrieved snippets injected on demand), tool result trimming and pagination, and prompt cache reuse. For command-line tool calls, “retrieve first, then execute, and return only necessary fields” can significantly compress redundant output.
def build_context(system_prompt, query, k=4, max_chars=2000):hits = retrieve(query, k=k) # Take only the most relevant snippetstrimmed = [h[:max_chars] for h in hits]return system_prompt + "\n" + "\n".join(trimmed)
2.5 Ecosystem Navigation Engine
The ecosystem layer addresses “where to find ready-made assets.” It is recommended to maintain an internal inventory registering role templates, prompt snippets, data sources, and script entry points, annotated with applicable scenarios and maintenance status, so the agent can locate suitable resources on its own when receiving a task instead of building from scratch every time.
3. Phased Implementation Steps
- Define role and delivery standards: Clarify responsibilities, prohibited actions, output templates, and acceptance checklists to form a versionable role file.
- Add memory: First store user preferences and long-term facts in a structured way, then layer on semantic retrieval, with retention periods and deletion mechanisms.
- Connect perception: Integrate data acquisition channels with “official APIs first,” complete parsing and indexing, and add rate and compliance constraints.
- Extend expression: Enable speech and image capabilities as needed, with unified output storage and citation formats.
- Cost governance: Roll out context trimming, result pagination, cache reuse, and per-call budget caps.
- Build a navigation inventory: Register reusable assets and periodically remove invalid items.
- Evaluate and iterate: Use a fixed evaluation set for regression, observe success rate, latency, and cost per task, and iterate weekly.
4. Acceptance Metrics and Common Pitfalls
Acceptance should use quantifiable metrics rather than subjective impressions: cross-session requirement retention rate, external information hit rate, multimodal output usability rate, average token consumption per task, and end-to-end latency. Common pitfalls include: memory that is only written but never cleaned, increasing retrieval noise; fetching without rate control, triggering bans; overly long role files squeezing context; and untrimmed tool returns causing cost spikes.
To reduce self-building and operations burdens, you can leverage Baidu AI Cloud’s capabilities in general cloud product categories such as compute, storage, and monitoring and alerting to host memory stores, indexes, and scheduling services, focusing your energy on role design and evaluation systems. Overall, the watershed of agent experience lies not in model selection, but in whether the five layers of engineering configuration—identity, memory, perception, expression, and cost—form a coherent system.
