create_relations
Establish connections between entities in the knowledge graph by defining relation types, enabling structured data storage and retrieval for AI memory systems.
Instructions
Create multiple new relations between entities in the knowledge graph. Relations should be in active voice
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| relations | Yes |
Implementation Reference
- index.ts:93-107 (handler)The core handler function in KnowledgeGraphManager that executes the create_relations tool logic: loads the graph from memory file, deduplicates incoming relations, adds creation timestamp and version, appends to graph, saves back to file, and returns newly created relations.async createRelations(relations: Relation[]): Promise<Relation[]> { const graph = await this.loadGraph(); const newRelations = relations.filter(r => !graph.relations.some(existingRelation => existingRelation.from === r.from && existingRelation.to === r.to && existingRelation.relationType === r.relationType )).map(r => ({ ...r, createdAt: new Date().toISOString(), version: r.version || 1 })); graph.relations.push(...newRelations); await this.saveGraph(graph); return newRelations; }
- index.ts:313-330 (schema)Input schema definition for the create_relations tool, specifying the expected structure: an object with a 'relations' array, each item having 'from', 'to', and 'relationType' strings.inputSchema: { type: "object", properties: { relations: { type: "array", items: { type: "object", properties: { from: { type: "string", description: "The name of the entity where the relation starts" }, to: { type: "string", description: "The name of the entity where the relation ends" }, relationType: { type: "string", description: "The type of the relation" }, }, required: ["from", "to", "relationType"], }, }, }, required: ["relations"], },
- index.ts:310-331 (registration)Tool registration in the listTools response, defining the name, description, and inputSchema for create_relations.{ name: "create_relations", description: "Create multiple new relations between entities in the knowledge graph. Relations should be in active voice", inputSchema: { type: "object", properties: { relations: { type: "array", items: { type: "object", properties: { from: { type: "string", description: "The name of the entity where the relation starts" }, to: { type: "string", description: "The name of the entity where the relation ends" }, relationType: { type: "string", description: "The type of the relation" }, }, required: ["from", "to", "relationType"], }, }, }, required: ["relations"], }, },
- index.ts:516-517 (registration)Dispatch case in the CallToolRequestSchema handler that routes create_relations calls to the knowledgeGraphManager.createRelations method and formats the response.case "create_relations": return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.createRelations(args.relations as Relation[]), null, 2) }] };
- index.ts:39-45 (schema)TypeScript interface defining the structure of a Relation, used for input validation and storage in create_relations and related tools.interface Relation { from: string; to: string; relationType: string; createdAt: string; version: number; }