agentscope-ai/agentscope · error · HTTPException

No model configuration found for agent {agent_id}

Error message

No model configuration found for agent {agent_id}

What it means

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.

Source

Thrown at src/agentscope/app/_service/_chat.py:918

                    background_task_manager=self._background_task_manager,
                    message_bus=self._message_bus,
                    middlewares=middlewares,
                    user_id=user_id,
                    agent_record=agent_record,
                    session_record=session_record,
                    resource_access_service=self._access,
                    extra_factory=self._extra_agent_tools,
                    sub_agent_templates=self._sub_agent_templates,
                    team_role=team_ctx.role if team_ctx else None,
                    channel_tools=channel_tools,
                )

                # -------------------------------------------------------------
                # 4. Model + fallback (resolved from session's config).
                # -------------------------------------------------------------
                model_cfg = session_record.config.chat_model_config
                if not model_cfg:
                    raise HTTPException(
                        status_code=404,
                        detail=(
                            f"No model configuration found for agent "
                            f"{agent_id}"
                        ),
                    )
                model = await get_model(user_id, model_cfg, self._access)

                fallback_cfg = session_record.config.fallback_chat_model_config
                fallback_model = (
                    await get_model(user_id, fallback_cfg, self._access)
                    if fallback_cfg is not None
                    else None
                )

                # -------------------------------------------------------------
                # 5. Assemble the Agent.
                # -------------------------------------------------------------

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Set a chat model on the agent/session configuration (e.g. update the agent with a valid chat_model_config) and re-run
  2. Ensure required model provider credentials/env vars are present before creating agents so the model config gets populated
  3. Validate that session creation payloads include a non-empty chat_model_config
  4. Add a UI/API check refusing to start runs when no model is configured

Example fix

# before
session.config.chat_model_config = None
await chat_service.run(...)  # 404
# after
session.config.chat_model_config = ChatModelConfig(model="gpt-4o-mini", api_key=...)
await storage.update_session(session)
await chat_service.run(...)
Defensive patterns

Strategy: validation

Validate before calling

session = await storage.get_session(user_id, agent_id, session_id)
if not session.config.chat_model_config:
    raise ValueError(f"Agent {agent_id} has no chat model configured")
await chat_client.run(user_id, agent_id, session_id, ...)

Type guard

def has_model(cfg) -> bool:
    return bool(getattr(cfg, "chat_model_config", None))

Try / catch

try:
    await chat_service.run(...)
except HTTPStatusError as e:
    if e.response.status_code == 404 and "No model configuration" in e.response.text:
        await configure_model_and_retry(agent_id)
    else:
        raise

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/ab4905b74f4139be. Report an issue: GitHub.