Run the agent on a single SWE-Bench instance.
(
instance: Dict[str, Any],
agent: "AgentSPEX",
mcp_client: "MCPClient",
args,
output_dir: Path,
save_logs: bool = False,
)
| 150 | |
| 151 | |
| 152 | def run_instance( |
| 153 | instance: Dict[str, Any], |
| 154 | agent: "AgentSPEX", |
| 155 | mcp_client: "MCPClient", |
| 156 | args, |
| 157 | output_dir: Path, |
| 158 | save_logs: bool = False, |
| 159 | ) -> InstanceResult: |
| 160 | """Run the agent on a single SWE-Bench instance.""" |
| 161 | instance_id = instance["instance_id"] |
| 162 | problem_statement = instance["problem_statement"] |
| 163 | |
| 164 | host_log_path = output_dir / f"{instance_id}_full.log" if save_logs else None |
| 165 | log_file = str(output_dir / f"{instance_id}_full.log") |
| 166 | event_log_file = str(output_dir / f"{instance_id}_agent_events.log") |
| 167 | host_event_log_path = output_dir / f"{instance_id}_agent_events.log" |
| 168 | logger = Logger( |
| 169 | mcp_client=mcp_client, |
| 170 | log_file=log_file, |
| 171 | host_log_path=host_log_path, |
| 172 | event_log_path=event_log_file, |
| 173 | host_event_log_path=host_event_log_path, |
| 174 | deduplicate=True, |
| 175 | ) |
| 176 | |
| 177 | logger(f"\n{'#'*80}") |
| 178 | logger(f"Processing instance: {instance_id}") |
| 179 | logger(f"{'#'*80}\n") |
| 180 | |
| 181 | try: |
| 182 | repo_path = "/testbed" |
| 183 | conda_env_to_use = "testbed" |
| 184 | |
| 185 | custom_yaml_file = prepare_yaml_for_instance( |
| 186 | args.workflow_file, |
| 187 | instance, |
| 188 | repo_path, |
| 189 | output_dir, |
| 190 | conda_env_name=conda_env_to_use, |
| 191 | ) |
| 192 | |
| 193 | # Get model from CLI args, or fall back to workflow config |
| 194 | model = getattr(args, "model", None) |
| 195 | if not model: |
| 196 | # Read model from workflow config |
| 197 | with open(args.workflow_file, "r") as f: |
| 198 | workflow = yaml.safe_load(f) |
| 199 | model = workflow.get("config", {}).get("model", "gpt-4.1-mini") |
| 200 | |
| 201 | agent_args = AgentArgs( |
| 202 | workflow_file=custom_yaml_file, |
| 203 | model=model, |
| 204 | problem_statement=problem_statement, |
| 205 | ) |
| 206 | |
| 207 | logger(f"Running agent on {instance_id}...") |
| 208 | |
| 209 | _ = agent.run(agent_args, external_logger=logger) |
no test coverage detected