cosmicstack-labs/mercury-agent

Mercury Agent tackles a common headache in AI assistants: how to maintain a persistent, structured memory while keeping control over what the agent can do. Its design revolves around a “Second Brain” that stores and consolidates knowledge persistently using SQLite with full-text search. This memory system enables the agent to remember preferences, goals, and context over time, adjusting its behavior safely and transparently.

What mercury agent is and its architecture

Mercury Agent is an AI assistant implemented in TypeScript, designed for continuous 24/7 operation through a command-line interface or Telegram bot integration. Its core idea is to provide a “soul-driven” AI agent — one that can retain context persistently and act with permission-hardened safeguards.

The architecture centers on several key components:

  • Second Brain memory: A SQLite database with FTS5 extension acts as the persistent knowledge store. The agent automatically extracts and consolidates different memory types — such as facts, preferences, goals — into a structured form.

  • Permission-hardened tools: The agent includes a set of tools it can invoke, but with strict safety controls like shell command blocklists and folder-level scoping. This limits the attack surface and prevents accidental or malicious commands.

  • Human-in-the-loop approval: Before executing potentially risky actions, the agent requests explicit user confirmation.

  • Token budget enforcement and streaming: To maintain API cost control and responsiveness, the agent enforces token limits and streams output in real-time.

  • Extensible skills: The architecture allows the community to contribute new skills, making the agent adaptable to new domains and tasks.

Under the hood, the codebase is TypeScript-based, reflecting a modern JavaScript ecosystem with npm tooling. The agent runs locally or can be deployed with the Telegram interface, giving flexibility in how users interact.

Why the “Second Brain” memory system stands out

Many AI agents operate in a largely stateless manner or rely on ephemeral context windows. Mercury Agent addresses this limitation by implementing a persistent memory that is both structured and searchable.

The use of SQLite with FTS5 for full-text search is a pragmatic choice balancing simplicity, performance, and flexibility. The agent not only stores raw memory items but also performs automatic extraction and consolidation:

  • Automatic extraction: The agent extracts key information and categorizes it into memory types.

  • Conflict resolution and consolidation: When overlapping or conflicting memories arise, the system consolidates them to maintain a consistent agent personality and knowledge base.

This persistent memory allows the agent to adapt over time, remembering user preferences and long-term goals. It also enables auto-conciseness triggers when the memory grows beyond a threshold (notably over 70%).

The tradeoff here is complexity: managing persistent and mutable memory introduces new failure modes and requires careful design to avoid memory bloat or inconsistency.

How to get started with mercury agent

Mercury Agent provides a straightforward quick start to get it up and running.

npx @cosmicstack/mercury-agent

Or install it globally:

npm i -g @cosmicstack/mercury-agent
mercury

On first run, a setup wizard guides you through entering a name, API key, and optionally a Telegram bot token. This setup takes about 30 seconds.

To reconfigure keys or settings later, use:

mercury doctor

This CLI-driven experience lowers the barrier to testing and modifying the agent. Developers looking to contribute can fork the repo, run npm install, make changes, and build with npm run build before testing locally.

verdict: who should use mercury agent

Mercury Agent is a solid choice if you want an AI assistant that goes beyond ephemeral context windows and stateless prompt chains. Its persistent “Second Brain” memory backed by SQLite with full-text search is a meaningful step toward adaptive, personalized AI agents.

The permission-hardened toolset and human approval flow make it suitable for scenarios where safety and control are critical. However, this added complexity means the project demands careful maintenance and understanding of the memory system tradeoffs.

For developers building AI assistants in TypeScript or looking for a robust baseline for long-lived agents with extensible skills, Mercury Agent offers a practical codebase to study and build from. It’s not a simple plug-and-play chatbot but a thoughtful framework balancing persistence, safety, and extensibility.


→ GitHub Repo: cosmicstack-labs/mercury-agent ⭐ 1,026 · TypeScript