Open-Source Autonomous Agent Architecture: Design and Persistent Memory Practices
This article breaks down the engineering design of open-source autonomous agents built for long-running operation. It covers a five-layer architecture from the message gateway to the reasoning core, a dual-track approach to persistent cross-session memory that combines exact retrieval with semantic summarization, a four-step loop for turning successful task traces into reusable skills, a unified message envelope for multi-platform integration, scheduling and execution backends for unattended workloads, and the observability, cost, and governance controls required to move from demo to production. The framework is model-agnostic, so the underlying LLM can be swapped without affecting upper-layer capabilities.
1. Why Long-Running Operation Became a Core Requirement for Agents
Early conversational AI systems were mostly stateless: one request triggered one inference pass, and the context was discarded when the session ended. This model is simple to implement, but it cannot support genuinely valuable automation. An agent that needs to accompany a user over time, track project progress continuously, and produce reports on a schedule must have three capabilities: remember things across sessions, accumulate methods from experience, and run autonomously on schedule while unattended.
Exploration in the open-source community over the past two years has gradually converged these three points into the standard design goals of an autonomous agent: persistence, self-improvement, and cross-session memory. Around these goals, the industry has formed a relatively common architectural paradigm, which this article breaks down from an engineering perspective and a neutral point of view.
It is worth emphasizing that this class of framework is decoupled from any specific large model. The model is only the inference engine; the framework is responsible for context organization, tool invocation, state storage, and scheduling. As a result, switching model vendors or moving to models of different parameter sizes should not affect the stability of upper-layer capabilities. This is the first principle for evaluating the maturity of any agent framework.
2. Layered Architecture: From Message Gateway to Reasoning Core
An agent that can run for a long time can usually be split into five layers:
- Access layer (message gateway): Unifies scattered instant messaging tools, command-line terminals, and web interfaces into “session channels,” abstracting away platform differences in authentication, message formats, and rich media support.
- Session and state layer: Maintains session identifiers, user preferences, and history summaries, and injects long-term memory into the current context on demand.
- Reasoning and orchestration layer: Handles task decomposition, tool selection, and the merging and execution of multi-step pipelines. This is the agent’s “brain.”
- Tool and capability layer: Atomic capabilities such as file operations, web retrieval, code execution, and image generation, plus external tool servers connected through the Model Context Protocol (MCP).
- Scheduling and runtime layer: Scheduled tasks, event triggers, and containerized or serverless execution backends that determine how the agent keeps working without human intervention.
The value of this layering is that each layer can be replaced and scaled horizontally independently. For example, adding a new messaging platform to the access layer requires no changes to the reasoning logic, and extending capabilities in the tool layer does not change the memory structure.
3. Persistent Cross-Session Memory: A Dual-Track Approach to Retrieval and Summarization
Memory is the hardest and most critical part of a long-running agent. The industry commonly adopts a dual-track strategy of “retrieval + summarization”:
- Exact retrieval track: Historical conversations, project notes, and user preferences are written into a local full-text search index. A common approach is the full-text search capability of an embedded database, such as an inverted index mechanism like FTS5, which achieves millisecond-level recall through keyword and boolean queries. Its advantages are high determinism, explainability, and low cost.
- Semantic summarization track: A large model performs rolling compression on long conversations to generate structured summaries (for example, “user’s current project = X, tech stack = Y, prohibited items = Z”), which are injected first when the context budget is limited.
The fusion logic of the two tracks can be expressed in pseudocode:
def build_context(query, session_id, budget=6000):# 1. Exact recall: local inverted index, highly deterministichits = fts_index.search(query, limit=20)# 2. Semantic recall: vector similarity supplements synonymous expressionsvec_hits = vector_index.search(embed(query), limit=10)# 3. Deduplication and rerankingmerged = rerank(dedupe(hits + vec_hits))# 4. Summary layer: long-term compressed memory, trimmed to the token budgetsummary = store.get_rolling_summary(session_id)return trim_to_budget(summary, merged, budget)
Three points need attention in engineering practice. First, writes should be asynchronous to avoid memory persistence blocking the main reasoning path. Second, forgetting and correction mechanisms must be designed, because incorrect memories will be repeatedly recalled and amplified. Third, memory needs namespaces and access control; in multi-user or multi-tenant scenarios, data must not leak across accounts.
4. Autonomous Skill Creation: Turning Experience into Reusable Programs
Self-improvement does not mean making the model “smarter”; it means distilling successful problem-solving paths into executable assets. The common approach is a four-step loop:
- Trace recording: Fully record a task’s problem description, tool invocation sequence, intermediate artifacts, and final result.
- Success determination: Rules or model self-assessment confirm that the task was accomplished; failed traces do not enter the distillation pipeline.
- Skill extraction: Abstract the trace into a parameterized programmatic skill (a function signature + usage instructions + preconditions).
- Reuse and optimization: When a similar task appears later, search the skill library first; on a hit, invoke the skill directly, and on a miss, run the full reasoning path, then iteratively refine the skill during use.
A sample skill definition can be written as a declarative structure:
skill: daily_repo_digestdescription: Summarize changes in a given repository over the last 24 hoursinputs: {repo: string, since: duration}steps:- tool: git_log(repo, since)- tool: summarize(changes, style="bullet")- tool: send_message(channel, content=summary)constraints:- Aggregate by directory first when a single repository has more than 500 changes
The benefit of this design is a significant reduction in token consumption: a complex multi-step task is compressed into a single “skill invocation + a few parameter values,” while behavior becomes auditable and rollback-friendly.
5. Multi-Platform Access and a Unified Message Abstraction
A long-running agent must live inside the workflows users already have. The engineering key is not how many platforms are integrated, but whether the abstraction is clean. It is recommended to define a unified message envelope:
{"channel": "im|cli|web","session_key": "user@tenant","text": "...","attachments": [{"type": "image", "ref": "..."}],"reply": "async|stream"}
Upper-layer business logic depends only on this envelope, while each platform adapter converts proprietary formats into the standard structure and handles acknowledgments, rate limiting, and reconnection. Differences between asynchronous and streaming replies should be smoothed out at the gateway layer; otherwise the reasoning layer will be polluted by platform-specific behavior.
6. Scheduling and Execution Backends: Engineering Constraints for Unattended Operation
Built-in scheduling (cron semantics) lets an agent “generate yesterday’s digest at 8 a.m. every day.” Implementation should focus on task idempotency (repeated triggers must not produce duplicate side effects), failure retries with backoff, and execution environment isolation. Execution backends usually need to coexist in several forms: local processes suit debugging, container platforms suit reproducible dependency environments, serverless suits bursty and low-frequency tasks, and remote hosts suit scenarios requiring long-lived connections or intranet resources. Sensitive operations should include a human confirmation step by default.
7. Observability, Cost, and Governance
Long-running operation means costs accumulate continuously. Three categories of metrics must be established: invocation volume (attributed by session, skill, and tenant dimensions), success rate (tool failure rate, task completion rate), and memory health (hit rate, staleness rate). Combined with logging services and monitoring alerts, anomalies can be detected before costs spiral out of control. On the governance side, the recommendations are: tool whitelists, code execution sandboxes, key management, and model routing policies (simple tasks go to small models, complex reasoning goes to large models).
If general-purpose cloud capabilities are used as the foundation, object storage can hold the skill library and artifacts, a message queue can smooth out task spikes, a container platform can host the execution backend, and logging and monitoring services can provide observability, forming a portable architecture that is independent of any vendor.
8. Conclusion
The real barrier for open-source autonomous agents is not “being able to call tools,” but the correctness of memory, the quality of distilled skills, the reliability of scheduling, and cost control. Get these four things solid, and both the framework and the model can be swapped freely, allowing an agent to move from demo to production.
