Understanding Self-Evolving Agent Architectures: From Stateless Inference to Stateful Engineering
This article breaks down the architecture of self-evolving AI agents and explains why mainstream conversational agents fail at long-running engineering tasks. It covers three core engineering paths—closed-loop learning that turns completed tasks into reusable, parameterized skill files, layered persistent memory for cross-session continuity, and architecture decoupling into reasoning, memory, skill, and sandbox layers. It also details automated prompt and skill optimization with a human review gate, key risks such as skill drift and permission creep, and quantifiable acceptance metrics for evaluating whether an agent truly improves with use.
1. The Root Problem: Stateless Inference vs. Stateful Tasks
A single LLM inference call is essentially a pure function: the same input yields the same output, and nothing is left behind once the call ends. Real engineering work is the opposite—stateful, long-running, and dependent on accumulated context. The deployment script you refined in the last session, the directory conventions you just confirmed, the permission pitfalls you already stepped into—all of it evaporates the moment the window closes, forcing the user to explain the background all over again. This is not a capability gap in any particular model; it is a structural trait of today’s mainstream conversational agents. The system is built as a stateless calculator, and state management is pushed onto the user.
Three progressive questions can measure whether an agent is genuinely usable:
- Memory continuity: across sessions and devices, does it still remember your preferences and project conventions?
- Experience reuse: when a problem has been solved once, does the second attempt take fewer wrong turns?
- Behavioral controllability: is the self-adjustment process auditable and rollback-capable?
Engineering usually advances along three paths at once: closed-loop learning, layered persistent memory, and architecture decoupling. Each is covered below.
2. Closed-Loop Learning: Turning One-Off Tasks into Reusable Assets
The execution chain of a traditional agent is linear: receive instruction → plan steps → call tools → return result. The task ends and experience resets to zero. A practical改造 is to add a feedback loop at the end of the chain: once a task is judged successful, trigger an experience extraction that compresses what just happened into a structured skill description file, ready to be loaded directly for similar tasks later.
A minimal viable skill file usually has three parts: trigger conditions, execution steps, and caveats.
---name: container-service-deploytriggers: ["deploy container service", "release new image version"]variables: [image_name, tag, replicas]---1. Validate that all variables are present; ask the user if any are missing2. Build and push the image ${image_name}:${tag}3. Update the orchestration config and set replicas to ${replicas}4. Run a rolling update and watch the readiness probesNote: keep the previous version before any production change so you can roll back
Two easily overlooked design points matter here.
First, skills must be parameterized, not log-style. A log records “what I did this time”; a skill describes “how this kind of task should be done.” The former only supports retrospection; only the latter is reusable. Externalizing the variable parts with placeholders lets the same skill adapt to different projects and environments.
Second, skill extraction needs a quality gate. Not every successful task is worth keeping. One-off scripts, obviously accidental successes, and processes that relied on heavy manual intervention should all be filtered out; otherwise the skill library gets polluted with low-value entries and retrieval just adds noise. In practice, score by “repeat frequency + step determinism + number of manual interventions” and keep only high-scoring samples.
3. Automatic Optimization of Prompts and Skills: Balancing Efficiency and Safety
Once the skill library reaches a certain size, the new bottleneck is description quality: a vaguely written skill loads inaccurately, and an ambiguous tool description causes wrong calls. This calls for an automatic optimization layer that iteratively improves skill text, tool descriptions, and system prompts.
One well-known approach in the industry belongs to the prompt evolution direction: explore multiple candidate prompts in parallel via population search, use actual task feedback as the fitness signal, and keep the better-performing individuals generation by generation. Its convergence efficiency is typically far better than pure reinforcement-learning-style end-to-end tuning. The key advantage is that no model training is required—everything is done through the inference API, so the engineering cost is low.
But automation must have a brake. A reliable production form is to submit optimization output as a change request, preserving the diff and evaluation results, and merge it only after human review. The reason is straightforward: the optimization target is “task success rate,” while the user’s real intent often includes constraints beyond success rate—least privilege, rollback capability, no unauthorized data access. Without a human gate, metric improvement and intent drift happen at the same time.
4. Layered Persistent Memory: Giving State a Place to Live
Cross-session continuity depends on storage design. It can be abstracted into three layers:
- Built-in persistent memory: holds stable long-term facts such as user preferences, project conventions, and environment topology. Small in volume, read frequently, requiring low latency and strong consistency.
- Session retrieval layer: chunks and vectorizes historical conversations and execution traces, builds an index, and recalls relevant fragments by semantic similarity to solve the “can’t remember everything” problem.
- External plugins and knowledge sources: connect to an organization’s existing document systems, code repositories, and ticketing systems, extending the memory boundary to organizational assets.
What is genuinely hard in engineering is not writing but forgetting and correcting. Once a memory entry is stale or wrong, every subsequent task keeps citing it, creating an amplification effect. So each memory entry should carry a source, timestamp, and confidence score, and support invalidation and overwriting; fields involving personal information need masking and access control, with a clear retention period.
5. Architecture Decoupling: Separating Capability, Memory, and Execution
If memory, skills, and tools are all hardcoded into one monolith process, any single upgrade forces a full restart, and local horizontal scaling is impossible. The goal of decoupling is to split the agent into four components that can evolve independently:
- Reasoning core: handles planning and decisions only, holds no state.
- Memory service: a unified read/write interface that hides whether the backend is a file, a database, or a search engine.
- Skill repository: version-controlled, supporting review, rollback, and sharing across instances.
- Execution sandbox: tool calls run in an isolated environment with restricted filesystem and network permissions.
On the cloud, these four layers map to general capability categories: a container platform hosts the reasoning core and sandbox, object storage and database services host memory and skill files, a message queue decouples long-running tasks, and logging plus monitoring/alerting provide observability. If you use Baidu AI Cloud capabilities, the same layering principle applies: define the interface contracts first, then choose concrete implementations, and avoid binding business logic to the technical details of any single layer.
6. Risks and Acceptance
Self-evolution introduces new failure modes, so guardrails must be designed in from the start:
- Skill drift: periodically sample and replay historical tasks, comparing success rate and step differences.
- Permission creep: skills and sandbox share a least-privilege model, and changes require review.
- Memory pollution: validate sources before writing, and support one-click rollback to a historical snapshot.
- Cost blowup: cap retrieval recall volume, context length, and number of call rounds.
For acceptance, use quantifiable metrics: the reduction in step count and time on the second run of a similar task, cross-session preference hit rate, number of manual interventions, and rollback success rate.
7. Conclusion
“Getting to know you better with use” is not achieved by a bigger model but by engineering state and experience management. Closed-loop learning turns experience into assets, layered memory gives state a place to live, and architecture decoupling lets the three evolve independently; human review and least privilege are the preconditions that keep this system from drifting over the long run.
