AI Agent System Architecture Design Space: From the Core Loop to Permission Defense
This article examines the engineering realities behind AI agent systems: why only a small fraction of the codebase performs model inference while most of it provides deterministic operational scaffolding. It covers five core values, seven major components, thirteen design principles, a seven-layer permission defense model, a five-stage context compression pipeline, extension mechanisms, deployment-driven architecture tradeoffs, and future directions for long-term capability protection and governance transparency.
1. Rethinking the Agent: 1.6% Model, 98.4% Engineering
Many developers entering the agent field fall into a common trap: they assume that building a powerful AI agent depends primarily on refining prompts to perfection. However, systematic analysis of the source code of contemporary AI coding tools reveals a counterintuitive fact: the code that actually calls the large model for inference accounts for only about 1.6% of the entire system codebase. The remaining 98.4% is deterministic engineering scaffolding.
Behind this ratio lies a core paradigm for agent design: the model is responsible only for “thinking” and proposing actions, while execution, security sandboxing, permission checks, and context management are handled by the underlying infrastructure. In other words, the future of AI is not omnipotent magic, but an engine running on precision gears. The model is like the combustion chamber of an engine, providing energy and decision pulses; how that energy is transmitted, how speed is controlled, and how overload is protected all depend on the surrounding mechanical structure.
The implication for architects is clear: when designing agent systems, effort spent on prompt engineering should not exceed one-tenth of the total engineering effort. What truly determines the upper limit of system quality is the 98.4% operational support system.
2. Five Core Values That Drive the Architecture
Large and complex architectures are not assembled arbitrarily; they are driven by a clear ordering of values. Researchers distilled five core values that form a “constitution” for all design decisions:
Human decision authority: Humans always retain the final say and can audit, reject, or interrupt any operation. This means agent autonomy must have explicit “circuit-breaker boundaries,” and any high-risk action should have a checkpoint where humans can intervene.
Safety and privacy: Build a “default deny” defense system. Defense design must not assume that users will always configure things correctly; it must assume that humans will make mistakes—and that the system can protect itself even when they do.
Reliable execution: Ensure correctness for a single task and coherence across long, multi-turn conversations. The former tests the determinism of tool calls; the latter tests state management and memory mechanisms.
Capability amplification: Pair a minimal decision scaffold with the strongest execution environment to maximize AI productivity. The stronger the model, the thinner the scaffold can be, but the execution environment must be thicker.
Context adaptability: The system can dynamically adjust its behavior based on the user’s context—project type, technology stack, and skill level—and gradually build trust.
There is natural tension among these five values. For example, “human decision authority” and “capability amplification” constrain each other in terms of interaction frequency, while “safety” and “reliability” may conflict along execution paths. The art of architecture design lies in resolving these tensions through layered mechanisms.
3. Seven Core Components: A Macro View of the Agent
From a macro perspective, a mature agent system can be broken down into seven core components that form a complete closed-loop chain:
User↓Multi-surface interfaces ← CLI / IDE / Web / API↓Agent Loop↓Permission System↓Tools → Execution Environment↓State & Persistence
User and multi-surface interfaces form the input layer. The same agent core must adapt to terminals, editor plugins, web interfaces, and other interaction forms. The interface layer must be “thin and unified,” standardize session protocols, and prevent business logic from leaking into the presentation layer.
The agent loop is the heart of the system. It follows a minimal loop paradigm: receive a goal → call model inference → model proposes an action → validate and execute the action → feed the result back into context → decide whether to continue the loop. The pseudocode for this loop can be summarized as:
while not task_done:response = llm.infer(context)action = parse_action(response)if not permission_gateway.check(action):action = request_human_approval(action)result = sandbox.execute(action)context = compressor.update(context, action, result)
The permission gateway is the key security gate, discussed in detail below. The tool pool defines what the agent can do—read and write files, execute commands, retrieve code, and call external services. Each tool should have explicit input validation and side-effect declarations. The execution sandbox ensures that tool side effects are confined within controllable boundaries, such as file system snapshots, network egress controls, and resource quotas. State and persistence is responsible for long-term storage of session history, task checkpoints, and user preferences, and is the material basis for long-range coherence.
4. Thirteen Design Principles and Seven-Layer Permission Defense
Supporting the implementation of the five values are thirteen concrete design principles. Among them, the permission defense system and the context compression pipeline deserve the most detailed discussion.
4.1 Seven-Layer Permission Defense
The permission system adopts a defense-in-depth approach: every tool call must pass through seven gates.
- Explicit user authorization layer: Highest priority. Actions directly approved by the user are allowed immediately.
- Session-level permission cache: Similar low-risk actions can be reused after being authorized once within a session, balancing security and flow.
- Rule engine layer: Automatically determines based on declarative rules, such as allowing read operations in a certain directory.
- Static analysis layer: Identifies risk characteristics in commands or code about to be executed, such as detecting high-risk patterns like deletion or outbound network transmission.
- Sandbox enforcement layer: Even if the first four layers misjudge, the sandbox still performs physical isolation across file system, network, and process dimensions.
- Audit log layer: All decisions and executions are fully recorded to support post-hoc replay and accountability.
- Interrupt and rollback layer: Humans can interrupt execution at any time, and the system can roll back state to the most recent checkpoint.
The essence of this design is “default deny + layer-by-layer release”: any action not on a whitelist is intercepted, and the more release paths there are, the lower the risk of a single point of failure.
4.2 Five-Stage Context Compression Pipeline
In long-running tasks, the context window is a scarce resource. Mature agents use a five-stage compression pipeline to manage it:
- Stage 1: Real-time trimming—Perform field-level filtering on raw tool outputs, retaining only structured information relevant to the current task.
- Stage 2: Summarization—When historical dialogue exceeds a threshold, compress earlier turns into semantic summaries.
- Stage 3: Hierarchical memory—Extract task goals, key decisions, and important file paths into persistent “working memory,” separate from chronological history.
- Stage 4: On-demand retrieval—Compressed details are not discarded but stored in searchable storage and precisely recalled when needed.
- Stage 5: Checkpoint reconstruction—Very long tasks save complete snapshots at key nodes, allowing recovery from checkpoints if compression fails and ensuring reliability.
This pipeline answers a key question: how to keep an agent coherent across hundreds of interaction turns without losing critical information. Its design philosophy is “lossy compression + lossless fallback”—summaries may lose details, but checkpoints and retrievable storage ensure that no information truly disappears.
5. Extension Mechanisms and the Shaping Role of Deployment Environments
The extension mechanisms of an agent system determine its ecosystem ceiling. Typical designs include custom tool registration (users inject new tools through a standard protocol), slash commands and skill packs (packaging high-frequency workflows into reusable units), and hooks (attaching user logic to key nodes in the loop). Their common feature is that extensions occur at the engineering scaffold layer rather than polluting the model decision layer, ensuring that extensions do not break the determinism of the core loop.
Another profound research conclusion is that deployment environments shape architectural choices. The same agent core deployed on a local developer terminal versus a cloud-hosted environment requires very different architectural tradeoffs. In a local environment, trust boundaries are clear, permissions can be relatively loose, and the sandbox can be thinner. In a cloud multi-tenant environment, isolation, auditing, and quotas must be strengthened. Through horizontal comparison with open-source agent systems, researchers found that there is no “optimal architecture,” only an architecture that best matches its deployment environment. This reminds architects that discussing architectural superiority outside the deployment scenario is meaningless.
6. Future Directions: Long-Term Capability Protection and Governance Transparency
The research concludes by pointing to two evolution directions for agent systems.
Long-term capability protection: As agent operating cycles extend from a single session to continuous tasks lasting days or even weeks, protecting accumulated skills, memories, and context assets from being damaged by compression pipelines or wiped out by version upgrades will become a core engineering problem. This involves topics such as persistent memory formats, capability version migration, and cross-session state continuity.
Governance transparency: As agents take on more real operations in enterprise environments, their decision processes must be explainable, auditable, and accountable. Future agent systems need to provide “flight recorder”-like capabilities—fully replaying the input of each inference, the approval chain of each action, and the environment snapshot of each execution—so human supervisors can understand why the AI acted as it did.
Conclusion
From 1.6% model code to 98.4% engineering scaffolding, from five core values to thirteen design principles, from seven-layer permission defense to a five-stage compression pipeline, the design space for agent systems is far broader than “writing better prompts.” For developers, the most important shift in understanding is this: the essence of agent engineering is not making the model smarter, but amplifying the model’s capabilities safely, reliably, and audibly. When you start building your own agent system, ask yourself three questions first: Where does final human decision authority reside? How many layers of defense in depth are there? How are long-range memories compressed and restored? Once these three questions are clear, the skeleton of the architecture will naturally stand up.
