Skip to content

feat(memory): add memory-graphiti extension with dual-backend support - #26925

Closed
supmo668 wants to merge 1 commit into
openclaw:mainfrom
supmo668:feat/graphiti
Closed

supmo668 wants to merge 1 commit into
openclaw:mainfrom
supmo668:feat/graphiti

Conversation

@supmo668

@supmo668 supmo668 commented Feb 25, 2026 •

Copy link
Copy Markdown

Summary

  • Problem: OpenClaw lacks a graph-based knowledge memory plugin that can extract entities, relationships, and temporal facts from conversations.
  • Why it matters: Graph memory enables agents to build persistent, structured knowledge that improves over time — capturing not just facts but how they relate and when they change.
  • What changed: New memory-graphiti extension in extensions/memory-graphiti/ with dual-backend support (Zep Cloud managed service + self-hosted Graphiti REST API), auto-capture/recall hooks, search tools, and CLI.
  • What did NOT change (scope boundary): No changes to core memory interfaces, existing memory-lancedb plugin, or any other plugins.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Related: Graphiti knowledge graph integration for OpenClaw memory slot

User-visible / Behavior Changes

  • New memory-graphiti plugin available in the memory slot
  • Configurable via apiKey (Zep Cloud) or serverUrl (self-hosted Graphiti)
  • Auto-capture: conversations are automatically sent to the knowledge graph after each agent turn
  • Auto-recall: relevant facts are injected as context before each agent turn
  • Two new agent tools: graphiti_search (search knowledge graph) and graphiti_episodes (retrieve recent episodes)
  • New CLI command: openclaw graphiti status to check connectivity
  • Group ID strategies: channel-sender (default, per-user per-channel), session (per-thread), static (shared graph)

Security Impact (required)

  • New permissions/capabilities? Yes — new memory plugin with network access to Zep Cloud or self-hosted Graphiti
  • Secrets/tokens handling changed? Yes — apiKey field marked sensitive: true, supports ${ENV_VAR} resolution
  • New/changed network calls? Yes — calls to Zep Cloud API (api.getzep.com) or self-hosted Graphiti REST API
  • Command/tool execution surface changed? Yes — two new agent tools (graphiti_search, graphiti_episodes)
  • Data access scope changed? No — operates within the memory plugin slot, same as existing memory plugins
  • Risk + mitigation: API key stored in config with sensitive: true flag. Environment variable resolution prevents hardcoded secrets. All network calls go to user-configured endpoints only.

Repro + Verification

Environment

  • OS: Linux (WSL2)
  • Runtime/container: Node.js (pnpm workspace)
  • Model/provider: N/A (plugin infrastructure)
  • Integration/channel: Zep Cloud + self-hosted Graphiti
  • Relevant config (redacted): { "apiKey": "${GETZEP_API_KEY}" }

Steps

  1. Configure plugin with Zep Cloud API key or self-hosted Graphiti URL
  2. Send messages through an agent
  3. Verify facts are captured and recalled

Expected

  • Messages captured into knowledge graph
  • Relevant facts injected before agent turns
  • Search tools return graph entities/edges

Actual

  • Verified via 49 unit tests and 6 Zep Cloud integration tests

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

49 unit tests covering: config parsing (15), client factory (3), group ID derivation (9), message extraction (7), fact formatting (3), REST client (12).
6 integration tests against live Zep Cloud: healthcheck, addMessages, getEpisodes (with polling), searchFacts.

Human Verification (required)

  • Verified scenarios: Unit tests pass, integration tests pass against live Zep Cloud API
  • Edge cases checked: Config validation (missing keys, invalid strategies, env var resolution), dual-backend auto-detection, user creation idempotency (400 + 409 handling), empty message arrays, content block extraction
  • What you did not verify: Self-hosted Graphiti backend (Railway deployment has missing OPENAI_API_KEY for entity extraction)

Compatibility / Migration

  • Backward compatible? Yes — new extension, no changes to existing code
  • Config/env changes? Yes — new GETZEP_API_KEY or GRAPHITI_SERVER_URL env vars needed
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: Remove memory-graphiti from plugin slot config, or uninstall extension
  • Files/config to restore: Only extensions/memory-graphiti/ directory — fully self-contained
  • Known bad symptoms reviewers should watch for: Network timeouts to Zep Cloud, missing API key errors

Risks and Mitigations

  • Risk: Zep Cloud SDK API changes could break cloud client
    • Mitigation: SDK version pinned to ^3.16.0, integration tests validate live API
  • Risk: Self-hosted Graphiti REST API schema drift
    • Mitigation: REST client uses minimal endpoint surface; typed response interfaces

Greptile Summary

