Update an existing memory system with new configuration and create a new version Args: memory_name: Name of the memory system to update memory: New memory instance or class with updated implementation memory_config_dict: Configuration dict for mem
(self,
memory_name: str,
memory: Union[Memory, Type[Memory]],
memory_config_dict: Optional[Dict[str, Any]] = None,
new_version: Optional[str] = None,
description: Optional[str] = None,
code: Optional[str] = None)
| 444 | raise |
| 445 | |
| 446 | async def update(self, |
| 447 | memory_name: str, |
| 448 | memory: Union[Memory, Type[Memory]], |
| 449 | memory_config_dict: Optional[Dict[str, Any]] = None, |
| 450 | new_version: Optional[str] = None, |
| 451 | description: Optional[str] = None, |
| 452 | code: Optional[str] = None) -> MemoryConfig: |
| 453 | """Update an existing memory system with new configuration and create a new version |
| 454 | |
| 455 | Args: |
| 456 | memory_name: Name of the memory system to update |
| 457 | memory: New memory instance or class with updated implementation |
| 458 | memory_config_dict: Configuration dict for memory initialization |
| 459 | If None, will try to get from global config |
| 460 | new_version: New version string. If None, auto-increments from current version. |
| 461 | description: Description for this version update |
| 462 | code: Optional source code string. If provided, uses this instead of extracting from memory class. |
| 463 | This is useful when memory class is dynamically created from code string. |
| 464 | |
| 465 | Returns: |
| 466 | MemoryConfig: Updated memory configuration |
| 467 | """ |
| 468 | try: |
| 469 | # Handle both instance and class cases |
| 470 | if isinstance(memory, Memory): |
| 471 | # Updating with an instance |
| 472 | memory_instance = memory |
| 473 | memory_cls = type(memory) |
| 474 | if memory_config_dict: |
| 475 | raise ValueError("Extra keyword arguments are not allowed when updating with memory instances.") |
| 476 | memory_config_dict = {} |
| 477 | else: |
| 478 | # Updating with a class |
| 479 | memory_cls = memory |
| 480 | if memory_config_dict is None: |
| 481 | # Fallback to global config by class name |
| 482 | memory_config_key = inflection.underscore(memory_cls.__name__) |
| 483 | memory_config_dict = config.get(memory_config_key, {}) |
| 484 | |
| 485 | # Instantiate memory immediately (update is a runtime operation) |
| 486 | try: |
| 487 | memory_instance = memory_cls(**memory_config_dict) |
| 488 | except Exception as e: |
| 489 | logger.error(f"| ❌ Failed to create memory instance for {memory_cls.__name__}: {e}") |
| 490 | raise ValueError(f"Failed to instantiate memory {memory_cls.__name__} with provided config: {e}") |
| 491 | |
| 492 | # Check if memory exists |
| 493 | original_config = self._memory_configs.get(memory_name) |
| 494 | if original_config is None: |
| 495 | raise ValueError(f"Memory {memory_name} not found. Use register() to register a new memory system.") |
| 496 | |
| 497 | memory_description = memory_instance.description |
| 498 | memory_metadata = getattr(memory_instance, 'metadata', {}) |
| 499 | # Get require_grad from memory_config_dict if provided, otherwise from memory_instance |
| 500 | memory_require_grad = memory_config_dict.get("require_grad", memory_instance.require_grad) if memory_config_dict and "require_grad" in memory_config_dict else memory_instance.require_grad |
| 501 | |
| 502 | # Determine new version from version_manager |
| 503 | if new_version is None: |
no test coverage detected