mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat: Add setdefault method to the ADK State object
This makes the ADK state more pythonic, with the State API being more like a python dict. PiperOrigin-RevId: 796767559
This commit is contained in:
committed by
Copybara-Service
parent
4afc9b2f33
commit
77ed1f5f15
@@ -48,6 +48,14 @@ class State:
|
|||||||
"""Whether the state dict contains the given key."""
|
"""Whether the state dict contains the given key."""
|
||||||
return key in self._value or key in self._delta
|
return key in self._value or key in self._delta
|
||||||
|
|
||||||
|
def setdefault(self, key: str, default: Any = None) -> Any:
|
||||||
|
"""Gets the value of a key, or sets it to a default if the key doesn't exist."""
|
||||||
|
if key in self:
|
||||||
|
return self[key]
|
||||||
|
else:
|
||||||
|
self[key] = default
|
||||||
|
return default
|
||||||
|
|
||||||
def has_delta(self) -> bool:
|
def has_delta(self) -> bool:
|
||||||
"""Whether the state has pending delta."""
|
"""Whether the state has pending delta."""
|
||||||
return bool(self._delta)
|
return bool(self._delta)
|
||||||
|
|||||||
Reference in New Issue
Block a user