Set variable values in a memory system and create a new version. Args: memory_name: Name of the memory system to update variable_updates: Dictionary mapping variable names to new values. For memory systems, this is typically {"name": "memory_n
(self, memory_name: str, variable_updates: Dict[str, Any], new_version: Optional[str] = None, description: Optional[str] = None)
| 1079 | return trainable_variables |
| 1080 | |
| 1081 | async def set_variables(self, memory_name: str, variable_updates: Dict[str, Any], new_version: Optional[str] = None, description: Optional[str] = None) -> MemoryConfig: |
| 1082 | """Set variable values in a memory system and create a new version. |
| 1083 | |
| 1084 | Args: |
| 1085 | memory_name: Name of the memory system to update |
| 1086 | variable_updates: Dictionary mapping variable names to new values. |
| 1087 | For memory systems, this is typically {"name": "memory_name", "variables": "memory code"} |
| 1088 | new_version: New version string. If None, auto-increments from current version. |
| 1089 | description: Description for this version update |
| 1090 | |
| 1091 | Returns: |
| 1092 | MemoryConfig: Updated memory configuration |
| 1093 | """ |
| 1094 | async with self._variables_lock: |
| 1095 | original_config = self._memory_configs.get(memory_name) |
| 1096 | if original_config is None: |
| 1097 | raise ValueError(f"Memory {memory_name} not found. Use register() to register a new memory system.") |
| 1098 | |
| 1099 | # For memory systems, variable_updates format is {"name": "memory_name", "variables": "memory code"} |
| 1100 | # Extract the new code from "variables" field |
| 1101 | if "variables" not in variable_updates: |
| 1102 | raise ValueError(f"variable_updates must contain 'variables' field with memory code, got: {list(variable_updates.keys())}") |
| 1103 | |
| 1104 | new_code = variable_updates["variables"] |
| 1105 | if not isinstance(new_code, str): |
| 1106 | raise ValueError(f"Memory code must be a string, got {type(new_code)}") |
| 1107 | |
| 1108 | # Load memory class from code |
| 1109 | class_name = dynamic_manager.extract_class_name_from_code(new_code) |
| 1110 | if not class_name: |
| 1111 | raise ValueError(f"Cannot extract class name from code") |
| 1112 | |
| 1113 | try: |
| 1114 | memory_cls = dynamic_manager.load_class( |
| 1115 | new_code, |
| 1116 | class_name=class_name, |
| 1117 | base_class=Memory, |
| 1118 | context="memory" |
| 1119 | ) |
| 1120 | except Exception as e: |
| 1121 | logger.error(f"| ❌ Failed to load memory class from code: {e}") |
| 1122 | raise ValueError(f"Failed to load memory class from code: {e}") |
| 1123 | |
| 1124 | # Use update() function to handle version management and persistence |
| 1125 | # Pass the code directly to avoid re-extracting from dynamically created class |
| 1126 | update_description = description or f"Updated code for {memory_name}" |
| 1127 | return await self.update( |
| 1128 | memory_name=memory_name, |
| 1129 | memory=memory_cls, |
| 1130 | memory_config_dict=original_config.config, |
| 1131 | new_version=new_version, |
| 1132 | description=update_description, |
| 1133 | code=new_code # Pass code directly since memory_cls is dynamically created |
| 1134 | ) |
| 1135 | |
| 1136 | async def cleanup(self): |
| 1137 | """Cleanup all active memory systems.""" |
nothing calls this directly
no test coverage detected