create_relations
Adds new connections between entities in a knowledge graph to enhance semantic search and code analysis capabilities.
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
- The main tool handler for 'create_relations' that validates the input relations array and delegates the creation to the knowledge graph manager.export const createRelationsHandler: ToolHandler = async (args) => { if (!args.relations || !Array.isArray(args.relations)) { throw new Error("The 'relations' parameter is required and must be an array"); } // Valider chaque relation for (const relation of args.relations) { if (!relation.from || typeof relation.from !== 'string') { throw new Error("Each relation must have a 'from' string property"); } if (!relation.to || typeof relation.to !== 'string') { throw new Error("Each relation must have a 'to' string property"); } if (!relation.relationType || typeof relation.relationType !== 'string') { throw new Error("Each relation must have a 'relationType' string property"); } } try { const result = await knowledgeGraphManager.createRelations(args.relations); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { console.error("Error in create_relations tool:", error); throw error; } };
- The tool definition object containing the name, description, and input schema for validating relations input.export const createRelationsTool: ToolDefinition = { 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"], }, };
- Core helper method in KnowledgeGraphManager that loads the graph, filters out duplicate relations, adds new ones, saves to memory.json, and returns created relations.async createRelations(relations: RelationInput[]): Promise<RelationInput[]> { 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 )); graph.relations.push(...newRelations); await this.saveGraph(graph); return newRelations; }
- src/core/registry.ts:262-282 (registration)The tool 'create_relations' is listed in the expected tools array used for verification after automatic registration via AutoRegistry.export function getExpectedTools(): string[] { return [ // Outils Graph (9 outils) 'create_entities', 'create_relations', 'add_observations', 'delete_entities', 'delete_observations', 'delete_relations', 'read_graph', 'search_nodes', 'open_nodes', // Outils RAG (5 outils - avec injection_rag comme outil principal) 'injection_rag', // Nouvel outil principal 'index_project', // Alias déprécié (rétrocompatibilité) 'search_code', 'manage_projects', 'update_project' ]; }