{"record":{"id":"552a38ab2e7884ad","repo":"langchain-ai/deepagents","slug":"subagent-spec-name-must-specify-model","errorCode":null,"errorMessage":"SubAgent '{spec['name']}' must specify 'model'","messagePattern":"SubAgent '(.+?)' must specify 'model'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/middleware/subagents.py","lineNumber":362,"sourceCode":"    raw subagent specs. Pre-compiled `CompiledSubAgent` runnables are already\n    created by the caller and are handled separately by `SubAgentMiddleware`.\n\n    Args:\n        spec: Subagent spec to compile. Must specify `model` and `tools`.\n        state_schema: Base graph state schema forwarded to `create_agent` for\n            the subagent.\n        response_format: Optional response format override for this compiled\n            subagent instance.\n\n    Returns:\n        Runnable agent ready for task-tool invocation.\n\n    Raises:\n        ValueError: If `spec` is missing `model` or `tools`.\n    \"\"\"\n    if \"model\" not in spec:\n        msg = f\"SubAgent '{spec['name']}' must specify 'model'\"\n        raise ValueError(msg)\n    if \"tools\" not in spec:\n        msg = f\"SubAgent '{spec['name']}' must specify 'tools'\"\n        raise ValueError(msg)\n\n    from deepagents._models import resolve_model  # noqa: PLC0415\n\n    model = resolve_model(spec[\"model\"])\n    middleware: list[AgentMiddleware] = list(spec.get(\"middleware\", []))\n\n    interrupt_on = spec.get(\"interrupt_on\")\n    if interrupt_on:\n        middleware.append(HumanInTheLoopMiddleware(interrupt_on=interrupt_on))\n\n    selected_response_format = response_format if response_format is not None else spec.get(\"response_format\")\n    create_agent_kwargs: dict[str, Any] = {\n        \"system_prompt\": spec[\"system_prompt\"],\n        \"tools\": spec[\"tools\"],\n        \"middleware\": middleware,","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/middleware/subagents.py#L344-L380","documentation":"`create_sub_agent` builds a runnable subagent from a declarative `SubAgent` dict spec. A spec must declare at least a `model` and `tools`; if the `model` key is absent the function raises `ValueError` immediately, because there is no way to construct the underlying agent LLM without it.","triggerScenarios":"Calling `create_sub_agent(spec=...)` (directly or via `_compile_spec` from `_build_task_tool`/`_select_subagent`) with a dict that has a `name` but no `model` key.","commonSituations":"Hand-writing subagent dicts and forgetting `model`; building specs programmatically from config files where the model field is optional/missing; migrating code that previously inherited the parent agent's default model.","solutions":["Add a `model` key to the spec dict, e.g. `\"model\": \"anthropic:claude-sonnet-4-5\"` or a `BaseChatModel` instance","If the subagent should use the parent's model, copy it into the spec explicitly before calling","Validate required keys (`name`, `model`, `tools`) at spec-construction time"],"exampleFix":"// before\n{\"name\": \"researcher\", \"tools\": [search_tool]}\n// after\n{\"name\": \"researcher\", \"model\": \"anthropic:claude-sonnet-4-5\", \"tools\": [search_tool]}","handlingStrategy":"validation","validationCode":"required = {\"name\", \"model\", \"tools\"}\nmissing = required - spec.keys()\nif missing:\n    raise ValueError(f\"SubAgent spec missing: {sorted(missing)}\")","typeGuard":"def has_model(spec: dict) -> bool:\n    return \"model\" in spec","tryCatchPattern":"try:\n    agent = create_sub_agent(spec=spec)\nexcept ValueError as e:\n    logger.error(\"Bad subagent spec %r: %s\", spec.get(\"name\"), e)\n    raise","preventionTips":["Define subagent specs with a TypedDict/dataclass so missing keys fail type checking","Validate all specs at app startup, before graph compilation","Keep spec construction and consumption in one schema-checked location"],"tags":["python","subagents","validation","valueerror"],"backgroundTag":"missing-required-field","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}