Run the agent on a single ELAIPBench question.
(
idx: int,
total: int,
instance: dict,
args,
output_dir: Path,
)
| 20 | |
| 21 | |
| 22 | def run_instance( |
| 23 | idx: int, |
| 24 | total: int, |
| 25 | instance: dict, |
| 26 | args, |
| 27 | output_dir: Path, |
| 28 | ) -> ELAIPBenchResult: |
| 29 | """Run the agent on a single ELAIPBench question.""" |
| 30 | qid = instance["id"] |
| 31 | qtype = instance["question_type"] |
| 32 | preview = instance["question"][:80].replace("\n", " ") |
| 33 | |
| 34 | _safe_print(f"\n[{idx}/{total}] Question {qid} ({qtype}): {preview}...") |
| 35 | |
| 36 | try: |
| 37 | from harness.agent import AgentSPEX |
| 38 | from harness.types.config import EffectiveArgs |
| 39 | from mcp_client.client import MCPClient |
| 40 | |
| 41 | mcp_client = MCPClient() |
| 42 | agent = AgentSPEX(mcp_client=mcp_client) |
| 43 | |
| 44 | custom_yaml_file = prepare_yaml_for_question( |
| 45 | args.workflow_file, |
| 46 | instance, |
| 47 | output_dir, |
| 48 | qtype, |
| 49 | ) |
| 50 | |
| 51 | # Create per-question log directory |
| 52 | question_log_dir = output_dir / f"logs/question_{qid}" |
| 53 | question_log_dir.mkdir(parents=True, exist_ok=True) |
| 54 | |
| 55 | # Create a copy of args with per-question output_dir for isolated logging |
| 56 | class _ArgsWithOutputDir: |
| 57 | def __init__(self, original_args, output_dir): |
| 58 | self.__dict__.update( |
| 59 | { |
| 60 | k: getattr(original_args, k) |
| 61 | for k in dir(original_args) |
| 62 | if not k.startswith("__") |
| 63 | } |
| 64 | ) |
| 65 | self.output_dir = str(output_dir) |
| 66 | |
| 67 | per_question_args = _ArgsWithOutputDir(args, question_log_dir) |
| 68 | |
| 69 | agent_args = EffectiveArgs( |
| 70 | workflow_file=custom_yaml_file, |
| 71 | model=args.model if args.model else "gpt-4.1", |
| 72 | _original_args=per_question_args, |
| 73 | ) |
| 74 | |
| 75 | agent_output = agent.run(agent_args) |
| 76 | response_text = ( |
| 77 | agent_output if isinstance(agent_output, str) else str(agent_output or "") |
| 78 | ) |
| 79 |
no test coverage detected