From 2ca0ec1c7c67d425519b84ad3695fb71ac0d4bf8 Mon Sep 17 00:00:00 2001 From: Nathan Hickey Date: Mon, 25 Aug 2025 23:06:10 -0500 Subject: [PATCH 1/2] feat(graph): add read_graph_summary function for efficient entity overview without having load the entire knowledge graph --- src/memory/README.md | 12 +++++++++++ src/memory/index.ts | 51 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/memory/README.md b/src/memory/README.md index 3fd59bbd79..e86a735376 100644 --- a/src/memory/README.md +++ b/src/memory/README.md @@ -108,6 +108,18 @@ Example: - No input required - Returns complete graph structure with all entities and relations +- **read_graph_summary** + - Read entity names, types, and basic info without full observations for efficient context usage + - No input required + - Returns: + - Entity summaries with: + - `name` (string): Entity name + - `entityType` (string): Entity type + - `observationCount` (number): Total number of observations + - `lastObservation` (string, optional): The most recent observation for the entity + - Complete relations array (unchanged from full graph) + - Use this instead of `read_graph` when you only need overview information to preserve context space + - **search_nodes** - Search for nodes based on query - Input: `query` (string) diff --git a/src/memory/index.ts b/src/memory/index.ts index 4590a1db6f..ad2f811da4 100644 --- a/src/memory/index.ts +++ b/src/memory/index.ts @@ -38,6 +38,18 @@ interface KnowledgeGraph { relations: Relation[]; } +interface EntitySummary { + name: string; + entityType: string; + observationCount: number; + lastObservation?: string; +} + +interface KnowledgeGraphSummary { + entities: EntitySummary[]; + relations: Relation[]; +} + // The KnowledgeGraphManager class contains all operations to interact with the knowledge graph class KnowledgeGraphManager { private async loadGraph(): Promise { @@ -133,6 +145,32 @@ class KnowledgeGraphManager { return this.loadGraph(); } + async readGraphSummary(): Promise { + const graph = await this.loadGraph(); + + // Create entity summaries without full observation arrays + const entitySummaries = graph.entities.map(entity => { + const observationCount = entity.observations.length; + let lastObservation: string | undefined; + + if (observationCount > 0) { + lastObservation = entity.observations[observationCount - 1]; + } + + return { + name: entity.name, + entityType: entity.entityType, + observationCount, + lastObservation + }; + }); + + return { + entities: entitySummaries, + relations: graph.relations // Relations are already lightweight, include them all + }; + } + // Very basic search function async searchNodes(query: string): Promise { const graph = await this.loadGraph(); @@ -343,6 +381,15 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { properties: {}, }, }, + { + name: "read_graph_summary", + description: "Read entity names, types, and most recent observations without full observations array for efficient context usage", + inputSchema: { + type: "object", + properties: {}, + additionalProperties: false, + }, + }, { name: "search_nodes", description: "Search for nodes in the knowledge graph based on a query", @@ -380,6 +427,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.readGraph(), null, 2) }] }; } + if (name === "read_graph_summary") { + return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.readGraphSummary(), null, 2) }] }; + } + if (!args) { throw new Error(`No arguments provided for tool: ${name}`); } From 5c7e8abc46c7f6ea8ce5cf47773d65e8624f65b7 Mon Sep 17 00:00:00 2001 From: Nathan Hickey Date: Mon, 25 Aug 2025 23:25:12 -0500 Subject: [PATCH 2/2] feat(graph): enhance read_graph_summary description for clarity and detail --- src/memory/README.md | 4 ++-- src/memory/index.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/memory/README.md b/src/memory/README.md index e86a735376..d9a22dbc03 100644 --- a/src/memory/README.md +++ b/src/memory/README.md @@ -109,7 +109,7 @@ Example: - Returns complete graph structure with all entities and relations - **read_graph_summary** - - Read entity names, types, and basic info without full observations for efficient context usage + - Read a summary of the knowledge graph which includes a summary of each entity and all relations. - No input required - Returns: - Entity summaries with: @@ -118,7 +118,7 @@ Example: - `observationCount` (number): Total number of observations - `lastObservation` (string, optional): The most recent observation for the entity - Complete relations array (unchanged from full graph) - - Use this instead of `read_graph` when you only need overview information to preserve context space + - Use this to get an overview of the entire graph, then use `open_nodes` to get full details for specific entities - **search_nodes** - Search for nodes based on query diff --git a/src/memory/index.ts b/src/memory/index.ts index ad2f811da4..2b8b60511a 100644 --- a/src/memory/index.ts +++ b/src/memory/index.ts @@ -383,7 +383,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => { }, { name: "read_graph_summary", - description: "Read entity names, types, and most recent observations without full observations array for efficient context usage", + description: "Read the knowledge graph summary. Returns all entity names, types, observation counts, and most recent observations without loading full observation arrays. Use open_nodes to get complete details for specific entities.", inputSchema: { type: "object", properties: {},