datawhalechina/hello-agents · error · AgentException

任务执行失败: {str(e)}

Error message

任务执行失败: {str(e)}

What it means

Outer wrapper in ControllerAgent.execute_task's except: any exception raised by the per-type executor (_execute_paper_hunting and friends) — including nested AgentExceptions from hunter/miner/coach/validator — is re-wrapped as AgentException('任务执行失败: <original>'). Side effects before re-raising: task status set to FAILED, error recorded, task_failed event triggered. The finally block then appends the task to task_history and deletes it from active_tasks, so the ID is gone regardless.

Source

Thrown at Co-creation-projects/Apricity-InnocoreAI/agents/controller.py:152

                task["result"] = result
                
                await self._trigger_event("task_completed", task)
                
                # 执行回调
                if task["callback"]:
                    await task["callback"](task)
                
                return result
                
            except Exception as e:
                task["status"] = TaskStatus.FAILED
                task["completed_at"] = datetime.now()
                task["error"] = str(e)
                
                await self._trigger_event("task_failed", task)
                
                logger.error(f"任务执行失败 {task_id}: {str(e)}")
                raise AgentException(f"任务执行失败: {str(e)}")
            
            finally:
                # 移动到历史记录
                self.task_history.append(task.copy())
                del self.active_tasks[task_id]
    
    async def _execute_paper_hunting(self, task: Dict) -> Dict[str, Any]:
        """执行论文抓取任务"""
        input_data = task["input_data"]
        
        # 调用Hunter Agent
        hunter_result = await self.agents["hunter"].run(input_data)
        task["agent_results"]["hunter"] = hunter_result
        
        return {
            "task_type": "paper_hunting",
            "papers_found": hunter_result.get("downloaded_papers", []),
            "statistics": {

View on GitHub (pinned to 606a07d341)

Solutions

  1. Strip the outer prefix and diagnose the suffixed inner error — the controller is almost never the culprit.
  2. Re-raise AgentException unchanged (except AgentException: raise) so error 48/49/51 style messages keep their original type and text.
  3. Use raise ... from e to preserve the chain in logs/Sentry.
  4. Check task_history (or the task_failed event payload) for task['error'] to see the same inner message with status context.

Example fix

# before
except Exception as e:
    ...
    raise AgentException(f"任务执行失败: {str(e)}")

# after
except AgentException:
    task["status"] = TaskStatus.FAILED
    task["completed_at"] = datetime.now()
    raise
except Exception as e:
    task["status"] = TaskStatus.FAILED
    task["completed_at"] = datetime.now()
    task["error"] = str(e)
    raise AgentException(f"任务执行失败: {e}") from e
Defensive patterns

Strategy: try-catch

Try / catch

try:
    result = await controller.execute_task(task_id)
except AgentException as e:
    root = str(e).split("任务执行失败:", 1)[-1].strip()
    # root carries the inner agent failure (hunter/miner/coach/validator) — route on it
    if "API请求失败" in root: alert_ops(root)
    elif "缺少必需字段" in root or "不支持" in root: return 422
    raise

Prevention

When it happens

Trigger: hunter.run failing on ArXiv HTTP error (error 55), miner.run failing on missing paper (error 57), coach rejecting a task type (error 49), missing required fields (error 48) — any of these bubbles through the executor and gains the '任务执行失败:' prefix.

Common situations: Reading only the outer prefix and debugging the controller instead of the inner agent; double-wrapping making the message chain long; task_failed event handlers themselves failing and masking the original error.

Related errors


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/c1c677fb5573182c. Report an issue: GitHub.