{"record":{"id":"fcc0c24f97eac22a","repo":"datawhalechina/hello-agents","slug":"agent-request-agent-id-not-found","errorCode":null,"errorMessage":"Agent '{request.agent_id}' not found","messagePattern":"Agent '(.+?)' not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"Co-creation-projects/huailishang-AgentPlatformBase/backend/main.py","lineNumber":78,"sourceCode":"\n@app.get(\"/agents\")\ndef list_agents() -> dict:\n    profiles = registry.list_profiles()\n    return {\"agents\": profiles, \"total\": len(profiles)}\n\n\n@app.post(\"/agents/{agent_id}/run\", response_model=AgentResponse)\ndef run_agent(agent_id: str, request: AgentRequest) -> AgentResponse:\n    try:\n        return registry.get(agent_id).run(request)\n    except KeyError:\n        raise HTTPException(status_code=404, detail=f\"Agent '{agent_id}' not found\")\n\n\n@app.post(\"/tasks\", response_model=TaskRecord)\ndef create_task(request: TaskCreateRequest) -> TaskRecord:\n    if request.agent_id not in set(registry.ids()):\n        raise HTTPException(status_code=404, detail=f\"Agent '{request.agent_id}' not found\")\n    return task_manager.create(request)\n\n\n@app.get(\"/tasks\")\ndef list_tasks() -> dict:\n    tasks = task_manager.list()\n    return {\"tasks\": tasks, \"total\": len(tasks)}\n\n\n@app.get(\"/tasks/{task_id}\", response_model=TaskRecord)\ndef get_task(task_id: str) -> TaskRecord:\n    try:\n        return task_manager.get(task_id)\n    except KeyError:\n        raise HTTPException(status_code=404, detail=f\"Task '{task_id}' not found\")\n\n\n@app.post(\"/tasks/{task_id}/run\", response_model=TaskRecord)","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/huailishang-AgentPlatformBase/backend/main.py#L60-L96","documentation":"POST /tasks returns HTTP 404 when the TaskCreateRequest body carries an agent_id that is not in registry.ids(). Unlike the /agents/{agent_id}/run route, here the invalid id comes from the JSON request body, and it is validated against the id set before the task is created.","triggerScenarios":"Creating a task with {\"agent_id\": \"rss_digst\", ...} (typo) or an agent not registered in this backend instance; the task is never persisted — the request is rejected up front.","commonSituations":"Client hardcoded agent ids that drift from the backend's registry; environments (staging vs prod) registering different agents; typo'd agent names in orchestration scripts.","solutions":["GET /agents and copy the exact agent id into TaskCreateRequest.agent_id.","Make the client fetch the agent list dynamically instead of hardcoding ids.","If the agent should exist, fix its registration (see backend startup logs)."],"exampleFix":"# before\ntask = requests.post(f\"{BASE}/tasks\", json={\"agent_id\": \"rss_digst\", \"input\": {...}}).json()\n\n# after\nvalid_ids = set(requests.get(f\"{BASE}/agents\").json()[\"agents\"])\nif payload[\"agent_id\"] not in valid_ids:\n    raise SystemExit(f\"agent_id must be one of {valid_ids}\")\ntask = requests.post(f\"{BASE}/tasks\", json=payload).json()","handlingStrategy":"validation","validationCode":"valid_ids = {a[\"id\"] for a in requests.get(f\"{BASE}/agents\").json()[\"agents\"]}\nif request.agent_id not in valid_ids:\n    raise ValueError(f\"agent_id must be one of {sorted(valid_ids)}\")\nresp = requests.post(f\"{BASE}/tasks\", json=request.model_dump())","typeGuard":"def is_known_agent(agent_id: str, registry_ids: set[str]) -> bool:\n    return agent_id in registry_ids","tryCatchPattern":"try:\n    resp = requests.post(f\"{BASE}/tasks\", json=payload)\n    resp.raise_for_status()\nexcept HTTPError as e:\n    if e.response.status_code == 404:\n        raise ValueError(f\"agent {payload['agent_id']} not registered\") from e\n    raise","preventionTips":["Validate agent_id against the live registry before creating tasks.","Refresh the cached agent list on 404 rather than retrying blindly.","Use dropdowns seeded from GET /agents in any task-creation UI."],"tags":["http-404","validation","task-queue","fastapi"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}