How memento-teams/memento-skills works
1. What this repo is
Memento-Skills is a self-hosted agent framework centered on “skills” as durable capabilities. The main architectural idea is a closed learning loop: user tasks come in, the agent retrieves or creates a skill, executes it locally, reflects on the outcome, and writes improvements back into the skill library.
2. Top-level runtime surfaces
The system is exposed through three main entry paths: cli/ for terminal use, gui/ for the desktop app, and im/ plus middleware/im/ for messaging-platform integrations. bootstrap.py appears to be the centralized startup entry for wiring config, services, and runtime dependencies.
3. Agent orchestration core
The main reasoning pipeline lives in core/memento_s/. It is split into phases: intent, planning, execution, reflection, and finalize. This is the “brain” that turns a task into a sequence of skill/tool calls and then summarizes the result. The core/protocol/ package provides the event/pipeline abstractions that connect these phases to the rest of the system.
4. Skill system as a separate bounded context
Skills are managed as a first-class subsystem under core/skill/. This includes:
- loader/ for discovering and loading skill packages
- retrieval/ for finding relevant skills via local file, local DB, and remote recall
- execution/ for running a skill safely
- store/ for persistence across file, DB, and vector backends
- embedding/ for semantic indexing
- builder/ for creating or rewriting skills
- market.py for search/download/install flows from the skill catalogue
This separation is important: the agent does not directly own skill persistence or execution; it delegates to the skill subsystem.
5. Skill routing and tool dispatch
core/memento_s/tools.py, core/skill/gateway.py, and core/shared/tools_facade.py are the main boundaries where high-level agent intent becomes concrete tool or skill invocation. Built-in tools in builtin/tools/ provide low-level operations such as bash, grep, Python REPL, file ops, and web access. The architecture distinguishes between agent reasoning and tool execution to keep policy and safety checks centralized.
6. Execution safety and sandboxing
Skill execution is intentionally isolated. middleware/sandbox/ provides the local sandbox environment, while core/skill/execution/policy/ adds pre-execute checks, path validation, tool gating, and recovery policy. There is also explicit loop detection and error recovery in core/skill/execution/. This means the execution boundary is not just a function call; it is a controlled runtime with guardrails.
7. LLM and external API middleware
middleware/llm/ is the model access layer, abstracting multiple providers behind a single client interface. This is where the app connects to OpenAI-compatible endpoints and other providers described in the README. Skill retrieval/execution and agent planning rely on this layer, but the agent core itself stays provider-agnostic.
8. Configuration and persistence
middleware/config/ implements the three-layer configuration model: system defaults, user config, and merged runtime config. middleware/storage/ handles durable application data such as sessions, conversations, skills, and migrations via SQLite/SQLAlchemy-style persistence. This cleanly separates runtime orchestration from long-lived state and makes the repo suitable for local-first deployment.
9. Context and conversation state
core/context/ and shared/chat/ manage short-term and persistent conversation state, scratchpad data, compaction, and runtime memory. These modules sit between the UI/IM surfaces and the agent core, ensuring that multi-turn sessions can be resumed and that long histories can be compacted before they reach the model.
10. Desktop GUI path
The gui/ package is a separate client surface built with Flet. It is not the core engine; it is a presentation layer that talks to the agent/session services through controllers and widgets. Its main responsibilities are chat interaction, session management, workspace browsing, and displaying skill execution feedback.
11. IM gateway and platform adapters
Real-time messaging is handled by middleware/im/gateway/ and the platform-specific adapters under im/ and middleware/im/im_platform/. The gateway layer normalizes inbound messages from Feishu, DingTalk, WeCom, and WeChat into a common protocol, then forwards them to agent workers. This is a distinct integration boundary: platform-specific transport is isolated from agent logic.
12. Built-in skill content
builtin/skills/ contains the shipped capabilities that bootstrap the system: filesystem, web-search, image-analysis, pdf, docx, xlsx, pptx, skill-creator, uv-pip-install, and im-platform. These are packaged as skill bundles with markdown specs and scripts, which the loader/retriever/executor treat as deployable units rather than hardcoded features.
13. Supporting operations and ecosystem
scripts/, build_scripts/, and .github/workflows/ support testing, packaging, OTA/update flows, and release automation. tests/ covers config, context, tool dispatch, skill execution, retrieval, storage, and integrations, which reinforces the repo’s modular boundaries. 3rd/ holds vendored SDK code, notably the WeChat-related SDK used by IM integration.
14. Primary end-to-end data flow
A typical request flows like this: user message enters CLI, GUI, or an IM bridge; session/context state is loaded; the agent pipeline identifies intent and plans; the skill router retrieves or creates a candidate skill; the executor runs it inside the sandbox with policy checks; results are summarized in finalize; then state, metrics, or skill updates are persisted back to storage and the skill library. The key architectural theme is that execution feedback is written back into the capability store, not just returned to the user.
Main entry points: memento_s Agent Core · bootstrap.py Bootstrap · execution Executor · store Skill Store
Components 22
Runtime Surfaces
Entry points for users and external channels.
- Bootstrap · Central startup entry that wires config, services, and runtime dependencies.
bootstrap.py - CLI · Command-line entry and operational commands.
cli - GUI · Flet-based desktop client for chat, sessions, workspace, and feedback.
gui - IM Gateway · Messaging-platform bridge and worker entry for inbound/outbound chat.
im/gateway
Core Engine
Agent orchestration, context, and shared boundaries.
- Agent Core · Main memento_s agent orchestration across intent, planning, execution, reflection, and finalize.
core/memento_s - Protocol · Event, adapter, and pipeline abstractions connecting the agent to the rest of the system.
core/protocol - Context · Short-term and persistent conversation state, scratchpad, compaction, and runtime memory.
core/context - Chat State · Shared chat/session managers used by UI and IM surfaces.
shared/chat - Tool Boundary · Converts agent intent into tool and skill invocation with shared policy/security controls.
core/memento_s/tools.py
Skill System
Discovery, retrieval, execution, storage, and marketplace flows.
- Loader · Discovers and loads skill packages from the filesystem.
core/skill/loader - Retrieval · Finds relevant skills via local file, local DB, and remote recall.
core/skill/retrieval - Executor · Runs skills with loop detection, error recovery, and execution state.
core/skill/execution - Execution Policy · Pre-execute checks, path validation, tool gating, and recovery policy for skills.
core/skill/execution/policy - Skill Store · Persistent storage for skills across files, database, and vectors.
core/skill/store - Skill Builder · Creates, rewrites, and packages skills back into durable capabilities.
core/skill/builder - Skill Market · Search, download, install, and uninstall flows for skill catalogue content.
core/skill/market.py
Middleware
Config, LLM access, sandboxing, and persistence infrastructure.
- LLM Layer · Provider-agnostic client layer for chat and embedding model access.
middleware/llm - Config · Three-layer configuration model: system defaults, user config, and merged runtime config.
middleware/config - Storage · SQLite/SQLAlchemy-backed persistence for sessions, conversations, skills, and migrations.
middleware/storage - Sandbox · Local sandbox environment used to execute skills safely.
middleware/sandbox
Builtin Capabilities
Shipped tools and packaged skill bundles.
- Builtin Tools · Core operations such as bash, grep, Python REPL, file ops, and web access.
builtin/tools - Builtin Skills · Packaged capabilities such as filesystem, web-search, document, media, and skill-creator skills.
builtin/skills
Connections 28
- Bootstrap → CLI: starts · Bootstraps terminal runtime.
- Bootstrap → GUI: starts · Bootstraps desktop runtime.
- Bootstrap → IM Gateway: starts · Bootstraps messaging gateway runtime.
- CLI → Agent Core: invokes · CLI submits tasks to the agent pipeline.
- GUI → Chat State: uses · GUI manages chat and session state through shared managers.
- GUI → Agent Core: drives · GUI forwards user tasks into the agent core.
- IM Gateway → Chat State: updates · IM gateway persists and resumes conversation state.
- IM Gateway → Agent Core: routes to · Inbound messages are routed into the agent runtime.
- Agent Core → Protocol: emits · Agent phases communicate through the event pipeline.
- Agent Core → Context: reads/writes · Agent loads and updates session and scratchpad state.
- Agent Core → Tool Boundary: calls · Reasoning pipeline delegates concrete operations to tool/skill dispatch.
- Tool Boundary → Builtin Tools: dispatches · High-level intent resolves to built-in tool execution.
- Tool Boundary → Loader: resolves · Dispatch may load a skill package before execution.
- Loader → Skill Store: loads from · Loaded skills come from persistent store backends.
- Retrieval → Skill Store: queries · Retrieval searches file, DB, and vector-backed stores.
- Retrieval → LLM Layer: embeds via · Semantic recall uses model/embedding services.
- Executor → Sandbox: runs in · Skills execute inside an isolated sandbox boundary.
- Executor → Execution Policy: protected by · Execution is guarded by policy checks and recovery logic.
- Executor → Builtin Tools: uses · Skill code can invoke low-level tools through controlled bridging.
- Skill Builder → Skill Store: writes · Skill creation and rewrite flows persist back into the library.
- Skill Market → Skill Store: installs into · Marketplace flows land in the local skill store.
- Skill Market → LLM Layer: assists · Catalogue and generation flows may rely on model services.
- Config → Bootstrap: configures · Runtime configuration feeds startup wiring.
- Storage → Context: persists · Session, conversation, and runtime state are durable across runs.
- Storage → Chat State: backs · Shared chat/session managers depend on durable storage.
- LLM Layer → Agent Core: serves · Agent planning and reflection depend on model access.
- Builtin Skills → Loader: discovered by · Shipped skill bundles are loaded like deployable units.
- Builtin Skills → Executor: executed by · Builtin skill bundles are run through the same executor path.