# memento-teams/memento-skills architecture

> Architecture diagram of the GitHub repository memento-teams/memento-skills, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/memento-teams/memento-skills
- Repository: https://github.com/memento-teams/memento-skills

## Overview

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: [`core/memento_s`](https://github.com/memento-teams/memento-skills/tree/main/core/memento_s) (Agent Core), [`bootstrap.py`](https://github.com/memento-teams/memento-skills/blob/main/bootstrap.py) (Bootstrap), [`core/skill/execution`](https://github.com/memento-teams/memento-skills/tree/main/core/skill/execution) (Executor), [`core/skill/store`](https://github.com/memento-teams/memento-skills/tree/main/core/skill/store) (Skill Store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_surfaces["Runtime Surfaces"]
  node_bootstrap["Bootstrap<br/>startup wiring<br/>[bootstrap.py]"]
  node_cli["CLI<br/>terminal surface"]
  node_gui["GUI<br/>desktop surface"]
  node_im_gateway["IM Gateway<br/>messaging surface"]
end

subgraph group_core["Core Engine"]
  node_agent_core(("Agent Core<br/>reasoning pipeline"))
  node_protocol["Protocol<br/>event pipeline"]
  node_context[("Context<br/>session state")]
  node_chat_shared[("Chat State<br/>conversation state")]
  node_tool_boundary{{"Tool Boundary<br/>dispatch boundary<br/>[tools.py]"}}
end

subgraph group_skills["Skill System"]
  node_skill_loader["Loader<br/>skill discovery"]
  node_skill_retrieval["Retrieval<br/>skill recall"]
  node_skill_execution(("Executor<br/>skill runtime"))
  node_skill_policy{{"Execution Policy<br/>safety checks"}}
  node_skill_store[("Skill Store<br/>skill persistence")]
  node_skill_builder["Skill Builder<br/>skill authoring"]
  node_skill_market["Skill Market<br/>catalog flow<br/>[market.py]"]
end

subgraph group_middleware["Middleware"]
  node_llm_middleware["LLM Layer<br/>model access"]
  node_config_middleware["Config"]
  node_storage_middleware[("Storage")]
  node_sandbox{{"Sandbox<br/>isolated runtime"}}
end

subgraph group_builtin["Builtin Capabilities"]
  node_builtin_tools["Builtin Tools<br/>low-level tools"]
  node_builtin_skills["Builtin Skills<br/>shipped capabilities"]
end

node_bootstrap -->|"starts"| node_cli
node_bootstrap -->|"starts"| node_gui
node_bootstrap -->|"starts"| node_im_gateway
node_cli -->|"invokes"| node_agent_core
node_gui -->|"uses"| node_chat_shared
node_gui -->|"drives"| node_agent_core
node_im_gateway -->|"updates"| node_chat_shared
node_im_gateway -->|"routes to"| node_agent_core
node_agent_core -->|"emits"| node_protocol
node_agent_core -->|"reads/writes"| node_context
node_agent_core -->|"calls"| node_tool_boundary
node_tool_boundary -->|"dispatches"| node_builtin_tools
node_tool_boundary -->|"resolves"| node_skill_loader
node_skill_loader -->|"loads from"| node_skill_store
node_skill_retrieval -->|"queries"| node_skill_store
node_skill_retrieval -->|"embeds via"| node_llm_middleware
node_skill_execution -->|"runs in"| node_sandbox
node_skill_execution -->|"protected by"| node_skill_policy
node_skill_execution -->|"uses"| node_builtin_tools
node_skill_builder -->|"writes"| node_skill_store
node_skill_market -->|"installs into"| node_skill_store
node_skill_market -.->|"assists"| node_llm_middleware
node_config_middleware -->|"configures"| node_bootstrap
node_storage_middleware -->|"persists"| node_context
node_storage_middleware -->|"backs"| node_chat_shared
node_llm_middleware -->|"serves"| node_agent_core
node_builtin_skills -->|"discovered by"| node_skill_loader
node_builtin_skills -->|"executed by"| node_skill_execution

click node_bootstrap "https://github.com/memento-teams/memento-skills/blob/main/bootstrap.py"
click node_cli "https://github.com/memento-teams/memento-skills/tree/main/cli"
click node_gui "https://github.com/memento-teams/memento-skills/tree/main/gui"
click node_im_gateway "https://github.com/memento-teams/memento-skills/tree/main/im/gateway"
click node_agent_core "https://github.com/memento-teams/memento-skills/tree/main/core/memento_s"
click node_protocol "https://github.com/memento-teams/memento-skills/tree/main/core/protocol"
click node_context "https://github.com/memento-teams/memento-skills/tree/main/core/context"
click node_chat_shared "https://github.com/memento-teams/memento-skills/tree/main/shared/chat"
click node_tool_boundary "https://github.com/memento-teams/memento-skills/blob/main/core/memento_s/tools.py"
click node_skill_loader "https://github.com/memento-teams/memento-skills/tree/main/core/skill/loader"
click node_skill_retrieval "https://github.com/memento-teams/memento-skills/tree/main/core/skill/retrieval"
click node_skill_execution "https://github.com/memento-teams/memento-skills/tree/main/core/skill/execution"
click node_skill_policy "https://github.com/memento-teams/memento-skills/tree/main/core/skill/execution/policy"
click node_skill_store "https://github.com/memento-teams/memento-skills/tree/main/core/skill/store"
click node_skill_builder "https://github.com/memento-teams/memento-skills/tree/main/core/skill/builder"
click node_skill_market "https://github.com/memento-teams/memento-skills/blob/main/core/skill/market.py"
click node_llm_middleware "https://github.com/memento-teams/memento-skills/tree/main/middleware/llm"
click node_config_middleware "https://github.com/memento-teams/memento-skills/tree/main/middleware/config"
click node_storage_middleware "https://github.com/memento-teams/memento-skills/tree/main/middleware/storage"
click node_sandbox "https://github.com/memento-teams/memento-skills/tree/main/middleware/sandbox"
click node_builtin_tools "https://github.com/memento-teams/memento-skills/tree/main/builtin/tools"
click node_builtin_skills "https://github.com/memento-teams/memento-skills/tree/main/builtin/skills"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_bootstrap,node_cli,node_gui,node_im_gateway toneBlue
class node_agent_core,node_protocol,node_context,node_chat_shared,node_tool_boundary toneAmber
class node_skill_loader,node_skill_retrieval,node_skill_execution,node_skill_policy,node_skill_store,node_skill_builder,node_skill_market toneMint
class node_llm_middleware,node_config_middleware,node_storage_middleware,node_sandbox toneRose
class node_builtin_tools,node_builtin_skills toneIndigo
```

## Components

### Runtime Surfaces

Entry points for users and external channels.

- [Bootstrap](https://github.com/memento-teams/memento-skills/blob/main/bootstrap.py): startup wiring · Central startup entry that wires config, services, and runtime dependencies. · `bootstrap.py`
- [CLI](https://github.com/memento-teams/memento-skills/tree/main/cli): terminal surface · Command-line entry and operational commands. · `cli`
- [GUI](https://github.com/memento-teams/memento-skills/tree/main/gui): desktop surface · Flet-based desktop client for chat, sessions, workspace, and feedback. · `gui`
- [IM Gateway](https://github.com/memento-teams/memento-skills/tree/main/im/gateway): messaging surface · Messaging-platform bridge and worker entry for inbound/outbound chat. · `im/gateway`

### Core Engine

Agent orchestration, context, and shared boundaries.

- [Agent Core](https://github.com/memento-teams/memento-skills/tree/main/core/memento_s): reasoning pipeline · Main memento_s agent orchestration across intent, planning, execution, reflection, and finalize. · `core/memento_s`
- [Protocol](https://github.com/memento-teams/memento-skills/tree/main/core/protocol): event pipeline · Event, adapter, and pipeline abstractions connecting the agent to the rest of the system. · `core/protocol`
- [Context](https://github.com/memento-teams/memento-skills/tree/main/core/context): session state · Short-term and persistent conversation state, scratchpad, compaction, and runtime memory. · `core/context`
- [Chat State](https://github.com/memento-teams/memento-skills/tree/main/shared/chat): conversation state · Shared chat/session managers used by UI and IM surfaces. · `shared/chat`
- [Tool Boundary](https://github.com/memento-teams/memento-skills/blob/main/core/memento_s/tools.py): dispatch 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](https://github.com/memento-teams/memento-skills/tree/main/core/skill/loader): skill discovery · Discovers and loads skill packages from the filesystem. · `core/skill/loader`
- [Retrieval](https://github.com/memento-teams/memento-skills/tree/main/core/skill/retrieval): skill recall · Finds relevant skills via local file, local DB, and remote recall. · `core/skill/retrieval`
- [Executor](https://github.com/memento-teams/memento-skills/tree/main/core/skill/execution): skill runtime · Runs skills with loop detection, error recovery, and execution state. · `core/skill/execution`
- [Execution Policy](https://github.com/memento-teams/memento-skills/tree/main/core/skill/execution/policy): safety checks · Pre-execute checks, path validation, tool gating, and recovery policy for skills. · `core/skill/execution/policy`
- [Skill Store](https://github.com/memento-teams/memento-skills/tree/main/core/skill/store): skill persistence · Persistent storage for skills across files, database, and vectors. · `core/skill/store`
- [Skill Builder](https://github.com/memento-teams/memento-skills/tree/main/core/skill/builder): skill authoring · Creates, rewrites, and packages skills back into durable capabilities. · `core/skill/builder`
- [Skill Market](https://github.com/memento-teams/memento-skills/blob/main/core/skill/market.py): catalog flow · Search, download, install, and uninstall flows for skill catalogue content. · `core/skill/market.py`

### Middleware

Config, LLM access, sandboxing, and persistence infrastructure.

- [LLM Layer](https://github.com/memento-teams/memento-skills/tree/main/middleware/llm): model access · Provider-agnostic client layer for chat and embedding model access. · `middleware/llm`
- [Config](https://github.com/memento-teams/memento-skills/tree/main/middleware/config): runtime config · Three-layer configuration model: system defaults, user config, and merged runtime config. · `middleware/config`
- [Storage](https://github.com/memento-teams/memento-skills/tree/main/middleware/storage): durable storage · SQLite/SQLAlchemy-backed persistence for sessions, conversations, skills, and migrations. · `middleware/storage`
- [Sandbox](https://github.com/memento-teams/memento-skills/tree/main/middleware/sandbox): isolated runtime · Local sandbox environment used to execute skills safely. · `middleware/sandbox`

### Builtin Capabilities

Shipped tools and packaged skill bundles.

- [Builtin Tools](https://github.com/memento-teams/memento-skills/tree/main/builtin/tools): low-level tools · Core operations such as bash, grep, Python REPL, file ops, and web access. · `builtin/tools`
- [Builtin Skills](https://github.com/memento-teams/memento-skills/tree/main/builtin/skills): shipped capabilities · Packaged capabilities such as filesystem, web-search, document, media, and skill-creator skills. · `builtin/skills`

## Connections

- 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.
