Open-Source Autonomous Agent Architecture: A Practical Guide

    This guide explains how to build an open-source autonomous agent that runs persistently instead of resetting with every conversation. It covers a six-layer architecture, a dual-track cross-session memory design combining full-text retrieval with layered summarization, autonomous skill creation and reuse, a unified event model for multi-platform integration, protocol-based tool expansion, scheduled proactive execution, multi-model routing, and a security and cost governance checklist. Readers will find the core design decisions, engineering trade-offs, and pseudocode, configuration, and event examples needed to make an agent remember users, improve with use, and act on its own.

    1. Why Persistent Operation Is the Dividing Line for Agents

    Most conversational AI systems are stateless by design: one request triggers one inference call, and the context disappears when the session ends. That is fine for a demo, but it breaks down in production. Users have to re-explain the project background, coding conventions, and personal preferences every time. The system accumulates no experience, and operating costs grow linearly with the number of sessions.

    The open-source autonomous agent approach is built on a different premise: turn the agent from a reactive tool into a long-running process. It has three design goals that cannot be avoided:

    1. Persistent operation: the process stays alive and can be triggered by external events, not only by user input.
    2. Self-improvement: reusable procedural skills are distilled from execution traces instead of planning from scratch every time.
    3. Cross-session memory: a user’s projects, preferences, and past conclusions are stored long term and recalled accurately.

    These three goals are coupled. Without memory, skills cannot accumulate. Without scheduling, the agent cannot run on its own. Without skill reuse, the token cost of long-running operation becomes unacceptable. The architecture layers below are organized around closing this loop.

    2. Layered Architecture Overview

    A deployable autonomous agent system is usually split into six layers, decoupled through explicit contracts:

    • Access layer: a multi-platform message gateway that normalizes heterogeneous channels into internal standard events.
    • Session and orchestration layer: maintains session state, task queues, inference calls, and tool orchestration.
    • Memory layer: full-text retrieval index plus summary compression plus structured preference storage.
    • Skill layer: skill generation, registration, retrieval, reuse, and iterative refinement.
    • Tool and extension layer: built-in toolset, terminal backends, and external protocol adapters.
    • Scheduling and operations layer: scheduled jobs, logging, monitoring and alerting, and cost control.

    3. Cross-Session Memory: A Dual-Track Design for Retrieval and Summarization

    Long-term memory cannot simply stuff the entire history into the context window, for three direct reasons: context length is limited, long-context inference is expensive, and noise significantly degrades output quality. The common industry approach is a dual-track design.

    Track one is full-text retrieval. Historical conversations, project documents, and decision records are written into a local or managed full-text index. At retrieval time, the top-K fragments are fetched and ranked by keyword and relevance. Full-text retrieval is precise, explainable, and cheap to write incrementally, which makes it a good fit for recall with an explicit cue, such as “I remember we discussed a certain error last time.”

    Track two is summary compression. A language model produces layered summaries of long histories: session-level, task-level, and preference-level. Summaries are small enough to stay resident in the context and provide background intuition, while details are left to retrieval on demand.

    The following is a sketch of the memory write and recall flow (pseudocode that only expresses the structure):

    1. def on_turn_end(session_id, messages):
    2. # 1) Index the raw text and keep traceable details
    3. index.upsert(session_id, chunk(messages))
    4. # 2) Layered summary, compressed into resident background
    5. summary = llm.summarize(messages, level="session")
    6. store.set_summary(session_id, merge(store.get_summary(session_id), summary))
    7. # 3) Extract structured preferences (long-term stable information)
    8. prefs = llm.extract_preferences(messages)
    9. store.merge_preferences(session_id, prefs)
    10. def build_context(query, session_id):
    11. hits = index.search(query, top_k=8) # exact recall
    12. background = store.get_summary(session_id) # compressed background
    13. prefs = store.get_preferences(session_id) # stable preferences
    14. return assemble(background, prefs, hits) # assemble the prompt

    Three engineering points matter here. First, write deduplication and freshness tagging, so outdated conclusions are not recalled repeatedly. Second, permissions and isolation: in multi-tenant scenarios, memory must be isolated along user and project boundaries. Third, deletability: when a user withdraws data, the index and summaries must be cleaned up in sync, which is both a compliance requirement and the basis of trust.

    4. Autonomous Skill Creation: From One-Off Planning to Capability Assets

    A skill is conceptually equivalent to procedural memory: it is not a “fact” but a “way of doing something.” A mature skill system has four stages.

    Generation. After the agent completes a multi-step task, it generalizes over the trace and turns the reusable parts into a process description or script with input and output contracts.

    Registration. Skills need metadata: applicable scenarios, preconditions, input parameters, failure modes, and version numbers. A skill without metadata cannot be retrieved reliably.

    Reuse. When a new task arrives, the system searches for a skill first. On a hit, it calls the skill directly; only on a miss does it enter full planning. This step is the key to cost control, because it turns high-frequency paths from “inference every time” into “one call.”

    Iteration. Skills are rarely right on the first attempt. Record the call success rate and failure reasons, then fix parameters or degrade low-success-rate skills, forming a self-improvement loop.

    It is worth stressing that autonomous skill generation raises security boundary issues. If generated code or commands can be executed, they must run in a restricted sandbox with resource quotas, a network egress allowlist, and a human confirmation threshold. Any autonomous execution capability should default to least privilege.

    5. Multi-Platform Access and a Unified Event Model

    Real users are spread across different messaging channels. In engineering terms, you should define a unified internal event structure for all channels, for example:

    1. {
    2. "event_id": "evt_01",
    3. "channel": "chat",
    4. "tenant_id": "u_42",
    5. "text": "Summarize last week's build failures into a one-page report",
    6. "attachments": [{"type": "file", "ref": "obj://bucket/key"}],
    7. "ts": "2026-01-01T09:00:00Z"
    8. }

    The gateway layer converts each channel’s private format into this structure and renders replies back in the original channel format. The benefit is that the orchestration layer is completely unaware of channel differences, and adding a channel only requires implementing one adapter. Attachments, images, and voice should be uniformly abstracted as “reference plus type,” with the actual content stored in object storage to avoid bloating the message body.

    6. Tool Ecosystem and Protocol-Based Extension

    Built-in tools typically cover web search, file read and write, code execution, and image processing. But a closed toolset cannot cover long-tail needs, so a protocol-based extension mechanism is required. The value of an open standard such as the Model Context Protocol (MCP) is that it decouples the tool provider from the agent implementation, so any external service that conforms to the protocol can be plugged in.

    A further optimization is pipeline merging: compile multi-step calls that originally required several rounds of chained inference into a single composite call within one inference pass, reducing round-trip latency. The system should also support multiple terminal backends (local containers, remote hosts, serverless functions, and so on) and choose according to task characteristics: tasks that need a persistent file system go to containers, short bursty tasks go to serverless, and tasks that involve intranet resources go through controlled remote execution.

    7. Scheduled Execution and Proactive Operation

    A built-in scheduler moves the agent from passive responses to proactive execution. A typical form is a declarative task definition:

    1. - name: daily-build-report
    2. schedule: "0 9 * * 1-5"
    3. prompt: "Summarize yesterday's build failures and generate improvement suggestions"
    4. deliver_to: "chat://ops-group"
    5. memory_scope: "project:platform"

    The scheduling system has to solve three problems: idempotency (repeated triggers produce no duplicate side effects), failure retry with backoff, and observable execution history. In production, the scheduler should work with common cloud capabilities such as message queues, logging services, and monitoring and alerting to form a complete observability loop.

    8. Multi-Model Routing and Hybrid Inference

    No single model is simultaneously best in quality and lowest in cost. A workable strategy is model routing: select different models by task type, context length, and cost budget. For difficult tasks, use hybrid inference, where several models each produce an answer and an aggregator model synthesizes them for a more reliable conclusion. The practical points are to set a cost gate and quality evaluation, so hybrid inference is not misapplied to simple tasks.

    9. Security, Cost, and Governance Checklist

    • Least privilege: authorize tool calls on demand, and require confirmation for high-risk operations.
    • Sandbox isolation: restrict resources and network for code and command execution.
    • Memory governance: isolation, freshness, deletability, and auditability.
    • Cost control: skill reuse, summary compression, model tiering, and quota alerts.
    • Observability: trace every inference and tool call across the full chain to make retrospectives easy.

    10. Conclusion

    The engineering focus of autonomous agents has shifted from model capability to system capability. Memory determines whether the agent understands you, skills determine whether it gets smoother with use, scheduling determines whether it can create value proactively, and governance determines whether an enterprise will actually accept it. With the common capabilities of cloud platforms such as Baidu AI Cloud, infrastructure like container platforms, object storage, message queues, logging, and monitoring and alerting lets the architecture above land faster, so teams only need to focus on the three areas of real differentiation: memory strategy, the skill loop, and business orchestration.