MCPcopy Create free account
hub / github.com/SkyworkAI/DeepResearchAgent / run_sample

Function run_sample

examples/run_aime_reflection_experiment.py:381–480  ·  view source on GitHub ↗
(
    *,
    question_text: str,
    ground_truth_text: str,
    model: Module,  # BlackboxLLM or ToolCallingAgentLLM
    evaluation_module: MultiFieldEvaluation,
    engine: tg.EngineLM,
    model_name: str,
    max_step: int,
)

Source from the content-addressed store, hash-verified

379
380
381def run_sample(
382 *,
383 question_text: str,
384 ground_truth_text: str,
385 model: Module, # BlackboxLLM or ToolCallingAgentLLM
386 evaluation_module: MultiFieldEvaluation,
387 engine: tg.EngineLM,
388 model_name: str,
389 max_step: int,
390) -> Dict[str, Any]:
391 question_var = Variable(
392 question_text,
393 requires_grad=False,
394 role_description="contest problem statement",
395 )
396
397 # Direct inference
398 direct_response = model(question_var)
399 direct_response_text = direct_response.value
400 direct_eval = evaluate_prediction(direct_response_text, ground_truth_text)
401 direct_think_stats = compute_think_token_stats(model_name, direct_response_text)
402
403 # Reflection loop
404 current_solution = direct_response_text
405 step_logs: List[Dict[str, Any]] = []
406
407 for step_idx in range(1, max_step + 1):
408 solution_var = Variable(
409 current_solution,
410 requires_grad=False,
411 role_description="candidate solution with reasoning and boxed answer",
412 )
413 evaluation_output = evaluation_module([question_var, solution_var])
414 evaluation_text = evaluation_output.value
415
416 reflection_prompt = build_reflection_prompt(
417 question_text=question_text,
418 current_solution=current_solution,
419 evaluation_text=evaluation_text,
420 )
421
422 try:
423 improved_text = engine(
424 reflection_prompt,
425 system_prompt=REFLECTION_SYSTEM_PROMPT,
426 )
427 except Exception as exc: # pragma: no cover - runtime safety
428 logger.error(f"Reflection step {step_idx} failed: {exc}")
429 step_logs.append(
430 {
431 "step": step_idx,
432 "error": f"reflection_failed: {exc}",
433 "evaluation_output": evaluation_text,
434 "reflection_prompt": reflection_prompt,
435 }
436 )
437 break
438

Callers 1

run_datasetFunction · 0.70

Calls 7

VariableClass · 0.90
joinMethod · 0.80
evaluate_predictionFunction · 0.70
build_reflection_promptFunction · 0.70
errorMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected