{"record":{"id":"7879984c85f6e94b","repo":"microsoft/semantic-kernel","slug":"model-id-required-when-creating-a-new-azure-ai-age-787998","errorCode":null,"errorMessage":"model.id required when creating a new Azure AI agent","messagePattern":"model\\.id required when creating a new Azure AI agent","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/open_ai/openai_assistant_agent.py","lineNumber":505,"sourceCode":"                setattr(definition, \"description\", spec.description)\n            if spec.instructions is not None:\n                setattr(definition, \"instructions\", spec.instructions)\n            if spec.extras:\n                merged_metadata = dict(getattr(definition, \"metadata\", {}) or {})\n                merged_metadata.update(spec.extras)\n                setattr(definition, \"metadata\", merged_metadata)\n\n            return cls(\n                definition=definition,\n                client=client,\n                kernel=kernel,\n                prompt_template_config=prompt_template_config,\n                arguments=arguments,\n                **kwargs,\n            )\n\n        if not (spec.model and spec.model.id):\n            raise ValueError(\"model.id required when creating a new Azure AI agent\")\n\n        # Build tool definitions & resources\n        tool_objs = [\n            _build_tool(t, kernel) for t in spec.tools if t.type != \"function\"\n        ]  # List[tuple[list[ToolParam], ToolResources]]\n        all_tools: list[AssistantToolParam] = []\n        all_resources: ToolResources = {}\n\n        for tool_list, resource in tool_objs:\n            all_tools.extend(tool_list)\n            all_resources.update(resource)\n\n        try:\n            agent_definition = await client.beta.assistants.create(\n                model=spec.model.id,\n                name=spec.name,\n                description=spec.description,\n                instructions=spec.instructions,","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/open_ai/openai_assistant_agent.py#L487-L523","documentation":"Raised as a ValueError by _from_dict() when the declarative spec has no existing assistant id (spec.id falsy) AND the spec.model or spec.model.id is missing. In that branch the agent must create a brand-new assistant via client.beta.assistants.create(model=...), and OpenAI requires a model; without spec.model.id the create call cannot proceed. Note the message text says 'Azure AI agent' though it fires on the OpenAI Assistant path too.","triggerScenarios":"Deserializing an agent spec that lacks both an id (to reuse an existing assistant) and a model.id (to create a new one); YAML/template missing the model section; passing a partial spec where model is null.","commonSituations":"Hand-written YAML agent template without a model block; copying a spec for a different provider and forgetting the model; model field renamed in a spec schema upgrade; spec.model set but spec.model.id omitted.","solutions":["Add a model.id to your spec, e.g. model: { id: 'gpt-4o' }, so a new assistant can be created.","Provide spec.id referencing an existing assistant to skip creation entirely.","Validate the spec with AgentSpec.model_validate(data) and assert spec.model and spec.model.id before calling _from_dict."],"exampleFix":"# before\nspec = {'name': 'my-agent', 'instructions': '...'}\nagent = await OpenAIAssistantAgent.from_dict(spec, kernel=kernel, client=client)\n\n# after\nspec = {'name': 'my-agent', 'instructions': '...', 'model': {'id': 'gpt-4o'}}\nagent = await OpenAIAssistantAgent.from_dict(spec, kernel=kernel, client=client)","handlingStrategy":"validation","validationCode":"spec = AgentSpec.model_validate(data)\nassert spec.id or (spec.model and spec.model.id), 'must provide spec.id (reuse) or spec.model.id (create)'","typeGuard":"def spec_has_target(spec: AgentSpec) -> bool:\n    return bool(spec.id) or bool(spec.model and spec.model.id)","tryCatchPattern":"try:\n    agent = await OpenAIAssistantAgent.from_dict(spec, kernel=kernel, client=client)\nexcept ValueError as e:\n    if 'model.id' in str(e):\n        spec.setdefault('model', {})['id'] = 'gpt-4o'\n        agent = await OpenAIAssistantAgent.from_dict(spec, kernel=kernel, client=client)","preventionTips":["Always include model.id in new-agent specs.","Provide spec.id to reuse existing assistants.","Validate spec with AgentSpec before _from_dict."],"tags":["configuration","agents","openai-assistant","declarative-spec","model-id"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}