datawhalechina/hello-agents · error · AgentException
不支持的任务类型: {task['type']}
Error message
不支持的任务类型: {task['type']} What it means
Dispatch guard in ControllerAgent.execute_task: task['type'] is compared against five TaskType members (PAPER_HUNTING, PAPER_ANALYSIS, WRITING_ASSISTANCE, CITATION_VALIDATION, FULL_WORKFLOW); any other value raises. Because tasks are dicts built by submit_task from TaskType(task_type), the usual cause is a raw string stored instead of the enum, since TaskType.PAPER_HUNTING != 'paper_hunting' in equality.
Source
Thrown at Co-creation-projects/Apricity-InnocoreAI/agents/controller.py:130
try:
task["status"] = TaskStatus.RUNNING
task["started_at"] = datetime.now()
await self._trigger_event("task_started", task)
# 根据任务类型执行相应的逻辑
if task["type"] == TaskType.PAPER_HUNTING:
result = await self._execute_paper_hunting(task)
elif task["type"] == TaskType.PAPER_ANALYSIS:
result = await self._execute_paper_analysis(task)
elif task["type"] == TaskType.WRITING_ASSISTANCE:
result = await self._execute_writing_assistance(task)
elif task["type"] == TaskType.CITATION_VALIDATION:
result = await self._execute_citation_validation(task)
elif task["type"] == TaskType.FULL_WORKFLOW:
result = await self._execute_full_workflow(task)
else:
raise AgentException(f"不支持的任务类型: {task['type']}")
task["status"] = TaskStatus.COMPLETED
task["completed_at"] = datetime.now()
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)
View on GitHub (pinned to 606a07d341)
Solutions
- Normalize on read: task['type'] = TaskType(task['type']) after any deserialization, since TaskType('paper_hunting') succeeds for str-values enums.
- Use dict-based dispatch keyed by TaskType so enum + handler are registered together, making missing branches loud at startup.
- Accept the string form in comparisons by comparing task['type'].value if tasks may carry raw strings.
- Grep for new TaskType members and confirm each has an _execute_* branch or mapping entry.
Example fix
# before
if task["type"] == TaskType.PAPER_HUNTING: ...
else:
raise AgentException(f"不支持的任务类型: {task['type']}")
# after — mapping dispatch, immune to enum/str drift
self._executors = {
TaskType.PAPER_HUNTING: self._execute_paper_hunting,
TaskType.PAPER_ANALYSIS: self._execute_paper_analysis,
TaskType.WRITING_ASSISTANCE: self._execute_writing_assistance,
TaskType.CITATION_VALIDATION: self._execute_citation_validation,
TaskType.FULL_WORKFLOW: self._execute_full_workflow,
}
executor = self._executors.get(TaskType(task["type"])) # accepts str values too
if executor is None:
raise AgentException(f"不支持的任务类型: {task['type']}")
result = await executor(task) Defensive patterns
Strategy: validation
Validate before calling
# Normalize the type through the enum before submission/execution
try:
normalized = TaskType(task["type"])
except ValueError:
raise ValueError(
f"unsupported task type {task['type']!r}; "
f"valid: {[t.value for t in TaskType]}"
) Type guard
def is_supported_task_type(v) -> bool:
try:
TaskType(v)
return True
except (ValueError, TypeError):
return False Try / catch
try:
await controller.execute_task(task_id)
except AgentException as e:
if "不支持的任务类型" in str(e):
log.error("enum/str drift for task type %r — normalize before submit", task["type"])
raise Prevention
- Always convert to the enum (TaskType(value)) right after any JSON deserialization.
- Use a dict-based dispatch table so a new enum member without a handler fails at startup, not at runtime.
- Add a serialization round-trip test: submit -> dump/load -> execute.
When it happens
Trigger: submit_task called with the enum's string value while the dict stores it unconverted (or JSON round-trip converts enum to string), so the later == comparisons all fail; or a genuinely new TaskType member added to the enum without a dispatch branch; or client sends 'paper-hunting' with a hyphen.
Common situations: Serializing tasks through JSON (queue persistence, API echo) turning TaskType into 'TaskType.PAPER_HUNTING' or 'paper_hunting'; adding FULL_WORKFLOW-style new types in one place only; mixing str and Enum comparisons after a Python version migration.
Related errors
- 不支持的任务类型: {task_type}
- Coach Agent执行失败: {str(e)}
- 任务不存在: {task_id}
- 任务执行失败: {str(e)}
- Unsupported latency_mode: {latency_mode}
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/1ac5e722f0731c8c.
Report an issue: GitHub.