add_observations
Update entities by adding observations to their data in the Elasticsearch Knowledge Graph, enhancing the memory-like storage and retrieval for AI models.
Instructions
Add observations to an existing entity in knowledge graph (memory)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| memory_zone | Yes | Optional memory zone where the entity is stored. If not specified, uses the default zone. | |
| name | Yes | Name of entity to add observations to | |
| observations | Yes | Observations to add to the entity |
Implementation Reference
- src/index.ts:393-417 (schema)Input schema definition for the add_observations tool, defining parameters: name (string), observations (array of strings), memory_zone (string, required).{ name: "add_observations", description: "Add observations to an existing entity in knowledge graph (memory)", inputSchema: { type: "object", properties: { name: { type: "string", description: "Name of entity to add observations to" }, observations: { type: "array", items: {type: "string"}, description: "Observations to add to the entity" }, memory_zone: { type: "string", description: "Optional memory zone where the entity is stored. If not specified, uses the default zone." } }, required: ["memory_zone", "name", "observations"], additionalProperties: false, "$schema": "http://json-schema.org/draft-07/schema#" } },
- src/index.ts:1032-1055 (handler)MCP server tool handler for 'add_observations': validates entity exists, calls kgClient.addObservations, returns formatted success/error response.else if (toolName === "add_observations") { const name = params.name; const observations = params.observations; const zone = params.memory_zone; // Get existing entity const entity = await kgClient.getEntity(name, zone); if (!entity) { const zoneMsg = zone ? ` in zone "${zone}"` : ""; return formatResponse({ success: false, error: `Entity "${name}" not found${zoneMsg}`, message: "Please create the entity before adding observations." }); } // Add observations to the entity const updatedEntity = await kgClient.addObservations(name, observations, zone); return formatResponse({ success: true, entity: updatedEntity }); }
- src/kg-client.ts:1722-1746 (handler)Core implementation: fetches existing entity using getEntity, appends new observations, saves updated entity via saveEntity, returns the updated ESEntity.async addObservations(name: string, observations: string[], zone?: string): Promise<ESEntity> { const actualZone = zone || this.defaultZone; // Get existing entity const entity = await this.getEntity(name, actualZone); if (!entity) { throw new Error(`Entity "${name}" not found in zone "${actualZone}"`); } // Add new observations to the existing ones const updatedObservations = [ ...entity.observations, ...observations ]; // Update the entity const updatedEntity = await this.saveEntity({ name: entity.name, entityType: entity.entityType, observations: updatedObservations, relevanceScore: entity.relevanceScore }, actualZone); return updatedEntity; }