agent-memory-graph 0.3.0 → 0.4.0

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.
@@ -5774,6 +5774,47 @@ var entry_default = definePluginEntry({
5774
5774
  name: "Memory Graph",
5775
5775
  description: "Auto-builds a knowledge graph from conversations. Extracts entities/relationships and exposes graph query tools.",
5776
5776
  register(api) {
5777
+ api.on(
5778
+ "before_prompt_build",
5779
+ async (event, ctx) => {
5780
+ const config = ctx?.pluginConfig;
5781
+ if (config?.promptInjection === false) return;
5782
+ try {
5783
+ const graph = await getGraph(config);
5784
+ const prompt = event.prompt || "";
5785
+ const stats = graph.stats();
5786
+ if (stats.entities === 0) return;
5787
+ let contextLines = [];
5788
+ if (prompt && prompt.length > 10) {
5789
+ const searchTerms = prompt.slice(0, 200);
5790
+ const results = graph.search(searchTerms, 5);
5791
+ if (results.length > 0) {
5792
+ contextLines = results.map((r) => {
5793
+ const rels = r.relations?.slice(0, 3).map((rel) => `${rel.relation} ${rel.target}`).join(", ") || "";
5794
+ return `${r.entity.name} (${r.entity.type})${rels ? ": " + rels : ""}`;
5795
+ });
5796
+ }
5797
+ }
5798
+ if (contextLines.length === 0) {
5799
+ const recentEntities = graph.listEntities({ limit: 5, sortBy: "updated_at" });
5800
+ if (recentEntities.length > 0) {
5801
+ contextLines = recentEntities.map((e) => `${e.name} (${e.type})`);
5802
+ }
5803
+ }
5804
+ if (contextLines.length === 0) return;
5805
+ const injection = `## Knowledge Graph Context (auto-injected by memory-graph plugin)
5806
+ Relevant entities from your knowledge graph:
5807
+ ${contextLines.join("\n")}
5808
+
5809
+ Use memory_graph_query or memory_graph_search tools for more details when needed.`;
5810
+ return { appendContext: injection };
5811
+ } catch (err) {
5812
+ console.warn("[memory-graph] Prompt injection failed:", err.message);
5813
+ return;
5814
+ }
5815
+ },
5816
+ { priority: 10 }
5817
+ );
5777
5818
  api.on(
5778
5819
  "message_received",
5779
5820
  async (event) => {
@@ -5827,6 +5868,58 @@ var entry_default = definePluginEntry({
5827
5868
  },
5828
5869
  { priority: 10 }
5829
5870
  );
5871
+ api.on(
5872
+ "agent_end",
5873
+ async (event, ctx) => {
5874
+ const config = ctx?.pluginConfig;
5875
+ const sessionKey = ctx?.sessionKey || "";
5876
+ const messages = event.messages || [];
5877
+ console.log(`[memory-graph] agent_end fired: sessionKey=${sessionKey}, messages=${messages.length}, success=${event.success}`);
5878
+ if (config?.sessionSummary === false) return;
5879
+ if (!sessionKey) return;
5880
+ const textParts = [];
5881
+ for (const msg of messages) {
5882
+ const role = msg.role || "unknown";
5883
+ if (role !== "user" && role !== "assistant") continue;
5884
+ const text = typeof msg.content === "string" ? msg.content : Array.isArray(msg.content) ? msg.content.filter((p) => p.type === "text").map((p) => p.text).join(" ") : "";
5885
+ if (!text || text.length < MIN_MEANINGFUL_LENGTH) continue;
5886
+ textParts.push(`[${role}]: ${text.slice(0, 500)}`);
5887
+ }
5888
+ if (textParts.length < 2) return;
5889
+ const transcript = textParts.join("\n").slice(0, 3e3);
5890
+ try {
5891
+ const graph = await getGraph(config);
5892
+ const { OpenAI } = await import("openai");
5893
+ const client = new OpenAI({
5894
+ apiKey: process.env.OPENAI_API_KEY,
5895
+ baseURL: process.env.OPENAI_BASE_URL
5896
+ });
5897
+ const summaryResponse = await client.chat.completions.create({
5898
+ model: config?.extractionModel || process.env.MEMORY_GRAPH_MODEL || "kr/claude-haiku-4.5",
5899
+ messages: [
5900
+ {
5901
+ role: "system",
5902
+ content: `You are a session summarizer for a knowledge graph. Given a conversation transcript, extract a 2-4 sentence summary of KEY ACTIONS taken (what was built, fixed, published, decided, configured). Focus on concrete outcomes, versions, platforms, and decisions. Skip casual chat and test/debug noise. If nothing meaningful happened, respond with "NO_SUMMARY". Output plain text only.`
5903
+ },
5904
+ { role: "user", content: transcript }
5905
+ ],
5906
+ max_tokens: 300,
5907
+ temperature: 0.3
5908
+ });
5909
+ const summary = summaryResponse.choices?.[0]?.message?.content?.trim();
5910
+ if (summary && summary !== "NO_SUMMARY" && summary.length >= 20) {
5911
+ const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
5912
+ await graph.ingest(summary, { source: `session-summary-${today}`, sessionId: sessionKey });
5913
+ console.log(`[memory-graph] Session summary ingested (${textParts.length} msgs \u2192 ${summary.length} chars)`);
5914
+ } else {
5915
+ console.log(`[memory-graph] No meaningful summary for session (${textParts.length} msgs)`);
5916
+ }
5917
+ } catch (err) {
5918
+ console.warn("[memory-graph] Session summary failed:", err.message);
5919
+ }
5920
+ },
5921
+ { priority: 10 }
5922
+ );
5830
5923
  api.on(
5831
5924
  "session_end",
5832
5925
  async (event, ctx) => {
@@ -71,6 +71,11 @@
71
71
  }
72
72
  },
73
73
  "default": []
74
+ },
75
+ "promptInjection": {
76
+ "type": "boolean",
77
+ "description": "Automatically inject relevant graph context into every agent prompt",
78
+ "default": true
74
79
  }
75
80
  },
76
81
  "additionalProperties": false
@@ -79,7 +84,7 @@
79
84
  "openclawVersion": ">=2026.3.24",
80
85
  "entry": "dist/plugin/entry.js"
81
86
  },
82
- "version": "0.1.1",
87
+ "version": "0.4.0",
83
88
  "author": "KLSGG",
84
89
  "repository": "https://github.com/KLSGG/agent-memory-graph",
85
90
  "license": "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-memory-graph",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Domain-agnostic knowledge graph memory for AI agents. Zero-config, local-first, SQLite-powered. Works as OpenClaw skill (CLI) or plugin (auto-hook).",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",