{"record":{"id":"ba3a0b83a3634702","repo":"datawhalechina/hello-agents","slug":"agent-agent-id-not-found","errorCode":null,"errorMessage":"Agent '{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":72,"sourceCode":"\n\n@app.get(\"/health\")\ndef health() -> dict:\n    return {\"status\": \"healthy\", \"service\": settings.app_name}\n\n\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:","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/huailishang-AgentPlatformBase/backend/main.py#L54-L90","documentation":"POST /agents/{agent_id}/run returns HTTP 404 when registry.get(agent_id) raises KeyError — i.e. the agent id in the URL path is not a registered agent. The registry only contains agents that were registered at startup (e.g. deep_research, rss_digest), so unknown or misspelled ids fail here.","triggerScenarios":"POSTing to /agents/deep_reaserch/run (typo), an agent whose registration failed at boot, or an id that was never registered in this deployment.","commonSituations":"Typos in agent ids in client code or curl commands; agent module failed to import/register at startup (check boot logs); calling an environment that registers a different agent subset than the one the client was written against.","solutions":["GET /agents first and use an exact id from the returned list.","If the agent should exist, check service startup logs for a failed registration/import of that agent module.","Fix the typo in the path (ids are exact-match).","Ensure the agent package is installed and registered in the registry configuration this backend boots with."],"exampleFix":"# before\nrequests.post(f\"{BASE}/agents/deep_reaserch/run\", json=payload)  # 404\n\n# after\nagents = requests.get(f\"{BASE}/agents\").json()[\"agents\"]\nids = [a[\"id\"] for a in agents]\nassert \"deep_research\" in ids, f\"unknown id; available: {ids}\"\nrequests.post(f\"{BASE}/agents/deep_research/run\", json=payload)","handlingStrategy":"validation","validationCode":"agents = requests.get(f\"{BASE}/agents\").json()[\"agents\"]\nvalid_ids = {a[\"id\"] for a in agents}\nif agent_id not in valid_ids:\n    raise SystemExit(f\"unknown agent {agent_id!r}; available: {sorted(valid_ids)}\")\nresp = requests.post(f\"{BASE}/agents/{agent_id}/run\", json=payload)","typeGuard":"def agent_exists(agent_id: str, valid_ids: set[str]) -> bool:\n    return agent_id in valid_ids","tryCatchPattern":"try:\n    resp = requests.post(f\"{BASE}/agents/{agent_id}/run\", json=payload)\nexcept HTTPError as e:\n    if e.response.status_code == 404:\n        available = {a[\"id\"] for a in requests.get(f\"{BASE}/agents\").json()[\"agents\"]}\n        raise SystemExit(f\"{agent_id} not registered; available: {sorted(available)}\") from e\n    raise","preventionTips":["Fetch the agent list once at client startup and cache valid ids.","Never hardcode agent ids in scripts; source them from GET /agents.","Monitor backend boot logs for agent registration failures."],"tags":["http-404","api","agent-registry","fastapi"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}