hermes-mindgraph-plugin 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,170 @@
1
+ """MindGraph semantic graph memory plugin for Hermes Agent.
2
+
3
+ Bridges MindGraph (https://mindgraph.cloud) into Hermes Agent's plugin
4
+ lifecycle hooks, giving any Hermes-powered agent persistent semantic memory
5
+ across sessions.
6
+
7
+ Install:
8
+ pip install hermes-mindgraph-plugin
9
+
10
+ Configure:
11
+ Set MINDGRAPH_API_KEY in ~/.hermes/.env (get one at https://mindgraph.cloud)
12
+
13
+ The plugin is auto-discovered via the ``hermes_agent.plugins`` entry point.
14
+ It can also be installed manually by copying this package to
15
+ ``~/.hermes/plugins/mindgraph/`` with an accompanying ``plugin.yaml``.
16
+
17
+ Hooks registered:
18
+ on_session_start — Opens a MindGraph session, pre-fetches context.
19
+ pre_llm_call — Injects session context (goals, decisions, policies)
20
+ on first turn; score-gated semantic retrieval every turn.
21
+ on_session_end — Closes the MindGraph session.
22
+ """
23
+
24
+ __version__ = "0.1.0"
25
+
26
+ import logging
27
+ from typing import Optional
28
+
29
+ logger = logging.getLogger(__name__)
30
+
31
+ # ---------------------------------------------------------------------------
32
+ # State — per-process, reset on session_start
33
+ # ---------------------------------------------------------------------------
34
+
35
+ _session_context_cache: Optional[str] = None
36
+ _session_started: bool = False
37
+
38
+
39
+ def _is_available() -> bool:
40
+ """Check if MindGraph is configured and ready."""
41
+ try:
42
+ from tools.mindgraph_tool import check_requirements
43
+ return check_requirements()
44
+ except ImportError:
45
+ return False
46
+
47
+
48
+ # ---------------------------------------------------------------------------
49
+ # Hook callbacks
50
+ # ---------------------------------------------------------------------------
51
+
52
+ def _on_session_start(
53
+ *, session_id: str = "", model: str = "", platform: str = "", **kw
54
+ ):
55
+ """Open a MindGraph session and pre-fetch session context."""
56
+ global _session_context_cache, _session_started
57
+ _session_context_cache = None
58
+ _session_started = False
59
+
60
+ if not _is_available():
61
+ return
62
+
63
+ # Open session
64
+ try:
65
+ from tools.mindgraph_tool import auto_open_session
66
+
67
+ label = f"hermes-{session_id[:8]}" if session_id else "hermes-session"
68
+ sid = auto_open_session(label=label)
69
+ if sid:
70
+ logger.info("MindGraph session opened: %s", sid)
71
+ _session_started = True
72
+ except Exception as exc:
73
+ logger.debug("MindGraph session open failed (non-fatal): %s", exc)
74
+
75
+ # Pre-fetch session context (goals, decisions, policies, weak claims)
76
+ # so it's ready for the first pre_llm_call without blocking.
77
+ try:
78
+ from tools.mindgraph_tool import retrieve_session_context
79
+
80
+ _session_context_cache = retrieve_session_context()
81
+ except Exception as exc:
82
+ logger.debug("MindGraph session context prefetch failed: %s", exc)
83
+
84
+
85
+ def _pre_llm_call(
86
+ *,
87
+ session_id: str = "",
88
+ user_message: str = "",
89
+ conversation_history: list = None,
90
+ is_first_turn: bool = False,
91
+ model: str = "",
92
+ platform: str = "",
93
+ **kw,
94
+ ) -> dict | None:
95
+ """Return context to inject into the agent's ephemeral system prompt.
96
+
97
+ First turn: cached session context (goals, decisions, policies, weak claims).
98
+ Every turn: score-gated semantic retrieval for topic relevance.
99
+
100
+ Returns ``{"context": "..."}`` or ``None``.
101
+ """
102
+ if not _is_available():
103
+ return None
104
+
105
+ parts: list[str] = []
106
+
107
+ # --- Session context (first turn only) ---
108
+ if is_first_turn and _session_context_cache:
109
+ parts.append(_session_context_cache)
110
+ # Don't clear the cache — the gateway creates a fresh AIAgent per
111
+ # message, so is_first_turn may be True on every gateway turn for
112
+ # continuing sessions. The cache stays valid for the process
113
+ # lifetime and is reset on the next on_session_start.
114
+
115
+ # --- Per-turn semantic retrieval ---
116
+ if user_message:
117
+ try:
118
+ from tools.mindgraph_tool import proactive_graph_retrieve
119
+
120
+ turn_ctx = proactive_graph_retrieve(user_message)
121
+ if turn_ctx:
122
+ parts.append(turn_ctx)
123
+ except Exception as exc:
124
+ logger.debug("MindGraph turn retrieval failed (non-fatal): %s", exc)
125
+
126
+ if parts:
127
+ return {"context": "\n\n".join(parts)}
128
+ return None
129
+
130
+
131
+ def _on_session_end(
132
+ *,
133
+ session_id: str = "",
134
+ completed: bool = True,
135
+ interrupted: bool = False,
136
+ model: str = "",
137
+ platform: str = "",
138
+ **kw,
139
+ ):
140
+ """Close the MindGraph session."""
141
+ global _session_context_cache, _session_started
142
+
143
+ if not _session_started:
144
+ return
145
+
146
+ try:
147
+ from tools.mindgraph_tool import auto_close_session
148
+
149
+ auto_close_session(
150
+ summary=(
151
+ f"Session {session_id[:8] if session_id else 'unknown'} "
152
+ f"({'completed' if completed else 'interrupted' if interrupted else 'ended'})"
153
+ ),
154
+ )
155
+ _session_started = False
156
+ _session_context_cache = None
157
+ except Exception as exc:
158
+ logger.debug("MindGraph session close failed (non-fatal): %s", exc)
159
+
160
+
161
+ # ---------------------------------------------------------------------------
162
+ # Plugin entry point — called by Hermes plugin discovery
163
+ # ---------------------------------------------------------------------------
164
+
165
+ def register(ctx):
166
+ """Register MindGraph memory hooks with the Hermes plugin system."""
167
+ ctx.register_hook("on_session_start", _on_session_start)
168
+ ctx.register_hook("pre_llm_call", _pre_llm_call)
169
+ ctx.register_hook("on_session_end", _on_session_end)
170
+ logger.info("MindGraph memory plugin registered (3 lifecycle hooks)")
File without changes
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: hermes-mindgraph-plugin
3
+ Version: 0.1.0
4
+ Summary: MindGraph semantic graph memory plugin for Hermes Agent
5
+ Project-URL: Homepage, https://mindgraph.cloud
6
+ Project-URL: Repository, https://github.com/shuruheel/hermes-mindgraph-plugin
7
+ Project-URL: Issues, https://github.com/shuruheel/hermes-mindgraph-plugin/issues
8
+ Author-email: Shan Rizvi <shan@rizvi.nu>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agent,hermes,memory,mindgraph,plugin,semantic-graph
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: mindgraph-sdk>=0.1.4
22
+ Description-Content-Type: text/markdown
23
+
24
+ # hermes-mindgraph-plugin
25
+
26
+ Semantic graph memory plugin for [Hermes Agent](https://github.com/NousResearch/hermes-agent). Gives any Hermes-powered agent persistent memory across sessions using [MindGraph](https://mindgraph.cloud).
27
+
28
+ ## What it does
29
+
30
+ This plugin hooks into Hermes Agent's lifecycle to provide:
31
+
32
+ - **Session context** — Active goals, open decisions, governance policies, weak claims, and user profile are injected into the agent's context at the start of each conversation.
33
+ - **Per-turn retrieval** — Score-gated semantic search finds topic-relevant knowledge from the graph and injects it ephemerally (never persisted to conversation history, no prompt cache breakage).
34
+ - **Session lifecycle** — Automatically opens and closes MindGraph sessions aligned with Hermes conversations.
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ pip install hermes-mindgraph-plugin
40
+ ```
41
+
42
+ The plugin is auto-discovered via the `hermes_agent.plugins` entry point. No configuration beyond the API key is needed.
43
+
44
+ ## Setup
45
+
46
+ 1. Get a MindGraph API key at [mindgraph.cloud](https://mindgraph.cloud)
47
+ 2. Add it to your Hermes environment:
48
+
49
+ ```bash
50
+ echo "MINDGRAPH_API_KEY=mg_your_key_here" >> ~/.hermes/.env
51
+ ```
52
+
53
+ 3. Verify the plugin is loaded:
54
+
55
+ ```bash
56
+ hermes plugins list
57
+ ```
58
+
59
+ ## How it works
60
+
61
+ The plugin registers three [lifecycle hooks](https://hermes.nousresearch.com/docs/user-guide/features/plugins):
62
+
63
+ | Hook | When | What |
64
+ |------|------|------|
65
+ | `on_session_start` | New conversation begins | Opens a MindGraph session, pre-fetches goals/decisions/policies |
66
+ | `pre_llm_call` | Before each agent turn | Returns session context (first turn) + semantic retrieval (every turn) |
67
+ | `on_session_end` | Conversation ends | Closes the MindGraph session |
68
+
69
+ Context is injected **ephemerally** into the system prompt — it's never persisted to the session database and doesn't break Anthropic's prompt cache prefix.
70
+
71
+ All MindGraph API calls are wrapped in try/except. A MindGraph failure never breaks the conversation.
72
+
73
+ ## Manual install (alternative)
74
+
75
+ If you prefer not to use pip, copy the plugin directly:
76
+
77
+ ```bash
78
+ mkdir -p ~/.hermes/plugins/mindgraph
79
+ # Copy plugin.yaml and __init__.py into that directory
80
+ ```
81
+
82
+ See the `plugin.yaml` in this repo for the manifest format.
83
+
84
+ ## Development
85
+
86
+ ```bash
87
+ git clone https://github.com/shuruheel/hermes-mindgraph-plugin
88
+ cd hermes-mindgraph-plugin
89
+ pip install -e ".[dev]"
90
+ pytest
91
+ ```
92
+
93
+ ## Requirements
94
+
95
+ - Hermes Agent ≥ v0.5.0 (plugin lifecycle hooks)
96
+ - Python ≥ 3.10
97
+ - `mindgraph-sdk` ≥ 0.1.4
98
+ - `MINDGRAPH_API_KEY` environment variable
99
+
100
+ ## License
101
+
102
+ MIT
@@ -0,0 +1,7 @@
1
+ hermes_mindgraph_plugin/__init__.py,sha256=QyhF_wB87qnzOvYawcfbLV0PDAu6miPjF71psb7pAJg,5652
2
+ hermes_mindgraph_plugin/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ hermes_mindgraph_plugin-0.1.0.dist-info/METADATA,sha256=cJHb3ZaRdxTb10emc6wBt-jGasSGUhmuoq-fzlvQUdM,3569
4
+ hermes_mindgraph_plugin-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
5
+ hermes_mindgraph_plugin-0.1.0.dist-info/entry_points.txt,sha256=eERZ4MlnlFmrzPvpOwD709Aepe6DZi4bF3ajpR7AnEs,59
6
+ hermes_mindgraph_plugin-0.1.0.dist-info/licenses/LICENSE,sha256=Ii6C3uBhgaTl3K8D_BMUjQsoVwmxeaYUv3RpYoiPJr4,1066
7
+ hermes_mindgraph_plugin-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [hermes_agent.plugins]
2
+ mindgraph = hermes_mindgraph_plugin
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MindGraph
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.