{"record":{"id":"b93d8e3c3b2513c5","repo":"agentscope-ai/agentscope","slug":"agent-agent-id-r-not-found","errorCode":null,"errorMessage":"Agent {agent_id!r} not found.","messagePattern":"Agent (.+?) not found\\.","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"src/agentscope/app/_service/_chat.py","lineNumber":686,"sourceCode":"            # left saying \"unknown error\".\n            try:\n                # -------------------------------------------------------------\n                # 1. Load records + resolve workspace ONCE here, reused below.\n                # Reject missing records up front with a clear error so the\n                # downstream assembly code can rely on non-None values.\n                #\n                # ``resolve_agent`` covers own agents (including team workers,\n                # which the owner runs directly) and cross-owner shared agents\n                # (viewer runs a shared user-source agent). It raises 404 when\n                # the agent is not visible to the caller.\n                # -------------------------------------------------------------\n                try:\n                    agent_record = await self._access.resolve_agent(\n                        user_id,\n                        agent_id,\n                    )\n                except HTTPException as exc:\n                    raise HTTPException(\n                        status_code=404,\n                        detail=f\"Agent {agent_id!r} not found.\",\n                    ) from exc\n                session_record = await self._storage.get_session(\n                    user_id,\n                    agent_id,\n                    session_id,\n                )\n                if session_record is None:\n                    raise HTTPException(\n                        status_code=404,\n                        detail=(\n                            f\"Session {session_id!r} not found for \"\n                            f\"agent {agent_id!r}.\"\n                        ),\n                    )\n                worker_name = agent_record.data.name\n","sourceCodeStart":668,"sourceCodeEnd":704,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/app/_service/_chat.py#L668-L704","documentation":"Raised inside ChatService._run_impl when access.resolve_agent raises (typically not-found or no access); the original HTTPException is wrapped into a clean 404 'Agent {id} not found'. This deliberately hides whether the agent doesn't exist or is invisible to the caller, to avoid leaking agent existence.","triggerScenarios":"Starting/continuing a chat run with an agent_id that was deleted, never existed, or is not visible to the calling user (resolve_agent denied). Also triggered by stale agent ids in persisted frontend state.","commonSituations":"Agent deleted between page load and message send; wrong environment's agent id in config; a collaborator runs an agent shared read-only in a context requiring resolution; typos in agent_id parameters.","solutions":["List the agents visible to the current user and use an id from that list","If the agent was deleted, recreate it or pick another agent id","Verify you are authenticated as a user that can resolve the agent","Handle the 404 in the run call and refresh the agent picker in the UI"],"exampleFix":"// before\nawait client.run(agent_id=\"agent-42\", ...);  // 404\n// after\nagents = await client.list_agents();\nmatch = next((a for a in agents if a.id == \"agent-42\"), None)\nif match is None:\n    raise SystemExit(\"Agent missing or not visible; pick from: \" + \", \".join(a.id for a in agents))\nawait client.run(agent_id=match.id, ...);","handlingStrategy":"validation","validationCode":"agents = await client.list_agents()\nif not any(a.id == agent_id for a in agents):\n    agent_id = await prompt_agent_selection(agents)\nawait client.run(agent_id=agent_id, ...)","typeGuard":"def agent_visible(agents: list[Agent], agent_id: str) -> bool:\n    return any(a.id == agent_id for a in agents)","tryCatchPattern":"try:\n    await client.run(agent_id=agent_id, ...)\nexcept HTTPStatusError as e:\n    if e.response.status_code == 404:\n        await refresh_agent_picker()\n    raise","preventionTips":["Only use agent ids returned by list_agents for the current user","Refresh agent state before sending after page reloads or long idle periods"],"tags":["agent","not-found-404","chat-run","access"],"backgroundTag":"resource-not-found-404","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}