Open-Source Autonomous Agent Design: Persistent Runtime, Cross-Session Memory, and Self-Evolving Skills

    This article describes a practical architecture for autonomous agents that go beyond request–response chatbots: a persistent process, hybrid retrieval for long-term memory, sandboxed skill generation, scheduling, and multi-channel adapters. It covers a five-layer design, FTS-plus-vector recall, safety constraints for generated tools, and rollout advice—without adding capabilities not in the original.

    From Conversational Assistants to Persistent Agents

    Most traditional LLM apps follow a request–response pattern: the user asks, the model answers, the session ends, and context is discarded. That is enough for chat, but not for long-term companionship or continuous task tracking.

    A newer class of autonomous agents is built on three shifts:

    1. Persistent runtime. The agent is a long-lived process or service, not a one-shot call. It has its own work schedule and can run planned tasks even when there is no user message.
    2. Cross-session memory. Memory is not dropped at session end. It is stored durably and retrieved in any later conversation.
    3. Self-growth. The agent can not only call tools but also write new tool code when it hits a new problem, turning solutions into reusable skills.

    Together these form the technical base that separates autonomous agents from ordinary chatbots. The sections below unpack each part.

    Overall Architecture

    A typical persistent-agent system has five layers:

    • Model layer. Connects to multiple LLMs through a unified adapter so vendor APIs can be swapped by task complexity and cost.
    • Memory layer. Persists and retrieves conversation history, factual knowledge, and user preferences.
    • Skill layer. Built-in tools plus dynamically generated custom skills.
    • Scheduler layer. Cron jobs, periodic checks, and async task queues.
    • Access layer. Exposes the agent to messaging platforms, a web UI, or an API gateway.
    1. [Messaging / CLI / API]
    2. │
    3. [Access-layer adapters]
    4. │
    5. [Core orchestrator] ──► [Skill layer: built-in tools + custom skills]
    6. │
    7. [Memory layer: retrieval + persistence]
    8. │
    9. [Model adapter] ──► multiple LLMs

    Cross-Session Memory: Full-Text Search Matters

    The hard part of long-term memory is not storage but retrieval. After weeks of operation, memory entries can number in the thousands or tens of thousands; stuffing them all into context is expensive and inefficient. A common approach is hybrid retrieval:

    1. Keyword search. Use an embedded database’s full-text module (for example FTS on an inverted index) so memory can be hit quickly by keywords.
    2. Semantic search. Embed memory items and recall semantically related content even when wording differs.
    3. Fusion ranking. Weight the two result sets, then apply a time-decay factor so memories that are both relevant and recent enter context first.

    A simplified write-and-recall example:

    1. import sqlite3
    2. conn = sqlite3.connect("agent_memory.db")
    3. conn.execute("CREATE VIRTUAL TABLE IF NOT EXISTS memory USING fts5(content, created_at, tags)")
    4. def remember(text: str, tags: str):
    5. conn.execute("INSERT INTO memory(content, created_at, tags) VALUES(?, datetime('now'), ?)", (text, tags))
    6. conn.commit()
    7. def recall(query: str, limit=5):
    8. rows = conn.execute(
    9. "SELECT content, created_at FROM memory WHERE memory MATCH ? ORDER BY rank LIMIT ?",
    10. (query, limit)
    11. ).fetchall()
    12. return rows

    Practical notes:

    • Structure memory. Besides the body text, store time, source, tags, and other metadata for filtering and decay.
    • Give memory a lifecycle. Periodically archive low-value items and merge duplicates so the index does not bloat.
    • Cap retrieval volume. Limit how many memories and how many tokens are injected, and teach the model to recall on demand.

    Skill Self-Creation: Teaching the Agent to Write Tools

    Built-in tools cover common needs, but real workloads always produce problems with no existing tool. A self-growing agent has the model emit skill code that matches a spec, then registers it after validation so similar problems can reuse it.

    Three safety constraints are non-negotiable:

    1. Sandboxed execution. Run skill code in a restricted environment: limited filesystem, network egress, and resource quotas—no arbitrary system calls.
    2. Human review or automated tests. Run tests against declared I/O before the skill is published.
    3. Versioning and rollback. Each skill has a version and an author (which conversation created it). Failures can be rolled back or disabled quickly.

    Abstract skill registry:

    1. SKILL_REGISTRY = {}
    2. def register_skill(name, func, schema):
    3. SKILL_REGISTRY[name] = {"func": func, "schema": schema}
    4. def invoke(name, **kwargs):
    5. skill = SKILL_REGISTRY.get(name)
    6. if not skill:
    7. raise KeyError(f"skill {name} not found")
    8. # Insert parameter validation and permission checks here
    9. return skill["func"](**kwargs)

    With prompt constraints on the model side (strict function signatures and docstrings), you get a loop: detect a gap → write a skill → register → reuse.

    Scheduling and Multi-Platform Access

    Scheduling makes the agent proactive. A built-in cron-style scheduler supports two kinds of work:

    • Recurring jobs, such as a morning summary of yesterday’s todos or a weekly project digest.
    • One-shot delayed jobs, such as “remind me in two hours to check the deploy.”
    1. @scheduler.cron("0 9 * * *")
    2. def morning_brief():
    3. memories = recall("todo project progress")
    4. report = llm.summarize(memories)
    5. notify_channel(report)

    Multi-platform access determines whether people actually use the agent. A shared message-adapter interface lets one core talk to IM bots, a web console, and a REST API:

    1. class ChannelAdapter(ABC):
    2. @abstractmethod
    3. def on_message(self, handler): ...
    4. @abstractmethod
    5. def send(self, target, text): ...

    Deduplication, auth, rate limits, and multimedia parsing usually take more engineering time than the core loop.

    Practical Advice

    1. Ship a minimal loop first. One channel, keyword memory, and a few built-in tools; expand after the value is proven.
    2. Manage cost and context together. Keep recall tight, tier model calls, and use a lighter model for simple tasks.
    3. Safety first. Skill sandbox, permission allowlists, and audit logs are all required.
    4. Measure growth. Track skill-creation count, autonomous task-completion rate, and similar metrics to see whether the agent is actually getting stronger.

    Persistent runtime, cross-session memory, and skill self-evolution together give an agent the outline of a digital coworker. The architecture is a general pattern: with mature LLM APIs plus object storage, message queues, and containers, teams can land a continuously growing autonomous-agent system on their own stack.