MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / run_instance

Function run_instance

src/benchmarks/swe_bench_verified/instance.py:152–276  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

150
151
152def 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)

Callers 1

process_single_instanceFunction · 0.90

Calls 8

AgentArgsClass · 0.90
InstanceResultClass · 0.90
LoggerClass · 0.85
getMethod · 0.80
runMethod · 0.45
invokeMethod · 0.45

Tested by

no test coverage detected