Create a memory instance and store it. Args: memory_config: Memory configuration Returns: MemoryConfig: Memory configuration with instance
(self, memory_config: MemoryConfig)
| 717 | return [name for name in self._memory_configs.keys()] |
| 718 | |
| 719 | async def build(self, memory_config: MemoryConfig) -> MemoryConfig: |
| 720 | """Create a memory instance and store it. |
| 721 | |
| 722 | Args: |
| 723 | memory_config: Memory configuration |
| 724 | |
| 725 | Returns: |
| 726 | MemoryConfig: Memory configuration with instance |
| 727 | """ |
| 728 | if memory_config.name in self._memory_configs: |
| 729 | existing_config = self._memory_configs[memory_config.name] |
| 730 | if existing_config.instance is not None: |
| 731 | return existing_config |
| 732 | |
| 733 | # Create new memory instance |
| 734 | try: |
| 735 | # cls should already be loaded (either from registry or from code in _load_from_code) |
| 736 | if memory_config.cls is None: |
| 737 | raise ValueError(f"Cannot create memory {memory_config.name}: no class provided. Class should be loaded during initialization.") |
| 738 | |
| 739 | # Instantiate memory instance |
| 740 | memory_instance = memory_config.cls(**memory_config.config) if memory_config.config else memory_config.cls() |
| 741 | |
| 742 | # Initialize memory if it has an initialize method |
| 743 | if hasattr(memory_instance, "initialize"): |
| 744 | await memory_instance.initialize() |
| 745 | |
| 746 | memory_config.instance = memory_instance |
| 747 | |
| 748 | # Store memory metadata |
| 749 | self._memory_configs[memory_config.name] = memory_config |
| 750 | |
| 751 | logger.info(f"| 🔧 Memory {memory_config.name} created and stored") |
| 752 | |
| 753 | return memory_config |
| 754 | except Exception as e: |
| 755 | logger.error(f"| ❌ Failed to create memory {memory_config.name}: {e}") |
| 756 | raise |
| 757 | |
| 758 | async def save_to_json(self, file_path: Optional[str] = None) -> str: |
| 759 | """Save all memory configurations with version history to JSON. |
no test coverage detected