delete_observations
Remove specific observations from entities in the knowledge graph. Use this tool to maintain data accuracy by deleting outdated or incorrect entity-associated observations.
Instructions
Delete specific observations from entities in the knowledge graph
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deletions | Yes | Array of entity observations to delete |
Implementation Reference
- src/memory/tools.ts:286-361 (handler)Full tool registration including the handler execute function that implements delete_observations by filtering observations from enhancedEntities in memoryStore after fuzzy entity matching.server.addTool({ name: 'delete_observations', description: 'Delete specific observations from entities in the knowledge graph', parameters: Schemas.DeleteObservationsSchema, execute: async (args) => { const results = { updated: [] as string[], notFound: [] as string[] }; for (const item of args.deletions) { try { // First, find the entity directly const entity = graph.entities.get(item.entityName); if (!entity) { // If not found directly, try to find similar entities const similarEntities = await memoryStore.findSimilar(item.entityName); if (similarEntities.length === 0) { // No matching entity found results.notFound.push(item.entityName); continue; } // Use the first similar entity item.entityName = similarEntities[0]; } // Get enhanced entity from memory store (access private property carefully) const enhancedEntityMap = (memoryStore as any).enhancedEntities; const enhancedEntity = enhancedEntityMap?.get(item.entityName); if (!enhancedEntity) { results.notFound.push(item.entityName); continue; } // Track if any observations were removed let observationsRemoved = false; // Loop through the observations to delete for (const observationToDelete of item.observations) { // Filter out observations that match the text const originalLength = enhancedEntity.observations.length; enhancedEntity.observations = enhancedEntity.observations.filter((obs: { text: string }) => !obs.text.includes(observationToDelete) ); if (enhancedEntity.observations.length < originalLength) { observationsRemoved = true; } } if (observationsRemoved) { results.updated.push(item.entityName); } else { results.notFound.push(item.entityName); } } catch (error) { console.error(`Error deleting observations for ${item.entityName}:`, error); results.notFound.push(item.entityName); } } // Save changes await memoryStore.save(); // Return as string return JSON.stringify({ updated: results.updated.length > 0 ? results.updated : null, notFound: results.notFound.length > 0 ? results.notFound : null, message: `Removed observations from ${results.updated.length} entities. ${results.notFound.length} entities not found or observations not found.` }); } });
- src/utils/validation.ts:48-53 (schema)Zod schema defining the input parameters for the delete_observations tool.export const DeleteObservationsSchema = z.object({ deletions: z.array(z.object({ entityName: z.string().min(1).describe('Name of the entity to remove observations from'), observations: z.array(z.string()).describe('Observations to remove from the entity') })).describe('Array of entity observations to delete') });
- src/memory/knowledgeGraph.ts:115-130 (helper)Supporting method in KnowledgeGraph class for deleting observations from an entity (used in other tools like upsert_entities).deleteObservations(entityName: string, observations: string[]): boolean { const entity = this.entities.get(entityName); if (!entity) { return false; } // Remove each observation if it exists for (const observation of observations) { const index = entity.observations.indexOf(observation); if (index !== -1) { entity.observations.splice(index, 1); } } return true; }
- src/memory/tools.ts:286-289 (registration)Tool registration within registerMemoryTools function.server.addTool({ name: 'delete_observations', description: 'Delete specific observations from entities in the knowledge graph', parameters: Schemas.DeleteObservationsSchema,