create_entities
Add multiple new entities with names, types, and observations to a knowledge graph for persistent memory across conversations.
Instructions
Create multiple new entities in the knowledge graph
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entities | Yes |
Implementation Reference
- The actual implementation of the entity creation logic using SQLite batch processing.
async def create_entities( self, entities: List[Dict[str, Any]], batch_size: int = 1000 ) -> List[Dict[str, Any]]: """Create multiple new entities using batch processing.""" created_entities = [] async with self.pool.get_connection() as conn: async with self.pool.transaction(conn): for i in range(0, len(entities), batch_size): batch = entities[i:i + batch_size] entity_objects = [Entity.from_dict(e) for e in batch] # Validate entities before insertion for entity in entity_objects: validate_entity(entity) cursor = await conn.execute( "SELECT 1 FROM entities WHERE name = ?", (sanitize_input(entity.name),) ) if await cursor.fetchone(): raise EntityAlreadyExistsError(entity.name) # Insert batch await conn.executemany( "INSERT INTO entities (name, entity_type, observations) VALUES (?, ?, ?)", [(e.name, e.entityType, ','.join(e.observations)) for e in entity_objects] ) created_entities.extend([e.to_dict() for e in entity_objects]) return created_entities - The definition and registration of the create_entities tool with its input schema.
types.Tool( name="create_entities", description="Create multiple new entities in the knowledge graph", inputSchema={ "type": "object", "properties": { "entities": { "type": "array", "items": { "type": "object", "properties": { "name": {"type": "string"}, "entityType": {"type": "string"}, "observations": { "type": "array", "items": {"type": "string"} } }, "required": ["name", "entityType", "observations"], "additionalProperties": False } } }, "required": ["entities"], "additionalProperties": False } ),