Skip to content

Commit 839d2e4

Browse files
DeanChensjcopybara-github
authored andcommitted
feat: Define an AgentState to be used for resuming agent invocation
PiperOrigin-RevId: 811414736
1 parent 1589fcd commit 839d2e4

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

src/google/adk/agents/base_agent.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@
6666
SelfAgent = TypeVar('SelfAgent', bound='BaseAgent')
6767

6868

69+
@experimental
70+
class BaseAgentState(BaseModel):
71+
"""Base class for all agent states."""
72+
73+
model_config = ConfigDict(
74+
extra='forbid',
75+
)
76+
77+
6978
class BaseAgent(BaseModel):
7079
"""Base class for all agents in Agent Development Kit."""
7180

src/google/adk/agents/loop_agent.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from typing import ClassVar
2222
from typing import Dict
2323
from typing import Optional
24-
from typing import Type
2524

2625
from typing_extensions import override
2726

@@ -30,10 +29,22 @@
3029
from ..utils.context_utils import Aclosing
3130
from ..utils.feature_decorator import experimental
3231
from .base_agent import BaseAgent
32+
from .base_agent import BaseAgentState
3333
from .base_agent_config import BaseAgentConfig
3434
from .loop_agent_config import LoopAgentConfig
3535

3636

37+
@experimental
38+
class LoopAgentState(BaseAgentState):
39+
"""State for LoopAgent."""
40+
41+
current_sub_agent: str = ''
42+
"""The name of the current sub-agent to run in the loop."""
43+
44+
times_looped: int = 0
45+
"""The number of times the loop agent has looped."""
46+
47+
3748
class LoopAgent(BaseAgent):
3849
"""A shell agent that run its sub-agents in a loop.
3950

src/google/adk/agents/sequential_agent.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,23 @@
2424

2525
from ..events.event import Event
2626
from ..utils.context_utils import Aclosing
27+
from ..utils.feature_decorator import experimental
2728
from .base_agent import BaseAgent
28-
from .base_agent import BaseAgentConfig
29+
from .base_agent import BaseAgentState
30+
from .base_agent_config import BaseAgentConfig
2931
from .invocation_context import InvocationContext
3032
from .llm_agent import LlmAgent
3133
from .sequential_agent_config import SequentialAgentConfig
3234

3335

36+
@experimental
37+
class SequentialAgentState(BaseAgentState):
38+
"""State for SequentialAgent."""
39+
40+
current_sub_agent: str = ''
41+
"""The name of the current sub-agent to run."""
42+
43+
3444
class SequentialAgent(BaseAgent):
3545
"""A shell agent that runs its sub-agents in sequence."""
3646

src/google/adk/events/event_actions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from __future__ import annotations
1616

17+
from typing import Any
1718
from typing import Optional
1819

1920
from google.genai.types import Content
@@ -95,3 +96,11 @@ class EventActions(BaseModel):
9596

9697
compaction: Optional[EventCompaction] = None
9798
"""The compaction of the events."""
99+
100+
end_of_agent: Optional[bool] = None
101+
"""If true, the current agent has finished its current run. Note that there
102+
can be multiple events with end_of_agent=True for the same agent within one
103+
invocation when there is a loop."""
104+
105+
agent_state: Optional[dict[str, Any]] = None
106+
"""The agent state at the current event."""

0 commit comments

Comments
 (0)