{"record":{"id":"3277466d435c6ef4","repo":"datawhalechina/hello-agents","slug":"agent-exc-args-0-not-found","errorCode":null,"errorMessage":"Agent '{exc.args[0]}' not found","messagePattern":"Agent '(.+?)' not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"Co-creation-projects/huailishang-AgentPlatformBase/backend/main.py","lineNumber":112,"sourceCode":"\n\n@app.post(\"/tasks/{task_id}/run\", response_model=TaskRecord)\ndef run_task(task_id: str, background: bool = True) -> TaskRecord:\n    try:\n        task_manager.get(task_id)\n    except KeyError:\n        raise HTTPException(status_code=404, detail=f\"Task '{task_id}' not found\")\n    if background:\n        return task_runner.start_background(task_id)\n    return task_runner.run(task_id)\n\n\n@app.post(\"/batch/run\")\ndef run_batch(request: BatchRunRequest) -> dict:\n    try:\n        return {\"responses\": batch_runner.run(request.requests)}\n    except KeyError as exc:\n        raise HTTPException(status_code=404, detail=f\"Agent '{exc.args[0]}' not found\")\n\n\n@app.get(\"/events\")\ndef list_events(task_id: str | None = None, limit: int = 100) -> dict:\n    return {\"events\": event_logger.list_events(task_id=task_id, limit=limit)}\n","sourceCodeStart":94,"sourceCodeEnd":118,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/huailishang-AgentPlatformBase/backend/main.py#L94-L118","documentation":"POST /batch/run returns HTTP 404 when batch_runner.run() raises KeyError: at least one AgentRequest in the request batch referenced an agent_id that is not registered. The detail interpolates exc.args[0], which is the missing agent id from the registry lookup, identifying which entry failed.","triggerScenarios":"Sending {\"requests\": [...]} where any element's agent_id is unknown to the registry; a single bad id fails the whole batch with 404.","commonSituations":"Bulk orchestration scripts with one stale/typo'd agent id among many; heterogeneous batches where some agents are not deployed in the target environment.","solutions":["Read the detail field — it names the exact missing agent id.","Validate every request's agent_id against GET /agents before submitting the batch.","Split the batch so one invalid id cannot fail valid requests, or have the backend return per-item results."],"exampleFix":"# before\nresp = requests.post(f\"{BASE}/batch/run\", json={\"requests\": batch})  # one bad id -> whole 404\n\n# after\nvalid = {a[\"id\"] for a in requests.get(f\"{BASE}/agents\").json()[\"agents\"]}\nbatch = [r for r in batch if r[\"agent_id\"] in valid]\nresp = requests.post(f\"{BASE}/batch/run\", json={\"requests\": batch})","handlingStrategy":"validation","validationCode":"valid = {a[\"id\"] for a in requests.get(f\"{BASE}/agents\").json()[\"agents\"]}\nbad = [r[\"agent_id\"] for r in batch if r[\"agent_id\"] not in valid]\nif bad:\n    raise ValueError(f\"unknown agent ids in batch: {bad}\")\nresp = requests.post(f\"{BASE}/batch/run\", json={\"requests\": batch})","typeGuard":"def batch_all_valid(batch: list[dict], valid_ids: set[str]) -> bool:\n    return all(r.get(\"agent_id\") in valid_ids for r in batch)","tryCatchPattern":"try:\n    resp = requests.post(f\"{BASE}/batch/run\", json={\"requests\": batch})\n    resp.raise_for_status()\nexcept HTTPError as e:\n    if e.response.status_code == 404:\n        missing = e.response.json()[\"detail\"]  # names the offending id\n        batch = [r for r in batch if r[\"agent_id\"] != missing.split(\"'\")[1]]\n        resp = requests.post(f\"{BASE}/batch/run\", json={\"requests\": batch})\n    else:\n        raise","preventionTips":["Pre-validate the whole batch against GET /agents before submission.","Parse the 404 detail to identify and drop the offending request, then resubmit.","Consider per-item result semantics instead of all-or-nothing batches."],"tags":["http-404","batch-processing","validation","fastapi"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}