Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/google/adk/workflow/utils/_rehydration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def _validate_resume_response(response_data: object, schema: object) -> object:
else:
fields[prop_name] = (
prop_type | None,
None,
prop_schema.get("default"),
)

try:
Expand Down
48 changes: 48 additions & 0 deletions tests/unittests/workflow/utils/test_rehydration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,54 @@ def test_string_schema_is_not_evaluated(self, tmp_path):
assert _validate_resume_response("data", schema) == "data"
assert not marker.exists()

def test_object_schema_uses_declared_defaults_for_missing_fields(self):
"""A partial resume answer keeps the optional fields' schema defaults."""

class Decision(BaseModel):
approved: bool
priority: int = 3
tags: list[str] = []
reviewer: str = "manager"

answer = _validate_resume_response(
{"approved": True}, Decision.model_json_schema()
)

assert answer == {
"approved": True,
"priority": 3,
"tags": [],
"reviewer": "manager",
}
# The next node rebuilds the model from this answer; it must not fail.
assert Decision.model_validate(answer) == Decision(approved=True)

def test_object_schema_explicit_values_override_declared_defaults(self):
"""A provided optional field wins over its schema default."""

class Decision(BaseModel):
approved: bool
priority: int = 3
tags: list[str] = []
reviewer: str = "manager"

answer = _validate_resume_response(
{
"approved": False,
"priority": 7,
"tags": ["urgent"],
"reviewer": "director",
},
Decision.model_json_schema(),
)

assert answer == {
"approved": False,
"priority": 7,
"tags": ["urgent"],
"reviewer": "director",
}


# --- _reconstruct_node_states ---

Expand Down