Preface¶
When writing code, creating proposals, or having casual chats with DeepSeek Harness (DSH), the context is lost as soon as the session ends. The project background, preferences, and pitfalls you discussed yesterday need to be repeated from scratch today. Switching machines or using a different Agent feels like a “first meeting.”
Plugins can extend capabilities within the DSH ecosystem. This article introduces SGME (ShiGuang Memory Engine) — a memory-type plugin maintained by freehul, with about 9 stars on GitHub under the MIT license. It crystallizes conversations into structured memories, injects them contextually in subsequent sessions, and provides tools like memory_search for the Agent to actively retrieve information.
What is This¶
SGME is a self-hosted memory hub: it captures your conversations with AI, distills them into tagged memories, and sends them back to the Agent contextually in future conversations. Data stays local (Python + SQLite), with no reliance on GPUs or external databases.
As a DSH plugin (npm package name dsh-sgme, current version v0.1.1), it integrates with the Harness via the Cordis SDK: profile injection at the start of a session, tools like memory_search / wiki_search, the /sgme command, per-turn conversation storage, and self-evolving writebacks after session end. It is decoupled from the SGME service itself — the plugin acts as a bridge, while the memory engine requires separate deployment and startup.
Core Features¶
Capture, Distill, Inject¶
The workflow is fully automated and consists of three steps:
- Capture: Conversations are saved as the L0 raw layer (on-disk Markdown, permanently retained).
- Distill: Tagged memories (facts, preferences, project status, decisions, etc.) are extracted from raw conversations, with automatic deduplication, merging, and conflict detection.
- Inject: At the start of each conversation, relevant memories are selected and injected based on the context — casual chats include identity and recent status, coding sessions include tech stacks and project context, avoiding full-load injection.
Profile injection uses structured SQL queries, and the README notes that it does not invoke large models, incurring zero token costs.
Capabilities Exposed on the DSH Side¶
According to the repository’s package.json and README, the plugin primarily provides:
memory_searchtool: Queries memories via the DSH ToolRuntime using natural language, returning bounded, structured results.- Wiki tools:
wiki_search,wiki_pages,wiki_page. /sgmecommand: An in-plugin command entry point.- Per-turn storage and self-evolution: Experience writebacks triggered on turn/end events.
The plugin declares compatibility with DSH 0.1.0-rc.6 and integrates via the harness-profile protocol. Activation requires restarting the profile.
Other Capabilities of the Memory Engine (Service Layer)¶
The following are provided by the SGME service and used indirectly via the plugin or MCP/HTTP:
- Traceable memories: Each memory can be traced back to the original conversation.
- Multi-Agent sharing: Hermes, DSH, and others access the same memory pool.
- Proactive care: Enables Agents to proactively care for users at appropriate times via care signals.
- Personality insights: Builds personality profiles based on conversation patterns, calibrated monthly.
- Unified retrieval: Combines keyword, semantic, and tag-based searches, covering both memory pools and knowledge bases.
- Chinese optimization: Tuned for distillation and recall in Chinese conversations.
- Hybrid retrieval: Combines BM25, vector, and tag filtering, and can run without a vector database.
Installation and Activation¶
SGME is deployed in two layers: first, set up the memory service, then install the DSH plugin.
1. Deploy the SGME Service¶
Requires Python 3.11+. In the SGME repository root directory, run:
# Create a virtual environment
python -m venv .venv
# macOS/Linux: source .venv/bin/activate
# Install dependencies
pip install -e .[dev]
# Start the Server (default port 9910)
python -m sgme
For production use, it is recommended to configure keys in config/.env:
SGME_ADMIN_KEY=<random string>
SGME_AGENT_KEY=<random string>
# Generate: python -c "import secrets;print(secrets.token_hex(32))"
Without configuration, the built-in default key is used, limited to local initial experience; after configuration, the default key becomes invalid. Optional model keys (Zhipu ZHIPU_API_KEY, SiliconFlow SILICONFLOW_API_KEY) are used for distillation and vector retrieval. For details, see docs/guide/免费模型Key申请指南.md in the repository.
2. Install the DSH Plugin¶
The official README provides the installation command:
# Install from npm (recommended)
dsh plugin --profile web add dsh-sgme
# Or install from the GitHub repository
dsh plugin --profile web add github:freehul/sgme
Before starting dsh, ensure the SGME service is visible in the environment variables:
SGME_BASE_URL=...
SGME_AGENT_KEY=...
SGME_ADMIN_KEY=...
The repository provides adapters/dsh/install.py to automatically register the agent and write keys. For full steps, see adapters/dsh/README.md.
Typical Usage¶
Service Health Check¶
Agents or operations can first probe if the service is online:
curl http://localhost:9910/v1/health
The default HTTP port is 9910, and the MCP port is 9913 (http://localhost:9913/mcp). The address can also be read from ~/.sgme/install.json or environment variables SGME_HTTP_URL / SGME_MCP_URL.
Behavior in DSH Sessions¶
After installation and key configuration, restart the DSH profile to activate the plugin. The typical flow is:
- Session start: The plugin automatically injects context-relevant profile memories.
- During conversation: The Agent can call
memory_searchto retrieve historical facts; for questions involving “previously/last time/remember,” it should search first and then answer. - Per-turn end: The current turn is appended and saved; session end triggers
refine_triggerfor asynchronous distillation. - Proactive care: The Agent can consume care signals and respond via SSE (
GET /v1/events/stream) orsignal_pull.
Wiki-related operations are performed via wiki_search, wiki_pages, wiki_page tools; the /sgme command provides a quick in-plugin entry point.
MCP Self-Check¶
If the Agent supports MCP, after connecting, calling agent_onboarding() retrieves the tool list and configuration template (version tag SGME-ONBOARDING-v2). A successful connection is confirmed if there are no 403 errors or timeouts.
Use Cases and Considerations¶
Who is it for?
- Users who rely on DSH for long-term development or daily collaboration and want to preserve context across sessions and devices.
- Users running multiple Agents (DSH, Hermes, etc.) who need a unified memory pool.
- Users who value data localization and are willing to self-host a Python service.
Pre-usage notes:
- Two-layer deployment: Installing only the DSH plugin is insufficient; the SGME service must be started and reachable (default
localhost:9910). - Permissions scope: The plugin declares permissions as
harness:tool,harness:command,network:read;subprocess,shell, andcredentialsare allnone. The plugin runs with the current DSH process permissions. Before installation, review the source code and MIT license to ensure it meets your security requirements. - Version compatibility: The
package.jsonspecifies compatibility with DSH0.1.0-rc.6. Verify versions before upgrading DSH or the plugin. - Key management: Do not rely on the default key in production;
SGME_AGENT_KEY/SGME_ADMIN_KEYshould be securely stored. - Model keys: Memory distillation relies on external LLMs (primary chain Zhipu GLM-4.7-Flash, backup Deepseek); vector retrieval uses SiliconFlow BAAI/bge-m3. If missing,
model_config.missing_keysin/v1/healthwill prompt.
Conclusion¶
SGME transforms “every conversation is a first meeting” into long-term memory that can be crystallized, retrieved, and injected contextually. For DSH users, the dsh-sgme plugin connects the Harness to this local memory engine — once the service is set up, keys are configured, and the plugin is installed, the Agent can continue from where it left off in the next conversation.
- Directory page: SkillHub — freehul/sgme
- Source code and documentation: GitHub — freehul/sgme