home / skills / yonatangross / orchestkit / mem0-sync

mem0-sync skill

/plugins/ork/skills/mem0-sync

This skill automatically synchronizes session context and decisions to Mem0 for seamless cross-session continuity and improved recall.

npx playbooks add skill yonatangross/orchestkit --skill mem0-sync

Review the files below or copy the command above to add this skill to your agents.

Files (10)
SKILL.md
3.2 KB
---
name: mem0-sync
description: Auto-sync session context, decisions, and patterns to Mem0 for cross-session continuity. Use when persisting session memory or syncing decisions.
tags: [mem0, sync, session, memory, continuity, persistence]
user-invocable: true
allowedTools: [Read, Grep, Glob]
auto-invoke: session-end
context: inherit
skills: [recall, remember]
---

# Mem0 Auto-Sync

Automatically synchronize session context to Mem0 for seamless cross-session continuity. This skill executes Python SDK scripts to persist decisions, patterns, and session summaries.

## Overview

- **Automatically**: Invoked at session end by `mem0-pre-compaction-sync.sh` hook
- **Manually**: Run `/mem0-sync` to force sync mid-session
- **After major decisions**: Sync important architectural decisions immediately

## Quick Sync

Execute these script commands based on the sync context provided:

### 1. Session Summary (Always)

```bash
!bash skills/mem0-memory/scripts/crud/add-memory.py \
  --text "Session Summary: {task_summary}" \
  --user-id "{project}-continuity" \
  --metadata '{"type":"session_summary","status":"{status}","has_blockers":{has_blockers},"has_next_steps":{has_next_steps}}' \
  --enable-graph
```

### 2. Pending Decisions (If Any)

For each decision in the decision log that hasn't been synced:

```bash
!bash skills/mem0-memory/scripts/crud/add-memory.py \
  --text "{decision_content}" \
  --user-id "{project}-decisions" \
  --metadata '{"category":"{category}","outcome":"success"}' \
  --enable-graph
```

### 3. Agent Patterns (If Any)

For each agent pattern that was learned:

```bash
!bash skills/mem0-memory/scripts/crud/add-memory.py \
  --text "{pattern_description}" \
  --user-id "{project}-agents" \
  --agent-id "ork:{agent_type}" \
  --metadata '{"category":"{category}","outcome":"{success|failed}"}' \
  --enable-graph
```

### 4. Best Practices (If Generalizable)

For patterns that apply across projects:

```bash
!bash skills/mem0-memory/scripts/crud/add-memory.py \
  --text "{best_practice}" \
  --user-id "orchestkit-global-best-practices" \
  --metadata '{"project":"{project}","category":"{category}","outcome":"success"}' \
  --enable-graph
```

## Sync Protocol

1. **Check availability**: Verify `MEM0_API_KEY` environment variable is set
2. **Read sync state**: Load `.claude/coordination/.decision-sync-state.json`
3. **Execute scripts**: Run `add-memory.py` script for each item
4. **Update sync state**: Mark synced items to prevent duplicates
5. **Confirm completion**: Output sync summary

## Key Patterns

### Idempotent Sync
- Track synced decision IDs in sync state file
- Skip already-synced items
- Handle partial failures gracefully

### Graph Memory
- Always use `enable_graph: true` for relationship extraction
- Mem0 automatically creates entity/relation graphs
- Enables semantic search across related concepts

### Scoped User IDs
- `{project}-continuity`: Session summaries
- `{project}-decisions`: Architectural decisions
- `{project}-agents`: Agent-specific patterns
- `orchestkit-global-best-practices`: Cross-project patterns

## Related Skills

- `recall` - Search and retrieve from Mem0
- `context-compression` - Compress context before sync
- `brainstorming` - Generate decisions worth syncing

Overview

This skill auto-syncs session context, decisions, and learned agent patterns to Mem0 to ensure cross-session continuity. It can run automatically at session end or be invoked manually to persist summaries, decisions, and best practices. Use it to keep a durable, searchable memory graph that supports semantic retrieval and follow-up planning.

How this skill works

The skill runs a set of Python SDK scripts to push items to Mem0: session summaries, unsynced decisions, agent patterns, and generalizable best practices. It checks a local sync state, executes add-memory calls with graph extraction enabled, updates the state to avoid duplicates, and emits a completion summary. Environment checks (MEM0_API_KEY) and idempotent handling prevent repeated writes.

When to use it

  • At the end of a session to persist the session summary and outcomes
  • Immediately after major architectural or product decisions
  • When an agent learns or refines a reusable pattern
  • Before handing work to another team or agent for continuity
  • To capture cross-project best practices for reuse

Best practices

  • Ensure MEM0_API_KEY is set and valid before running sync
  • Run a quick review of the decision log to mark only finalized decisions
  • Keep sync atomic and idempotent: mark items in the state file after successful writes
  • Enable graph extraction for richer semantic relations and search
  • Group generalizable learnings under a global user ID for cross-project discovery

Example use cases

  • Persist a session summary and blockers so the next agent resumes with full context
  • Sync finalized architectural decisions to build an auditable decision log
  • Store newly discovered agent strategies so future runs reuse effective patterns
  • Capture team-level best practices to seed onboarding or project templates
  • Force a mid-session sync after a high-impact milestone using the manual command

FAQ

What happens if the Mem0 API key is missing?

The skill verifies MEM0_API_KEY before running and aborts with an error; set the variable and retry.

How does the skill avoid duplicate entries?

It records synced item IDs in a local sync-state JSON file and skips items already marked as synced.