Designing and Building a Prompt-Driven General-Purpose AI Agent Framework

    This article explores the design philosophy and engineering architecture behind prompt-driven, dynamically evolving general-purpose AI agent frameworks. It covers how to expose a full computing environment to the model as a toolset, why behavior should be defined entirely by system prompts, hierarchical multi-agent collaboration, layered architecture from scripts to multi-agent systems, core components such as agents, tools, memory, prompts, and knowledge bases, containerized runtime benefits, task decomposition best practices, and common pitfalls—helping you build a transparent, auditable, and continuously improving agent system.

    1. Background: From Task-Specific Tools to a General-Purpose Personal Assistant

    Over the past two years, agent-related frameworks have proliferated, but many are essentially pre-programmed workflow orchestrators built for specific tasks: inputs are constrained to fixed formats, outputs are limited to a few predefined actions, and once a task deviates from what the designer anticipated, the system can only error out or spin idly. Such tools perform well in demos but struggle to serve as a true “personal assistant”—because real user needs are long-tailed, ambiguous, and constantly changing.

    General-purpose agent frameworks aim to resolve exactly this tension. Their goal is not to do one particular thing right, but to give the agent the ability to figure out unfamiliar tasks on its own. This requires the framework to abandon hard-coding of specific business workflows, hand decision-making over to the model, and provide a set of tools the model can call freely.

    This article uses a class of open-source, prompt-driven, dynamically evolving agent frameworks as a prototype, abstracting their design philosophy and engineering structure to discuss how to build a personal agent that grows organically and is highly transparent, readable, understandable, customizable, and interactive.

    2. Core Design Philosophy: Treat the Computer Itself as the Toolset

    The most critical abstraction in these frameworks is that instead of defining dozens of semantic business functions for the agent, they directly expose “a computer” to the model: it can execute commands, read and write files, run code, and access the network. The benefit is an extremely high capability ceiling—anything a human could accomplish on this machine, the agent can in principle do as well. The cost is reduced controllability, which is why sandboxing and auditing must accompany it.

    The second key decision is that “behavior is defined entirely by the system prompt.” The framework code does not dictate what the agent “should do first and do next”; it only provides mechanisms. Policies, tone, workflows, and prohibitions all live in prompt files. A user modifying a single Markdown file effectively rewrites the agent’s personality and way of working—enabling near-zero-threshold customization and making behavior fully explainable: when something goes wrong, you only need to read the prompt.

    The third is “hierarchical multi-agent collaboration.” A single context window has limited attention and capacity, so the framework allows each agent to spawn sub-agents, recursively decomposing complex tasks. Parent agents keep only conclusions, while sub-agents absorb the noisiest exploration process—an explicit form of context isolation and parallelization.

    3. Layered Architecture: Elastic Scaling from Script to Multi-Agent System

    A mature implementation typically consists of four layers:

    • Infrastructure layer: container runtime, file system, network egress, and dependency management, providing a consistent, reclaimable execution environment.
    • Core engine layer: the agent loop (reason–act–observe), tool scheduling, prompt assembly, memory read/write, and message routing.
    • Application layer: interaction entry points (CLI, web UI, external message channels), multi-agent orchestration, and task queues.
    • Developer toolchain: prompt version management, tool registration and debugging, logging and tracing, and evaluation regression.

    The value of layering is a smooth scaling path: to run a single script, minimal configuration suffices; to build a complex system with dozens of collaborating agents, no kernel changes are needed—just add orchestration logic and tools at the upper layers.

    4. Core Components Explained

    Agents are the executing entities, running in a hierarchy. Each instance has its own context, memory view, and list of sub-agents.

    Tools extend an agent’s capabilities, typically including a set of built-in capabilities (command execution, file operations, code interpretation, web scraping) plus user-defined ones. The quality of tool descriptions directly determines call accuracy, so tool naming, parameter documentation, and return formats should be designed with the same rigor as public APIs.

    The memory system is what separates these frameworks from ordinary script orchestration. It enables agents to accumulate experience from historical interactions, typically organized into storage zones:

    1. memory/
    2. ├── user/ # User profile, preferences, long-term agreements
    3. ├── code/ # Reusable code snippets and scripts
    4. ├── solutions/ # Verified solutions to problems
    5. └── meta/ # Time, task progress, runtime state

    Zoning keeps retrieval targeted: when writing code, check code/ first; when facing a repeated problem, check solutions/ first—avoiding the recall noise caused by dumping everything into one large vector store.

    The prompt system typically uses a main prompt file carrying personality and general principles, with supplementary fragments in subdirectories assembled per scenario:

    1. # Role
    2. You are a general-purpose personal assistant capable of executing commands and writing code on a sandboxed computer.
    3. # Working principles
    4. 1. Restate the goal and constraints before presenting a plan;
    5. 2. After each action, observe and verify the result; if you fail twice, switch approaches;
    6. 3. Write important conclusions to memory with timestamps and sources;
    7. 4. Always request confirmation before destructive operations.
    8. # Tool usage
    9. Prefer least-privilege tools; accessing resources outside the sandbox is forbidden.

    The knowledge base supports importing custom documents, giving the agent a private source of facts to mitigate hallucination.

    Toolsets and extensions provide capability injection “without increasing the system prompt burden”: a group of related functions is packaged as a pluggable module whose descriptions are loaded only when needed, controlling context bloat. This is a key cost-control measure for long sessions.

    5. Runtime: The Triple Dividend of Containerization

    Building the runtime around containers yields three main benefits. First, environment consistency: dependencies, system libraries, and runtime versions are baked into the image, so behavior is identical across machines and platforms—“works on my machine” is eliminated. Second, security isolation: the file system and network can be restricted, the blast radius of destructive commands is contained within the container, and deleting the container rolls everything back. Third, simplified deployment and updates: upgrading the framework means swapping the image tag, while mounted data volumes preserve memory and the knowledge base.

    Illustrative orchestration constraints:

    1. agent:
    2. image: agent-runtime:latest
    3. network: restricted # Allow only necessary egress
    4. read_only_root: true # Read-only root filesystem
    5. volumes:
    6. - agent_memory:/data/memory
    7. - agent_kb:/data/kb
    8. limits:
    9. cpu: "2"
    10. memory: 4Gi

    When deploying in the cloud, the runtime can run on a container platform, object storage can hold the knowledge base and memory snapshots, message queues can distribute multi-agent tasks, and logging services with monitoring and alerting provide end-to-end observability—standard product categories suffice, with no proprietary interfaces required.

    6. Multi-Agent Collaboration and Task Decomposition: Engineering Essentials

    To make hierarchical collaboration actually work, three things must be defined: task contracts (the goal, inputs, and acceptance criteria a parent agent hands to a sub-agent), context pruning (return only conclusions and key evidence), and termination conditions (maximum depth, maximum rounds, timeouts). Missing any one of these leads to infinite recursion among sub-agents or distorted conclusions.

    For parallelism, independent subtasks should run concurrently while dependent ones run serially; shared memory writes need locking or an append-only log to avoid overwriting each other.

    7. Dynamic Evolution: From Experience Accumulation to Model Self-Iteration

    “Dynamic evolution” has two layers of meaning. The shallow layer is behavioral improvement driven by memory and the knowledge base: the second time an agent encounters a class of problems, it can directly reuse verified solutions. The deeper layer is model-level self-iteration: using real interaction trajectories as corpus to build training data and continuously fine-tune the base model, forming a closed loop of “use—sample—train—regression evaluation.” Engineering-wise, an offline evaluation set and human spot-checks must be retained; otherwise, self-optimization easily degenerates into amplifying biases.

    8. Common Pitfalls and Practical Advice

    1. Prompt bloat: Stuffing every rule into the main prompt crowds out context; split it into fragments loaded on demand.
    2. Overly broad permissions: Default to least privilege; force double confirmation for destructive operations and keep audit records.
    3. Memory pollution: Validate and deduplicate before writes; set expiry and confidence scores on memory entries.
    4. Missing observability: Structurally log every reasoning step, tool call, and duration so you can pinpoint failure points.
    5. Ignoring cost: Set round and budget limits for long tasks; lazy-load toolsets.

    In summary, the value of a prompt-driven general-purpose agent lies not in any single feature but in the architectural choice of “separating mechanism from policy”: the framework provides stable mechanisms, while prompts and memory carry the mutable policies and experience. Understanding and mastering this layering lets you build agent systems in your own environment that are transparent, auditable, and continuously growing.