Get variables from agents, where each agent's class source code is used as the variable value. Args: agent_name (Optional[str]): Name of a specific agent. If None, returns variables for all agents. Returns: Dict[str, Variable]: Dictionary
(self, agent_name: Optional[str] = None)
| 1115 | return [] |
| 1116 | |
| 1117 | async def get_variables(self, agent_name: Optional[str] = None) -> Dict[str, 'Variable']: |
| 1118 | """Get variables from agents, where each agent's class source code is used as the variable value. |
| 1119 | |
| 1120 | Args: |
| 1121 | agent_name (Optional[str]): Name of a specific agent. If None, returns variables for all agents. |
| 1122 | |
| 1123 | Returns: |
| 1124 | Dict[str, Variable]: Dictionary mapping agent names to Variable objects. Each Variable has: |
| 1125 | - name: agent name |
| 1126 | - type: "agent_code" |
| 1127 | - description: agent description |
| 1128 | - require_grad: agent's require_grad value |
| 1129 | - variables: agent's class source code (as string value) |
| 1130 | """ |
| 1131 | # Lazy import to avoid circular dependency |
| 1132 | from src.optimizer.types import Variable |
| 1133 | |
| 1134 | variables: Dict[str, Variable] = {} |
| 1135 | |
| 1136 | if agent_name is not None: |
| 1137 | # Get specific agent |
| 1138 | agent_config = await self.get_info(agent_name) |
| 1139 | if agent_config is None: |
| 1140 | logger.warning(f"| ⚠️ Agent {agent_name} not found") |
| 1141 | return variables |
| 1142 | |
| 1143 | agent_configs = {agent_name: agent_config} |
| 1144 | else: |
| 1145 | # Get all agents |
| 1146 | agent_configs = self._agent_configs |
| 1147 | |
| 1148 | for name, agent_config in agent_configs.items(): |
| 1149 | # Get agent code |
| 1150 | agent_code = "" |
| 1151 | if agent_config.cls is not None: |
| 1152 | agent_code = dynamic_manager.get_full_module_source(agent_config.cls) or "" |
| 1153 | elif agent_config.code: |
| 1154 | agent_code = agent_config.code |
| 1155 | |
| 1156 | # Create Variable for this agent |
| 1157 | variable = Variable( |
| 1158 | name=name, |
| 1159 | type="agent_code", |
| 1160 | description=agent_config.description or f"Code for agent {name}", |
| 1161 | require_grad=agent_config.require_grad, |
| 1162 | template=None, |
| 1163 | variables=agent_code # Store code as the variable value |
| 1164 | ) |
| 1165 | variables[name] = variable |
| 1166 | |
| 1167 | return variables |
| 1168 | |
| 1169 | async def get_trainable_variables(self, agent_name: Optional[str] = None) -> Dict[str, 'Variable']: |
| 1170 | """Get trainable variables from agents, filtering out agents with require_grad=False. |
no test coverage detected