fix: Convert entity_types from list to dict for Graphiti API

The Graphiti add_episode() API expects entity_types as a
dict[str, type[BaseModel]], not a list. Changed entity type
building to create a dictionary mapping entity names to their
Pydantic model classes.

Fixed error: 'list' object has no attribute 'items'

Changes:
- Build entity_types as dict instead of list in config processing
- Add fallback to convert ENTITY_TYPES list to dict if needed
- Map entity type names to their model classes
This commit is contained in:
Daniel Chalef 2025-10-29 22:51:24 -07:00
parent 9561c12e59
commit b434a6b680

View file

@ -151,7 +151,7 @@ class GraphitiService:
# Build custom entity types if configured
custom_types = None
if self.config.graphiti.entity_types:
custom_types = []
custom_types = {}
for entity_type in self.config.graphiti.entity_types:
# Create a dynamic Pydantic model for each entity type
entity_model = type(
@ -162,10 +162,14 @@ class GraphitiService:
'__doc__': entity_type.description,
},
)
custom_types.append(entity_model)
custom_types[entity_type.name] = entity_model
# Also support the existing ENTITY_TYPES if use_custom_entities is set
elif hasattr(self.config, 'use_custom_entities') and self.config.use_custom_entities:
custom_types = ENTITY_TYPES
# Convert ENTITY_TYPES list to dict if needed
if isinstance(ENTITY_TYPES, list):
custom_types = {et.__name__: et for et in ENTITY_TYPES}
else:
custom_types = ENTITY_TYPES
# Store entity types for later use
self.entity_types = custom_types