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

Function _run_single_problem

src/benchmarks/aime/run.py:105–190  ·  view source on GitHub ↗

Run the agent on a single AIME problem.

(
    idx: int,
    total: int,
    problem: dict,
    args,
    output_dir: Path,
)

Source from the content-addressed store, hash-verified

103
104
105def _run_single_problem(
106 idx: int,
107 total: int,
108 problem: dict,
109 args,
110 output_dir: Path,
111) -> AIMEResult:
112 """Run the agent on a single AIME problem."""
113 pid = problem["id"]
114 preview = problem["problem"][:80].replace("\n", " ")
115
116 print(f"\n[{idx}/{total}] Problem {pid} ({problem['dataset']}): {preview}...")
117
118 try:
119 from harness.agent import AgentSPEX
120 from harness.types.config import EffectiveArgs
121 from mcp_client.client import MCPClient
122
123 mcp_client = MCPClient()
124 agent = AgentSPEX(mcp_client=mcp_client)
125
126 # Create a thread-local copy of args to avoid race conditions
127 # Ensure agent-level resume is disabled (benchmark handles its own resume)
128 local_args = argparse.Namespace(**vars(args))
129 local_args.problem_statement = QUESTION_PROMPT.format(
130 problem=problem["problem"]
131 )
132 local_args.resume = False
133
134 agent_args = EffectiveArgs(
135 workflow_file=args.workflow_file,
136 _original_args=local_args,
137 )
138
139 import concurrent.futures
140
141 executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
142 future = executor.submit(agent.run, agent_args)
143 timeout = getattr(args, "timeout", 900)
144 try:
145 agent_output = future.result(timeout=timeout)
146 finally:
147 executor.shutdown(wait=False, cancel_futures=True)
148 response_text = (
149 agent_output if isinstance(agent_output, str) else str(agent_output or "")
150 )
151
152 parsed = parse_answer(response_text)
153 ground_truth = problem["answer"]
154
155 # Use math-verify for robust comparison
156 is_correct = verify_answer(response_text, ground_truth)
157
158 result = AIMEResult(
159 problem_id=pid,
160 problem=problem["problem"],
161 correct_answer=ground_truth,
162 dataset=problem["dataset"],

Callers 1

mainFunction · 0.85

Calls 10

MCPClientClass · 0.90
AgentSPEXClass · 0.90
EffectiveArgsClass · 0.90
parse_answerFunction · 0.90
verify_answerFunction · 0.90
AIMEResultClass · 0.90
save_resultFunction · 0.90
submitMethod · 0.80
shutdownMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected