Skip to content

Commit

Permalink
fix(platform): Fields with default value are not set to advanced by d…
Browse files Browse the repository at this point in the history
…efault (#9128)

#8739 causes input
fields that are supposed to be an advanced field end up being a
mandatory field:


![image](https://github.com/user-attachments/assets/1cb41a79-fe85-4012-91b8-861bd5f9a0ca)

*See the retry count field here.

### Changes 🏗️

Set the `advanced` field on each input field, and set the default value
using this logic:
* If it has a default value, set it to True.
* otherwise, False.

### Checklist 📋

#### For code changes:
- [ ] I have clearly listed my changes in the PR description
- [ ] I have made a test plan
- [ ] I have tested my changes according to the test plan:
  <!-- Put your test plan here: -->
  - [ ] ...

<details>
  <summary>Example test plan</summary>
  
  - [ ] Create from scratch and execute an agent with at least 3 blocks
- [ ] Import an agent from file upload, and confirm it executes
correctly
  - [ ] Upload agent to marketplace
- [ ] Import an agent from marketplace and confirm it executes correctly
  - [ ] Edit an agent from monitor, and confirm it executes correctly
</details>

#### For configuration changes:
- [ ] `.env.example` is updated or already compatible with my changes
- [ ] `docker-compose.yml` is updated or already compatible with my
changes
- [ ] I have included a list of my configuration changes in the PR
description (under **Changes**)

<details>
  <summary>Examples of configuration changes</summary>

  - Changing ports
  - Adding new services that need to communicate with each other
  - Secrets or environment variable changes
  - New or infrastructure changes such as databases
</details>

---------

Co-authored-by: Swifty <[email protected]>
  • Loading branch information
majdyz and Swiftyos authored Dec 31, 2024
1 parent 314b04e commit 1ce1918
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
5 changes: 0 additions & 5 deletions autogpt_platform/backend/backend/data/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion autogpt_platform/backend/backend/data/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}),
Expand Down
7 changes: 6 additions & 1 deletion autogpt_platform/backend/backend/data/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 8 additions & 3 deletions autogpt_platform/backend/test/data/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1ce1918

Please sign in to comment.