A General Engineering Paradigm for Building AI Agents: Practices and Trade-offs

    This article presents a general engineering paradigm for building AI agents on top of two universal primitives: executable commands and a readable/writable file system. It explains why this minimal foundation improves portability, reproducibility, auditability, and replaceability, and when specialized channels are still preferable. The article then walks through a six-layer architecture (interface, orchestration, capability, context, governance, and observability), context engineering principles, a unified contract for wrapping heterogeneous tools, interactive result rendering with security caveats, permission and compliance boundaries, progressive rollout driven by observability, and common anti-patterns to avoid. Readers will gain a clear, replicable path for building controllable agents in their own environments.

    1. Why Return to the Minimal Foundation of “Command Line + File System”

    As agent engineering evolves rapidly, the industry has produced many specialized frameworks and proprietary protocols. Yet one conclusion keeps being validated: converging an agent’s capability boundary onto two of the most universal primitives—executing commands and reading/writing files—often yields better portability and debuggability.

    The reason is not mysterious. A file system is naturally a tree-structured context container, while a command acts as an adapter layer that normalizes any external capability into “text in, text out.” Once combined, the model does not need to learn framework-specific abstractions; it only needs to understand paths, encoding, and exit codes. The direct engineering benefits include:

    • Reproducibility: all intermediate artifacts are persisted to disk, so any step can be replayed and compared.
    • Auditability: read/write behavior leaves a natural trace, which helps with compliance and retrospection.
    • Replaceability: models, runtimes, and tool implementations can all be swapped without locking into a single ecosystem.
    • Low barrier to entry: newcomers can contribute with only basic systems knowledge.

    It is worth emphasizing that this is an architectural trade-off, not an absolute truth. When a task depends heavily on high-frequency structured calls or ultra-low latency, a specialized channel should still be introduced. But for the vast majority of day-to-day development scenarios—reading code, modifying files, running tests, and producing reports—the minimal foundation offers the best cost-performance ratio.

    2. Layered Architecture: Splitting the Agent into Six Governable Layers

    It is recommended to divide the system into six layers that communicate through explicit contracts, avoiding capability coupling.

    1. Interface layer: handles interaction with humans or upstream systems, supports multiple input forms such as text and voice, and normalizes them into structured requests.
    2. Orchestration layer: handles task decomposition, plan generation, step scheduling, and failure retries. This is where the “brain” resides.
    3. Capability layer: uniformly wraps external actions as command-style invocations, with both input and output being text or files.
    4. Context layer: manages short-term sessions, long-term memory, and retrieval indexes, deciding “what the model can see right now.”
    5. Governance layer: handles permissions, auditing, rate limiting, data masking, and policy validation.
    6. Observability layer: collects metrics, logs, and traces to support diagnosis and optimization.

    A sample directory convention can make these layers land naturally:

    1. /workspace
    2. /skills # Reusable atomic capability descriptions and scripts
    3. /context # Sessions and long-term memory
    4. /short-term # Current task context
    5. /long-term # Structured memory and summaries
    6. /artifacts # Intermediate and final artifacts
    7. /logs # Runtime logs and traces
    8. /policy # Permission and policy configuration

    3. Context Engineering: The Real Bottleneck That Sets the Agent’s Ceiling

    Model capability matters, but in engineering practice, the quality of context organization often determines success or failure. Three principles can be followed:

    • Layered loading: provide a directory-level summary first, then load details on demand after retrieval hits, avoiding a one-time flood of noise.
    • Structure first: carrying information with fixed fields and heading hierarchies helps the model locate content better than free-form text.
    • Recyclable: proactively compress and archive context when a task ends or a phase switches, preventing context bloat from diluting attention.

    A practical context assembly pseudocode is shown below, reflecting “summary first, expand on demand, recycle after use”:

    1. def build_context(task, workspace):
    2. plan = load_summary(workspace / "context/long-term")
    3. hits = search_index(task.query, top_k=5)
    4. details = [read_text(p) for p in hits]
    5. ctx = f"[Task]{task.goal}\n[Plan]{plan}\n[Data]{''.join(details)}"
    6. return trim(ctx, budget=task.token_budget)

    4. Capability Wrapping: Taming Heterogeneous Tools with a Unified Contract

    Writing each external capability as a three-part description of “description + invocation method + constraints” can significantly reduce the model’s misuse rate. The key insight here is that the core value of a capability description lies not in listing features, but in filling the implicit premises that the model “doesn’t know it doesn’t know”—for example, applicability boundaries, failure modes, side effects, and rollback methods.

    1. name: run_tests
    2. description: Run tests for a specified module and return structured results
    3. input: { module: string, pattern?: string }
    4. constraints:
    5. - Execute only on a read-only branch
    6. - Automatically terminate after a 300-second timeout
    7. side_effects: Generates /artifacts/test-report.json
    8. rollback: Simply delete the artifact directory

    5. Interactive Content Presentation: From Static Text to Actionable Interfaces

    The traditional approach writes results into static documents that readers can only consume passively. A more effective direction is to generate lightweight interactive pages: turning key conclusions into filterable tables, expandable charts, and small tools that can be verified instantly. Compared with static text, interactive presentation has three advantages: higher information density, less ambiguity, and lower verification cost.

    At the same time, security must be emphasized: interactive content should be rendered in an isolated environment, inline scripts must be forbidden from accessing host resources, and all external data should be treated as untrusted input by default and escaped, to avoid the combined risk of prompt injection and script injection.

    6. Permission, Security, and Compliance Boundaries

    The governance layer cannot be added after the fact; it must be in place at design time:

    • Least privilege: default to read-only; write operations require explicit authorization and are limited to a path allowlist.
    • Dangerous action interception: apply secondary confirmation and rate limiting to actions such as deletion, bulk rewrites, and outbound network transmission.
    • Data classification: sensitive data must be masked before it is allowed into context, encrypted on disk, and given a retention period.
    • Full-chain auditing: record “who triggered what action under what policy at what time,” supporting one-click replay.
    • Platform policy coordination: in scenarios such as peak-time rate limiting and third-party access control, clearly explain the reasons and alternatives to users to reduce misunderstanding.

    7. Release Strategy: Iteration Driven by Progressive Rollout and Observability

    It is recommended to adopt progressive delivery when launching a capability: first internal trial, then a small-percentage user canary, observing core metrics (task success rate, average number of steps, human takeover rate, latency distribution) before gradually ramping up. Each step should have a rollback switch and configuration center support, ensuring recovery within minutes when anomalies occur.

    For observability, at least three types of signals should be covered: metrics for trend judgment, logs for detailed diagnosis, and traces for reconstructing the complete decision chain of a task. Only when all three are correlated to the same task identifier can a closed loop be formed.

    8. Common Anti-patterns and How to Avoid Them

    • Over-abstraction: introducing multi-layer frameworks too early, resulting in an overly long debugging chain. It is recommended to get a minimal closed loop running first, then evolve.
    • Unbounded context: stuffing all materials in at once, which instead lowers hit rate.
    • Vague capability descriptions: writing only “what it can do” without “when it should not be used.”
    • Missing governance: launching first and adding permissions later, which is extremely risky.
    • Ignoring human-agent collaboration: lacking a step of “asking the user to clarify intent,” which amplifies errors early on.

    9. Conclusion

    The value of an agent architecture based on commands and files lies in turning complexity into engineering-solvable problems: context can be organized, capabilities can be described, behavior can be audited, and releases can be rolled back. On this basis, introducing interactive result presentation and internal capability reuse mechanisms can further compress the delivery cycle. For teams that want to build controllable agents in their own environments, running and governance can be carried by general cloud capabilities such as container platforms, object storage, log services, and monitoring/alerting, forming a clear, replicable, and continuously evolvable implementation path.