diff --git a/autogpt_platform/backend/backend/data/block.py b/autogpt_platform/backend/backend/data/block.py index ea293dc197c4..ec4616b1336b 100644 --- a/autogpt_platform/backend/backend/data/block.py +++ b/autogpt_platform/backend/backend/data/block.py @@ -97,11 +97,6 @@ def ref_to_dict(obj): cls.cached_jsonschema = cast(dict[str, Any], ref_to_dict(model)) - # Set default properties values - for field in cls.cached_jsonschema.get("properties", {}).values(): - if isinstance(field, dict) and "advanced" not in field: - field["advanced"] = True - return cls.cached_jsonschema @classmethod diff --git a/autogpt_platform/backend/backend/data/graph.py b/autogpt_platform/backend/backend/data/graph.py index 551b6072d1c3..75449febe1ef 100644 --- a/autogpt_platform/backend/backend/data/graph.py +++ b/autogpt_platform/backend/backend/data/graph.py @@ -193,7 +193,8 @@ def _generate_schema( "properties": { p.name: { "secret": p.secret, - "advanced": p.advanced, + # Default value has to be set for advanced fields. + "advanced": p.advanced and p.value is not None, "title": p.title or p.name, **({"description": p.description} if p.description else {}), **({"default": p.value} if p.value is not None else {}), diff --git a/autogpt_platform/backend/backend/data/model.py b/autogpt_platform/backend/backend/data/model.py index 898ef1040b0c..e22e9718b3f4 100644 --- a/autogpt_platform/backend/backend/data/model.py +++ b/autogpt_platform/backend/backend/data/model.py @@ -134,13 +134,18 @@ def SchemaField( title: Optional[str] = None, description: Optional[str] = None, placeholder: Optional[str] = None, - advanced: Optional[bool] = False, + advanced: Optional[bool] = None, secret: bool = False, exclude: bool = False, hidden: Optional[bool] = None, depends_on: list[str] | None = None, **kwargs, ) -> T: + if default is PydanticUndefined and default_factory is None: + advanced = False + elif advanced is None: + advanced = True + json_extra = { k: v for k, v in { diff --git a/autogpt_platform/backend/test/data/test_graph.py b/autogpt_platform/backend/test/data/test_graph.py index 050e20fdc04b..0075fde9dd5d 100644 --- a/autogpt_platform/backend/test/data/test_graph.py +++ b/autogpt_platform/backend/test/data/test_graph.py @@ -90,7 +90,12 @@ async def test_get_input_schema(server: SpinTestServer): Node( id="node_0_a", block_id=input_block, - input_default={"name": "in_key_a", "title": "Key A", "value": "A"}, + input_default={ + "name": "in_key_a", + "title": "Key A", + "value": "A", + "advanced": True, + }, metadata={"id": "node_0_a"}, ), Node( @@ -138,8 +143,8 @@ async def test_get_input_schema(server: SpinTestServer): ) class ExpectedInputSchema(BlockSchema): - in_key_a: Any = SchemaField(title="Key A", default="A", advanced=False) - in_key_b: Any = SchemaField(title="in_key_b", advanced=True) + in_key_a: Any = SchemaField(title="Key A", default="A", advanced=True) + in_key_b: Any = SchemaField(title="in_key_b", advanced=False) class ExpectedOutputSchema(BlockSchema): out_key: Any = SchemaField(