Set variable values in a tool and create a new version. Args: tool_name: Name of the tool to update variable_updates: Dictionary mapping variable names to new values. For tools, this is typically {"code": new_code_string} - exa
(self, tool_name: str, variable_updates: Dict[str, Any], new_version: Optional[str] = None, description: Optional[str] = None)
| 1188 | return trainable_variables |
| 1189 | |
| 1190 | async def set_variables(self, tool_name: str, variable_updates: Dict[str, Any], new_version: Optional[str] = None, description: Optional[str] = None) -> ToolConfig: |
| 1191 | """Set variable values in a tool and create a new version. |
| 1192 | |
| 1193 | Args: |
| 1194 | tool_name: Name of the tool to update |
| 1195 | variable_updates: Dictionary mapping variable names to new values. |
| 1196 | For tools, this is typically {"code": new_code_string} |
| 1197 | - example: |
| 1198 | { |
| 1199 | "name": "tool_name", |
| 1200 | "variables": "tool code" |
| 1201 | } |
| 1202 | new_version: New version string. If None, auto-increments from current version. |
| 1203 | description: Description for this version update |
| 1204 | |
| 1205 | Returns: |
| 1206 | ToolConfig: Updated tool configuration |
| 1207 | """ |
| 1208 | async with self._variables_lock: |
| 1209 | original_config = self._tool_configs.get(tool_name) |
| 1210 | if original_config is None: |
| 1211 | raise ValueError(f"Tool {tool_name} not found. Use register() to register a new tool.") |
| 1212 | |
| 1213 | # For tools, variable_updates format is {"name": "tool_name", "variables": "tool code"} |
| 1214 | # Extract the new code from "variables" field |
| 1215 | if "variables" not in variable_updates: |
| 1216 | raise ValueError(f"variable_updates must contain 'variables' field with tool code, got: {list(variable_updates.keys())}") |
| 1217 | |
| 1218 | new_code = variable_updates["variables"] |
| 1219 | if not isinstance(new_code, str): |
| 1220 | raise ValueError(f"Tool code must be a string, got {type(new_code)}") |
| 1221 | |
| 1222 | # Load tool class from code |
| 1223 | class_name = dynamic_manager.extract_class_name_from_code(new_code) |
| 1224 | if not class_name: |
| 1225 | raise ValueError(f"Cannot extract class name from code") |
| 1226 | |
| 1227 | try: |
| 1228 | tool_cls = dynamic_manager.load_class( |
| 1229 | new_code, |
| 1230 | class_name=class_name, |
| 1231 | base_class=Tool, |
| 1232 | context="tool" |
| 1233 | ) |
| 1234 | except Exception as e: |
| 1235 | logger.error(f"| ❌ Failed to load tool class from code: {e}") |
| 1236 | raise ValueError(f"Failed to load tool class from code: {e}") |
| 1237 | |
| 1238 | # Use update() function to handle version management and persistence |
| 1239 | # Pass the code directly to avoid re-extracting from dynamically created class |
| 1240 | update_description = description or f"Updated code for {tool_name}" |
| 1241 | return await self.update( |
| 1242 | tool_cls=tool_cls, |
| 1243 | tool_config_dict=original_config.config, |
| 1244 | new_version=new_version, |
| 1245 | description=update_description, |
| 1246 | code=new_code # Pass code directly since tool_cls is dynamically created |
| 1247 | ) |
nothing calls this directly
no test coverage detected