{"record":{"id":"ab4905b74f4139be","repo":"agentscope-ai/agentscope","slug":"no-model-configuration-found-for-agent-agent-id","errorCode":null,"errorMessage":"No model configuration found for agent {agent_id}","messagePattern":"No model configuration found for agent (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"src/agentscope/app/_service/_chat.py","lineNumber":918,"sourceCode":"                    background_task_manager=self._background_task_manager,\n                    message_bus=self._message_bus,\n                    middlewares=middlewares,\n                    user_id=user_id,\n                    agent_record=agent_record,\n                    session_record=session_record,\n                    resource_access_service=self._access,\n                    extra_factory=self._extra_agent_tools,\n                    sub_agent_templates=self._sub_agent_templates,\n                    team_role=team_ctx.role if team_ctx else None,\n                    channel_tools=channel_tools,\n                )\n\n                # -------------------------------------------------------------\n                # 4. Model + fallback (resolved from session's config).\n                # -------------------------------------------------------------\n                model_cfg = session_record.config.chat_model_config\n                if not model_cfg:\n                    raise HTTPException(\n                        status_code=404,\n                        detail=(\n                            f\"No model configuration found for agent \"\n                            f\"{agent_id}\"\n                        ),\n                    )\n                model = await get_model(user_id, model_cfg, self._access)\n\n                fallback_cfg = session_record.config.fallback_chat_model_config\n                fallback_model = (\n                    await get_model(user_id, fallback_cfg, self._access)\n                    if fallback_cfg is not None\n                    else None\n                )\n\n                # -------------------------------------------------------------\n                # 5. Assemble the Agent.\n                # -------------------------------------------------------------","sourceCodeStart":900,"sourceCodeEnd":936,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/app/_service/_chat.py#L900-L936","documentation":"Raised in _run_impl when the session's config has no chat_model_config, i.e. the agent has no model to run with. AgentScope runs require a chat model resolved from the session configuration; an empty config means the run would have nothing to generate responses, so it fails fast with 404 before invoking any model.","triggerScenarios":"Starting a run for an agent/session whose configuration was saved without a chat model (model left blank at agent creation, config updated to empty, or session created from a template lacking model settings).","commonSituations":"Creating an agent via API/UI without filling the model field; model provider env vars (API keys) skipped so the setup wizard stored an empty model config; copying a session config from another environment where the model id doesn't apply; programmatic session creation that omits chat_model_config.","solutions":["Set a chat model on the agent/session configuration (e.g. update the agent with a valid chat_model_config) and re-run","Ensure required model provider credentials/env vars are present before creating agents so the model config gets populated","Validate that session creation payloads include a non-empty chat_model_config","Add a UI/API check refusing to start runs when no model is configured"],"exampleFix":"# before\nsession.config.chat_model_config = None\nawait chat_service.run(...)  # 404\n# after\nsession.config.chat_model_config = ChatModelConfig(model=\"gpt-4o-mini\", api_key=...)\nawait storage.update_session(session)\nawait chat_service.run(...)","handlingStrategy":"validation","validationCode":"session = await storage.get_session(user_id, agent_id, session_id)\nif not session.config.chat_model_config:\n    raise ValueError(f\"Agent {agent_id} has no chat model configured\")\nawait chat_client.run(user_id, agent_id, session_id, ...)","typeGuard":"def has_model(cfg) -> bool:\n    return bool(getattr(cfg, \"chat_model_config\", None))","tryCatchPattern":"try:\n    await chat_service.run(...)\nexcept HTTPStatusError as e:\n    if e.response.status_code == 404 and \"No model configuration\" in e.response.text:\n        await configure_model_and_retry(agent_id)\n    else:\n        raise","preventionTips":["Require a chat model at agent-creation time in your own wrappers","Set provider API keys via env before creating agents so model config resolves"],"tags":["model-config","missing-configuration","chat-run"],"backgroundTag":"missing-configuration","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}