Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/memory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ Example:
- No input required
- Returns complete graph structure with all entities and relations

- **read_graph_summary**
- Read a summary of the knowledge graph which includes a summary of each entity and all relations.
- 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 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
- Input: `query` (string)
Expand Down
51 changes: 51 additions & 0 deletions src/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<KnowledgeGraph> {
Expand Down Expand Up @@ -143,6 +155,32 @@ class KnowledgeGraphManager {
return this.loadGraph();
}

async readGraphSummary(): Promise<KnowledgeGraphSummary> {
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<KnowledgeGraph> {
const graph = await this.loadGraph();
Expand Down Expand Up @@ -365,6 +403,15 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
additionalProperties: false,
},
},
{
name: "read_graph_summary",
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: {},
additionalProperties: false,
},
},
{
name: "search_nodes",
description: "Search for nodes in the knowledge graph based on a query",
Expand Down Expand Up @@ -404,6 +451,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}`);
}
Expand Down