AI Agent Architecture: From Command Line to File System

    This article explores a proven paradigm for building AI agents: using command-line tools and file systems as the core interface instead of proprietary tool APIs. It covers the architectural rationale, context engineering with files as memory, capability injection through skills, structured output trade-offs, interaction design and security boundaries, and release strategy with observability. Engineers will find practical guidance on context layering, skill governance, permission scoping, and gradual rollout metrics.

    Introduction: Why “Simple” Interfaces Work Better for Agents

    A conclusion that keeps proving itself in the engineering practice of building AI agents is this: the closer an interface is to native operating system capabilities, the more stable and composable it tends to be. Command-line tools and file systems, as the oldest and most universal abstraction layer, are becoming the core infrastructure for coding agents. This article uses that paradigm as a thread to systematically cover architecture design, context management, capability injection, output format selection, and release strategy.

    1. Core Idea: Build on General-Purpose Tools and the File System

    Traditional agent frameworks tend to define a large number of proprietary tool interfaces for the model, such as structured query APIs and custom action protocols. This kind of design looks good in a demo, but in real engineering it quickly exposes problems: the number of interfaces balloons, parameter schemas become hard to maintain, and the probability of the model picking the wrong tool rises as the tool count grows.

    Using the command line and file system as a unified interface essentially hands the “world model” back to the operating system. The advantages show up on three levels:

    1. Composability: Mechanisms such as pipes, redirection, and wildcards naturally support chaining multiple operations together, with no need to predefine an interface for every combination.
    2. Observability: All intermediate state is persisted as plain text, so developers can directly inspect, diff, and roll back, keeping troubleshooting costs very low.
    3. Portability: Model training corpora contain massive amounts of command-line and scripting examples, so models have far stronger prior knowledge of these expressions than of private protocols.

    A schematic interaction loop looks like this:

    1. Loop begins
    2. Read the current directory structure and task description file
    3. Model outputs the next command (read, search, modify, execute)
    4. Execute the command in a controlled sandbox, capturing stdout and stderr
    5. Append the output to the context and move to the next round
    6. Loop ends (task complete or step limit reached)

    2. Context Engineering: Files as Memory

    The biggest bottleneck for long tasks is not model capability but context window management. Using the file system as the memory layer lets you split context into two levels, “index” and “detail”: the main context keeps only the directory tree, task list, and a summary of key conclusions, while specific content is read on demand. This lazy-loading strategy significantly reduces the interference of irrelevant information on attention.

    Practical points include:

    • Maintain a structured task list file and update the status as each item is completed, avoiding goal drift during long tasks;
    • Write large logs and build artifacts to temporary files, and return only a summary to the model;
    • Use a two-stage “locate first, then read closely” process for retrieval results to reduce the noise injected all at once.

    3. Capability Injection: Telling the Model What It Doesn’t Know

    The core of the skill mechanism is not to expand the action space but to fill in the model’s cognitive blind spots. A high-quality skill description should answer three questions: in what scenario it must be used, the exact shape of its inputs and outputs, and the troubleshooting path when it fails. Design should follow three principles: single responsibility, explicit trigger conditions, and verifiable success criteria, avoiding stuffing multiple unrelated workflows into the same skill.

    Internal practice at scale shows that when the number of skills reaches the hundreds, the real difficulty shifts from writing to governance: you need naming conventions, version records, hit-rate statistics, and a retirement mechanism, otherwise the skill library degenerates into a graveyard of unmaintained documents.

    4. Structured Output: Trade-offs Between Lightweight and Rich Interaction

    Using plain text markup as the output format has the advantages of zero dependencies, easy diffing, and stable model generation; the limitation is the lack of interactivity. When a task needs to present complex hierarchies, filterable tables, or interactive controls, you can consider having the model generate a locally renderable rich text page for the user or an upper-layer program to consume. Engineering recommendations follow these boundaries:

    • Use a lightweight text format by default to ensure readability and versionability;
    • Switch to rich text rendering only when there is a genuine interaction need, and clearly label the source and trustworthiness of generated content;
    • Escape and sanitize generated results to prevent untrusted content from entering the rendering context.

    5. Interaction Design and Security Boundaries

    An agent needs to confirm with the user at key points, such as high-risk write operations, delete actions, and external resource access. Exposing “asking” itself as an explicit capability to the model is more reliable than letting the model guess user intent. On the security side, apply the principle of least privilege: read-only by default, with write access opened per directory allowlist; execute all commands in an isolated environment; treat all external input uniformly as untrusted data to prevent prompt injection from taking effect indirectly through file contents or command output.

    6. Release Strategy and Observability

    New capabilities should ship through a gradual rollout: first open to a small group of internal users, collect metrics such as success rate, average steps, and interruption reasons, then gradually expand the percentage. Capabilities involving hardware differences, such as voice and cross-platform adaptation, especially need layered validation. Observability should cover three kinds of data: the step trace of each session, the distribution of tool call failure reasons, and the locations where users actively interrupt. This data is both the basis for troubleshooting and the input for optimizing skills and prompts.

    When deploying in the cloud, you can combine a container platform to host the sandbox execution environment, object storage to save session artifacts, and logging services plus monitoring and alerting systems to track quality metrics, gaining elasticity and operability without binding to a specific implementation.

    Conclusion

    An agent architecture built on the command line and file system trades generality for three gains: composability, observability, and lower migration cost. The takeaway for engineering teams is to invest effort in context layering, skill governance, permission boundaries, and gradual rollout metrics rather than continuously piling up proprietary interfaces. Baidu AI Cloud can follow the same general paradigm for architecture design and capability layering when hosting and operating this kind of workflow.