Added graph-based memory plugin with dual-backend support (Zep Cloud managed service + self-hosted Graphiti). Implements auto-capture/recall hooks, search tools, and CLI commands.

Key changes:

  • New memory-graphiti extension in extensions/memory-graphiti/ with comprehensive configuration
  • Client abstraction supports both Zep Cloud SDK (@getzep/zep-cloud) and self-hosted REST API
  • Auto-capture hook stores conversations after agent turns, auto-recall injects relevant facts before agent turns
  • Two agent tools: graphiti_search (query knowledge graph) and graphiti_episodes (retrieve conversation history)
  • CLI command openclaw graphiti status for connectivity checks
  • 49 unit tests + 6 integration tests against live Zep Cloud API

Issues found:

  • Inconsistent userId handling between auto-recall and auto-capture hooks (line 294) causes facts to be stored under one ID but searched under another when cfg.userId is explicitly set

Code quality:

  • Good separation of concerns with MemoryClient interface
  • Proper security handling (sensitive config fields, HTML escaping for prompt injection)
  • Comprehensive test coverage and clear documentation
  • Follows OpenClaw plugin conventions (workspace deps, ESM imports, TypeScript strict mode)

Confidence Score: 3/5

  • Safe to merge after fixing the userId handling bug in auto-recall hook
  • Score reflects one functional bug (inconsistent userId handling) that would cause incorrect behavior when cfg.userId is explicitly set. However, the fix is trivial (one line change), test coverage is comprehensive (49 unit + 6 integration tests), security handling is proper (sensitive fields, HTML escaping), and the overall architecture is clean with good separation of concerns. The bug is localized and doesn't affect the default configuration.
  • Pay close attention to extensions/memory-graphiti/index.ts line 294 - the userId consistency fix is critical for users who explicitly configure a fixed userId

Last reviewed commit: 335e258

@supmo668

Copy link
Copy Markdown
Author

@greptileai review

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

12 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread extensions/memory-graphiti/index.ts Outdated
}

// Derive group_id from context, fall back to last known
const groupId = ctx.sessionKey ? deriveGroupId(ctx, cfg) : lastGroupId;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsistent userId handling: when cfg.userId is explicitly set, agent_end uses it directly (line 327), but this line ignores it and derives from context

Facts captured under cfg.userId won't be recalled if ctx.sessionKey is present.

Suggested change
const groupId = ctx.sessionKey ? deriveGroupId(ctx, cfg) : lastGroupId;
const groupId = cfg.userId ?? (ctx.sessionKey ? deriveGroupId(ctx, cfg) : lastGroupId);
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/memory-graphiti/index.ts
Line: 294

Comment:
inconsistent userId handling: when `cfg.userId` is explicitly set, `agent_end` uses it directly (line 327), but this line ignores it and derives from context

Facts captured under `cfg.userId` won't be recalled if `ctx.sessionKey` is present.

```suggestion
        const groupId = cfg.userId ?? (ctx.sessionKey ? deriveGroupId(ctx, cfg) : lastGroupId);
```

How can I resolve this? If you propose a fix, please make it concise.

Graph-based knowledge memory plugin using Graphiti for temporally-aware
knowledge graphs. Supports two backends:

- Zep Cloud (managed) via @getzep/zep-cloud SDK
- Self-hosted Graphiti via REST API

Features: auto-capture (agent_end), auto-recall (before_agent_start),
graphiti_search/graphiti_episodes tools, CLI status command, and
configurable group ID strategies (channel-sender, session, static).

Includes 49 unit tests and 6 integration tests against Zep Cloud.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@supmo668

Copy link
Copy Markdown
Author

Addressed greptile review feedback:

Fixed inconsistent userId handling — when cfg.userId is explicitly set, it's now honoured in all code paths:

  • auto-recall (before_agent_start): cfg.userId ?? deriveGroupId(ctx, cfg) (was missing cfg.userId check)
  • graphiti_search tool: cfg.userId ?? lastGroupId (was using only lastGroupId)
  • graphiti_episodes tool: cfg.userId ?? lastGroupId (was using only lastGroupId)
  • auto-capture (agent_end): already correct (cfg.userId ?? deriveGroupId(ctx, cfg))

All 49 unit tests pass.

@thewilloftheshadow thewilloftheshadow added the r: third-party-extension Auto-close: third-party plugins/capabilities belong on ClawHub. label Feb 28, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Please make this as a third-party plugin that you maintain yourself in your own repo. Docs: https://docs.openclaw.ai/plugin. Feel free to open a PR after to add it to our community plugins page: https://docs.openclaw.ai/plugins/community

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

r: third-party-extension Auto-close: third-party plugins/capabilities belong on ClawHub. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants