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

Method set_variables

src/prompt/context.py:1082–1216  ·  view source on GitHub ↗

Set variable values in prompts and create new versions. This method accepts flattened variable updates and automatically routes them to the appropriate parent prompts (system_prompt or agent_message_prompt) based on variable type. Args: prompt_n

(self, 
                            prompt_name: str, 
                            variable_updates: Dict[str, Any],
                            new_version: Optional[str] = None, 
                            description: Optional[str] = None)

Source from the content-addressed store, hash-verified

1080 return variables
1081
1082 async def set_variables(self,
1083 prompt_name: str,
1084 variable_updates: Dict[str, Any],
1085 new_version: Optional[str] = None,
1086 description: Optional[str] = None) -> Dict[str, PromptConfig]:
1087 """Set variable values in prompts and create new versions.
1088
1089 This method accepts flattened variable updates and automatically routes them to the
1090 appropriate parent prompts (system_prompt or agent_message_prompt) based on variable type.
1091
1092 Args:
1093 prompt_name: Base name of the prompt (e.g., "tool_calling")
1094 variable_updates: Dictionary mapping variable names to new values.
1095 - Keys are variable names (e.g., "tool_context_rules", "reasoning_rules")
1096 - Values are the new content strings for those variables
1097 - Example:
1098 {
1099 "tool_context_rules": "New tool context rules content...",
1100 "reasoning_rules": "New reasoning rules content...",
1101 "agent_context": "New agent context content..."
1102 }
1103 new_version: New version string. If None, auto-increments from current version.
1104 description: Description for this version update
1105
1106 Returns:
1107 Dict[str, PromptConfig]: Dictionary mapping prompt names to updated configurations
1108 (e.g., {"tool_calling_system_prompt": PromptConfig, ...})
1109 """
1110 async with self._variables_lock:
1111 import copy
1112
1113 system_prompt_name = f"{prompt_name}_system_prompt"
1114 agent_prompt_name = f"{prompt_name}_agent_message_prompt"
1115
1116 # Get both prompt instances
1117 system_prompt_instance = await self.get(system_prompt_name)
1118 agent_prompt_instance = await self.get(agent_prompt_name)
1119
1120 # Group updates by parent prompt type
1121 system_updates = {}
1122 agent_updates = {}
1123
1124 # Classify each variable update by checking which prompt contains it
1125 for var_name, new_value in variable_updates.items():
1126 found = False
1127
1128 # Check if variable belongs to system prompt
1129 if system_prompt_instance is not None:
1130 system_config = self._prompt_configs.get(system_prompt_name)
1131 if system_config and isinstance(system_config.variables, dict):
1132 if var_name in system_config.variables:
1133 system_updates[var_name] = new_value
1134 found = True
1135 logger.debug(f"| 📍 Variable '{var_name}' belongs to {system_prompt_name}")
1136
1137 # Check if variable belongs to agent message prompt
1138 if not found and agent_prompt_instance is not None:
1139 agent_config = self._prompt_configs.get(agent_prompt_name)

Callers

nothing calls this directly

Calls 8

getMethod · 0.95
updateMethod · 0.95
buildMethod · 0.95
debugMethod · 0.80
warningMethod · 0.80
infoMethod · 0.45
model_dumpMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected