Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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":
Expand Down
19 changes: 19 additions & 0 deletions python/packages/declarative/tests/test_declarative_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down
Loading