MCPcopy Create free account
hub / github.com/SkyworkAI/DeepResearchAgent / MemoryConfig

Class MemoryConfig

src/memory/types.py:114–188  ·  view source on GitHub ↗

Memory configuration for registration

Source from the content-addressed store, hash-verified

112
113
114class MemoryConfig(BaseModel):
115 """Memory configuration for registration"""
116 name: str = Field(description="The name of the memory system")
117 description: str = Field(description="The description of the memory system")
118 require_grad: bool = Field(default=False, description="Whether the memory system requires gradients")
119 version: str = Field(default="1.0.0", description="Version of the memory system")
120
121 cls: Optional[Type[Memory]] = Field(default=None, description="The class of the memory system")
122 instance: Optional[Any] = Field(default=None, description="The instance of the memory system")
123 config: Optional[Dict[str, Any]] = Field(default_factory=dict, description="The initialization configuration of the memory system")
124 metadata: Optional[Dict[str, Any]] = Field(default_factory=dict, description="The metadata of the memory system")
125 code: Optional[str] = Field(default=None, description="Source code for dynamically generated memory classes (used when cls cannot be imported from a module)")
126
127 def model_dump(self, **kwargs) -> Dict[str, Any]:
128 """Dump the model to a dictionary."""
129 return {
130 "name": self.name,
131 "description": self.description,
132 "require_grad": self.require_grad,
133 "version": self.version,
134 "cls": dynamic_manager.get_class_string(self.cls) if self.cls else None,
135 "config": self.config,
136 "instance": None, # Don't serialize instance
137 "metadata": self.metadata,
138 "code": self.code,
139 }
140
141 @classmethod
142 def model_validate(cls, data: Dict[str, Any]) -> 'MemoryConfig':
143 """Validate the model from a dictionary."""
144 name = data.get("name")
145 description = data.get("description")
146 require_grad = data.get("require_grad", False) # Default to False if not provided
147 version = data.get("version", "1.0.0")
148
149 cls_ = None
150 code = data.get("code")
151 if code:
152 class_name = dynamic_manager.extract_class_name_from_code(code)
153 if class_name:
154 try:
155 cls_ = dynamic_manager.load_class(
156 code,
157 class_name=class_name,
158 base_class=Memory,
159 context="memory"
160 )
161 except Exception as e:
162 cls_ = None
163 else:
164 cls_ = None
165 else:
166 cls_ = None
167
168 config = data.get("config", {})
169 instance = data.get("instance", None)
170 metadata = data.get("metadata", {})
171

Callers 5

register_memory_classMethod · 0.90
registerMethod · 0.90
updateMethod · 0.90
copyMethod · 0.90
restoreMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected