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:
- 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.
- Cross-session memory. Memory is not dropped at session end. It is stored durably and retrieved in any later conversation.
- 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.
[Messaging / CLI / API]│[Access-layer adapters]│[Core orchestrator] ──► [Skill layer: built-in tools + custom skills]│[Memory layer: retrieval + persistence]│[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:
- 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.
- Semantic search. Embed memory items and recall semantically related content even when wording differs.
- 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:
import sqlite3conn = sqlite3.connect("agent_memory.db")conn.execute("CREATE VIRTUAL TABLE IF NOT EXISTS memory USING fts5(content, created_at, tags)")def remember(text: str, tags: str):conn.execute("INSERT INTO memory(content, created_at, tags) VALUES(?, datetime('now'), ?)", (text, tags))conn.commit()def recall(query: str, limit=5):rows = conn.execute("SELECT content, created_at FROM memory WHERE memory MATCH ? ORDER BY rank LIMIT ?",(query, limit)).fetchall()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:
- Sandboxed execution. Run skill code in a restricted environment: limited filesystem, network egress, and resource quotas—no arbitrary system calls.
- Human review or automated tests. Run tests against declared I/O before the skill is published.
- 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:
SKILL_REGISTRY = {}def register_skill(name, func, schema):SKILL_REGISTRY[name] = {"func": func, "schema": schema}def invoke(name, **kwargs):skill = SKILL_REGISTRY.get(name)if not skill:raise KeyError(f"skill {name} not found")# Insert parameter validation and permission checks herereturn 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.”
@scheduler.cron("0 9 * * *")def morning_brief():memories = recall("todo project progress")report = llm.summarize(memories)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:
class ChannelAdapter(ABC):@abstractmethoddef on_message(self, handler): ...@abstractmethoddef send(self, target, text): ...
Deduplication, auth, rate limits, and multimedia parsing usually take more engineering time than the core loop.
Practical Advice
- Ship a minimal loop first. One channel, keyword memory, and a few built-in tools; expand after the value is proven.
- Manage cost and context together. Keep recall tight, tier model calls, and use a lighter model for simple tasks.
- Safety first. Skill sandbox, permission allowlists, and audit logs are all required.
- 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.
