add_location
Add a new location to MemoryMesh's knowledge graph, including details like name, type, description, status, notable features, and associated characters, quests, or artifacts for enhanced world-building.
Instructions
Add a new location to the knowledge graph
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| location | Yes |
Input Schema (JSON Schema)
{
"properties": {
"location": {
"additionalProperties": {
"description": "Additional property value",
"type": "string"
},
"properties": {
"accessibility": {
"description": "How characters can enter/exit the location",
"type": "string"
},
"atmosphere": {
"description": "The general feel/mood of the location",
"type": "string"
},
"dangerLevel": {
"description": "The level of danger present in the location",
"type": "string"
},
"description": {
"description": "Detailed description of the location",
"type": "string"
},
"name": {
"description": "Location's name",
"type": "string"
},
"notableFeatures": {
"description": "Distinct characteristics of the location",
"items": {
"description": "Item in notableFeatures array",
"type": "string"
},
"type": "array"
},
"parentLocation": {
"description": "The parent location this location belongs to",
"type": "string"
},
"relatedArtifacts": {
"description": "Artifacts associated with the location",
"items": {
"description": "Item in relatedArtifacts array",
"type": "string"
},
"type": "array"
},
"relatedCharacters": {
"description": "Characters associated with the location",
"items": {
"description": "Item in relatedCharacters array",
"type": "string"
},
"type": "array"
},
"relatedQuests": {
"description": "Quests associated with the location",
"items": {
"description": "Item in relatedQuests array",
"type": "string"
},
"type": "array"
},
"size": {
"description": "The size or scale of the location",
"type": "string"
},
"status": {
"description": "Current state of the location",
"type": "string"
},
"subLocations": {
"description": "Locations contained within this location",
"items": {
"description": "Item in subLocations array",
"type": "string"
},
"type": "array"
},
"type": {
"description": "Type of location",
"type": "string"
}
},
"required": [
"name",
"type",
"description",
"status"
],
"type": "object"
}
},
"required": [
"location"
],
"type": "object"
}
Implementation Reference
- Core handler logic for the 'add_location' tool (and similar add_<schema> tools). Checks if node exists, creates nodes and relationships using createSchemaNode, adds them to the graph in a transaction, and returns formatted response.switch (operation) { case 'add': { const nodeData = args[schemaName]; const existingNodes = await knowledgeGraphManager.openNodes([nodeData.name]); if (existingNodes.nodes.length > 0) { throw new Error(`Node already exists: ${nodeData.name}`); } const {nodes, edges} = await createSchemaNode(nodeData, schema, schemaName); await knowledgeGraphManager.beginTransaction(); try { await knowledgeGraphManager.addNodes(nodes); if (edges.length > 0) { await knowledgeGraphManager.addEdges(edges); } await knowledgeGraphManager.commit(); return formatToolResponse({ data: {nodes, edges}, actionTaken: `Created ${schemaName}: ${nodeData.name}` }); } catch (error) { await knowledgeGraphManager.rollback(); throw error; } }
- SchemaBuilder.build() method generates the Tool inputSchema for 'add_location' from the schema configuration, used as the tool schema in dynamic tool generation.build(): SchemaConfig { return { ...this.schema as SchemaConfig, relationships: Object.fromEntries(this.relationships), metadataConfig: this.metadataConfig }; }
- src/integration/tools/registry/toolsRegistry.ts:34-59 (registration)ToolsRegistry.initialize() registers all dynamic tools (including 'add_location' if location schema exists) into the central tools Map by calling dynamicToolManager.getTools().async initialize(knowledgeGraphManager: ApplicationManager): Promise<void> { if (this.initialized) { return; } try { this.knowledgeGraphManager = knowledgeGraphManager; // Register static tools allStaticTools.forEach(tool => { this.tools.set(tool.name, tool); }); // Initialize and register dynamic tools await dynamicToolManager.initialize(); dynamicToolManager.getTools().forEach(tool => { this.tools.set(tool.name, tool); }); this.initialized = true; console.error(`[ToolsRegistry] Initialized with ${this.tools.size} tools`); } catch (error) { console.error('[ToolsRegistry] Initialization error:', error); throw error; } }
- src/integration/tools/DynamicSchemaToolRegistry.ts:52-77 (registration)DynamicSchemaToolRegistry.initialize() loads schema files, creates SchemaBuilder instances, generates add/update/delete tools (e.g. 'add_location'), and caches them.public async initialize(): Promise<void> { try { const SCHEMAS_DIR = CONFIG.PATHS.SCHEMAS_DIR; const schemaFiles = await fs.readdir(SCHEMAS_DIR); // Process schema files for (const file of schemaFiles) { if (file.endsWith('.schema.json')) { const schemaName = path.basename(file, '.schema.json'); const schema = await SchemaLoader.loadSchema(schemaName); this.schemas.set(schemaName, schema); } } // Generate tools for each schema for (const [schemaName, schema] of this.schemas.entries()) { const tools = await this.generateToolsForSchema(schemaName, schema); tools.forEach(tool => this.toolsCache.set(tool.name, tool)); } console.error(`[DynamicSchemaTools] Initialized ${this.schemas.size} schemas and ${this.toolsCache.size} tools`); } catch (error) { console.error('[DynamicSchemaTools] Initialization error:', error); throw error; } }
- SchemaBuilder constructor initializes the inputSchema structure specifically for 'add_*' named schemas (like 'add_location'), setting up the object wrapper and properties.constructor(name: string, description: string) { this.schema = { name, description, inputSchema: { type: "object", properties: { [name.replace('add_', '')]: { type: "object", properties: {}, required: [], additionalProperties: { type: "string", description: "Any additional properties" } } }, required: [name.replace('add_', '')] } }; this.relationships = new Map(); this.metadataConfig = { requiredFields: [], optionalFields: [], excludeFields: [] }; }