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

Function process_single_task

examples/analysis.py:311–394  ·  view source on GitHub ↗

Process a single task with the optimizer.

(optimizer_type: str, benchmark_name: str, task_data: Any, task_index: int, total_tasks: int, result_saver: ExperimentResultSaver = None)

Source from the content-addressed store, hash-verified

309 return incorrect_tasks
310
311async def process_single_task(optimizer_type: str, benchmark_name: str, task_data: Any, task_index: int, total_tasks: int, result_saver: ExperimentResultSaver = None):
312 """Process a single task with the optimizer."""
313 task_id = task_data.task_id
314 task_input = task_data.input
315 task_gt = task_data.ground_truth
316 system_instruction = task_data.system_prompt
317 start_time = time.time()
318
319 # Combine system instruction with task input
320 full_task = f"{system_instruction}\n\n{task_input}"
321
322 logger.info(f"\n📋 Task {task_index + 1}/{total_tasks}: {task_id}")
323 print(f"\n📋 Task {task_index + 1}/{total_tasks}: {task_id}")
324 logger.info(f"📋 Task: {full_task[:150]}..." if len(full_task) > 150 else f"📋 Task: {full_task}")
325
326 try:
327 # Get the agent instance
328 agent = await acp.get("tool_calling")
329 # Create optimizer
330 optimizer = create_optimizer(optimizer_type, reward_fn)
331
332 # !!!!!用于临时代替参考模型输出
333 if optimizer_type == 'reinforce_pp':
334 logger.info(f"| 🚀 Running agent to get initial solution...")
335 reference_agent_response = await agent(task=full_task, files=[])
336 reference_agent_response_extra_data = reference_agent_response.extra.data if reference_agent_response.extra and reference_agent_response.extra.data else None
337 reference_agent_result = reference_agent_response_extra_data['final_result']
338 reference_agent_reasoning = reference_agent_response_extra_data['final_reasoning']
339 reference_solution = f"Result: {reference_agent_result}\nReasoning: {reference_agent_reasoning}" if reference_agent_reasoning else f"Result: {reference_agent_result}"
340 logger.info(f"| ✅ Initial solution obtained")
341
342 initial_agent_result, initial_agent_reasoning, reflecion_text, improved_solution, agent_reasoning, agent_result = await optimizer.optimize(agent=agent,
343 task=full_task,
344 ground_truth=task_gt,
345 sft_solution=reference_solution,
346 benchmark_task_id=task_id,
347 files=[])
348 else:
349 initial_agent_result, initial_agent_reasoning, reflecion_text, improved_solution, agent_reasoning, agent_result = await optimizer.optimize(agent=agent,
350 task=full_task,
351 ground_truth=task_gt,
352 benchmark_task_id=task_id,
353 files=[])
354
355 parse_reasoning, parse_result = parse_agent_result(agent_result)
356
357 if parse_reasoning == '':
358 parse_reasoning = agent_reasoning
359 task_data.reasoning = parse_reasoning
360 task_data.result = parse_result
361
362 _ = await benchmark_manager.eval(benchmark_name, task_data)
363 # Get current stats after processing this task
364 stats = await benchmark_manager.stats(benchmark_name)
365 if stats:
366 attempted = stats.correct + stats.wrong
367 accuracy_msg = f"📊 Overall Progress: {attempted}/{stats.total} | Accuracy: {stats.accuracy:.2%}"
368 print(accuracy_msg)

Callers 1

process_with_semaphoreFunction · 0.70

Calls 10

printFunction · 0.85
create_optimizerFunction · 0.70
parse_agent_resultFunction · 0.70
infoMethod · 0.45
getMethod · 0.45
optimizeMethod · 0.45
evalMethod · 0.45
statsMethod · 0.45
add_task_resultMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected