AI Agent Architecture Design: A Three-Layer Approach to Persistent, Self-Evolving Agents
This article breaks down how modern AI agents move beyond single-session assistants to run as persistent, server-side processes. It introduces a three-layer framework—prompt engineering, context engineering, and harness (framework) engineering—and explains how each layer contributes to reliability and self-improvement. You will find practical guidance on versioned prompt contracts, four-tier memory with experience write-back, tool governance, execution isolation, observability, failure recovery, common anti-patterns, and a step-by-step rollout path for cloud deployment.
1. From Chat Assistants to Persistent Agents
Over the past two years, the shape of AI agents has shifted noticeably. Early products were mostly tied to an IDE or a single chat entry point, and were essentially assistants that completed one task within one session. A newer generation of solutions deploys agents on the server side as long-running autonomous processes, triggered through multiple entry points such as messaging platforms, scheduled jobs, and event callbacks.
This shift creates two core requirements. The first is persistence: processes and state do not disappear when a session ends, and tasks can continue across days or weeks. The second is self-evolution: the system can turn successful experience from execution into reusable assets, so the longer it runs, the more capable it becomes, rather than reasoning from scratch every time.
It is worth emphasizing that “self-evolution,” as commonly understood in the industry, does not mean model weights are updated automatically. For most engineering implementations, it refers to the continuous accumulation of the agent’s writable outer layers: prompt templates are refined, context is compressed and organized, tools and workflows are solidified, and lessons from failures are recorded. The model itself is usually still provided by an external inference service, and remains replaceable, subject to canary rollout, and rollback-capable.
2. A Three-Layer Framework: Prompt / Context / Harness
Judging whether an agent is “doing well” is not enough if you only look at frontend and backend engineering. A more effective way to split the problem is into three layers:
- Prompt engineering: how to express intent and constraints reliably, focusing on role definition, task decomposition, and output contracts.
- Context engineering: what to put into a limited window, focusing on memory tiers, retrieval strategy, compression, and invalidation handling.
- Harness engineering: how to turn model capability into reliable production behavior, focusing on scheduling, execution isolation, tool governance, observability, and rollback.
The three layers build on one another: the prompt defines behavior boundaries, the context defines information supply, and the harness defines reliability and operability. In most projects with unstable results, the problem is often not the model but a missing third layer.
3. Prompt Layer Design: Turning “Persona Setup” into an Executable Contract
In persistent runtime scenarios, a prompt is no longer a few hundred words of role description, but a layered contract.
The first layer is identity and boundaries: what the agent is, what it does not do, and how it refuses out-of-scope requests. The second layer is the task protocol, which specifies the order of input parsing, plan generation, tool selection, and result validation. The third layer is the output contract, which constrains results with a structured format so downstream programs can consume them.
An illustrative example:
[Role] You are a long-running operations analysis agent that handles monitoring and log analysis tasks only.[Flow] 1) Parse the request 2) List required data 3) Call query tools 4) Validate data completeness 5) Output conclusions[Output] Return strict JSON: {"conclusion": string, "evidence": string[], "risk": "low|mid|high"}[Refusal] For account credentials or delete operations, stop and request human confirmation.
Two practices are key. First, prompt templates must be versioned, so any change can be traced to a specific shift in results. Second, write “reusable experience” as conditional snippets—for example, “when a query returns empty, widen the time window before concluding there is no anomaly”—to avoid the model over-inferring from empty data.
4. Context Layer Design: Tiered Memory and Experience Write-Back
Context is a finite resource, and the essence of self-evolution is “putting the right context in at the right moment.” A relatively mature industry approach is a four-tier structure:
- Working context: the current task’s inputs and intermediate results, with the shortest lifecycle.
- Session memory: summaries of recent turns, with controlled length to prevent the window from being crowded out by conversation history.
- Long-term knowledge: documents, code conventions, and historical conclusions, usually stored externally and retrieved on demand.
- Experience library: rules, script snippets, and failure cases automatically accumulated during runs.
Experience write-back is the core mechanism behind “getting stronger with use,” and it needs an admission threshold; otherwise noise will quickly pollute the context:
if task succeeds and result passes validation and experience similarity < threshold:write to experience library(summary, trigger condition, source reference)else:log to run logs only, awaiting human or offline review
Engineering work also needs to handle three things. First, compression: produce layered summaries of long histories, keeping conclusions and discarding process. Second, invalidation: give knowledge entries an expiration and a source tag, and downweight them once expired. Third, isolation: memory across tenants and business lines must not be cross-retrieved, to avoid wrong decisions caused by context mixing.
5. Harness Layer Design: Scheduling, Tool Governance, and Operability
The harness layer determines whether an agent can survive long-term as a production system, and includes at least five modules.
Scheduling and triggering: a built-in scheduler handles periodic tasks, while event-driven entry points handle instant requests. Tasks must support idempotency and deduplication to prevent side effects from repeated triggering.
Tool governance: as the number of tools grows, selection accuracy drops. A sound approach is grouped registration, enabling tools per scenario, and declaring a parameter schema, permission level, and timeout for each tool. In practice, keeping the tool set lean with clear descriptions works better than piling up many tools.
Execution isolation: high-risk actions run in a controlled environment with restricted filesystem and network access, and write and delete operations require mandatory human confirmation.
Observability and evaluation: record the prompt version, retrieval hits, tool call chain, and latency of each run to form a replayable trace; build an offline evaluation set, and run any prompt or retrieval strategy change through evaluation before release.
Failure recovery: set retry limits, circuit breakers, and fallback paths, and on consecutive failures fall back to a read-only mode that “outputs analysis and suggestions only,” rather than continuing to attempt high-risk operations.
6. Common Anti-Patterns and Adoption Advice
- Treating self-evolution as automatic prompt rewriting: unreviewed self-rewriting drifts quickly, so keep human confirmation and rollback points.
- Memory that only grows: context bloat raises costs and dilutes attention, so compression and expiration policies are mandatory.
- Unbounded tool expansion: tools with vague descriptions significantly reduce selection accuracy.
- Releasing without evaluation: without a baseline, you cannot tell whether a change is an improvement or a regression.
A suggested adoption path has three steps: first build a read-only analysis agent and get context tiering and observability working; then introduce controlled write operations with human confirmation; finally open experience write-back and automatic optimization, gradually expanding the permission scope.
For cloud deployment, general-purpose capabilities are usually enough: a container platform hosts the long-running process, object storage holds knowledge and experience entries, a message queue buffers and smooths task peaks, and logging plus monitoring and alerting provide observability. Keeping the overall architecture model-replaceable and storage-portable avoids being locked into a single inference service.
In summary, persistent running and self-evolution are not mysterious capabilities, but the combined result of contractualized prompts, tiered context, and engineered harnesses. Make these three layers solid, and an agent’s capability growth will be stable, explainable, and operable.
