diff --git a/python/packages/declarative/agent_framework_declarative/_models.py b/python/packages/declarative/agent_framework_declarative/_models.py index d748dd65862..dc87886b389 100644 --- a/python/packages/declarative/agent_framework_declarative/_models.py +++ b/python/packages/declarative/agent_framework_declarative/_models.py @@ -1079,6 +1079,11 @@ def agent_schema_dispatch(schema: dict[str, Any]) -> AgentSchemaSpec | None: case "tool": return ToolResource.from_dict(schema) case "model": + # Both the model resource and the model specification claim this + # kind. The specification carries provider fields; the resource + # carries a name. Dispatch by shape so both stay loadable. + if any(key in schema for key in ("provider", "apiType", "connection", "options")): + return Model.from_dict({key: value for key, value in schema.items() if key != "kind"}) return ModelResource.from_dict(schema) case "resource": return Resource.from_dict(schema) @@ -1138,8 +1143,6 @@ def agent_schema_dispatch(schema: dict[str, Any]) -> AgentSchemaSpec | None: return Parser.from_dict(schema) case "template": return Template.from_dict(schema) - case "model": - return Model.from_dict(schema) case "model_options": return ModelOptions.from_dict(schema) case "property_schema": diff --git a/python/packages/declarative/tests/test_declarative_loader.py b/python/packages/declarative/tests/test_declarative_loader.py index c3066178869..080a229c361 100644 --- a/python/packages/declarative/tests/test_declarative_loader.py +++ b/python/packages/declarative/tests/test_declarative_loader.py @@ -408,6 +408,25 @@ def test_agent_schema_dispatch_model_resource(): assert result.id == "gpt-4" +def test_agent_schema_dispatch_model_specification(): + """A model tagged spec carrying provider fields loads as a Model, not a resource.""" + yaml_content = """ +kind: model +id: gpt-4o +provider: OpenAI +apiType: Chat +""" + result = agent_schema_dispatch(yaml.safe_load(yaml_content)) + + assert isinstance(result, Model) + assert result.provider == "OpenAI" + assert result.apiType == "Chat" + + via_options = agent_schema_dispatch({"kind": "model", "id": "m", "options": {"temperature": 0.2}}) + assert isinstance(via_options, Model) + assert via_options.options is not None + + def test_agent_schema_dispatch_property_schema_with_nested_properties(): """Test loading a property schema with nested properties.""" yaml_content = """