chore: Returns agent state regardless if ctx.is_resumable

This allows state to be passing across agents

PiperOrigin-RevId: 828665491
This commit is contained in:
Google Team Member
2025-11-05 15:59:57 -08:00
committed by Copybara-Service
parent 59d422ca21
commit 48681cb31b
+6 -3
View File
@@ -164,16 +164,19 @@ class BaseAgent(BaseModel):
ctx: InvocationContext,
state_type: Type[AgentState],
) -> Optional[AgentState]:
"""Loads the agent state from the invocation context.
"""Loads the agent state from the invocation context, handling resumption.
Args:
ctx: The invocation context.
state_type: The type of the agent state.
Returns:
The current state if exists, otherwise None.
The current state if resuming, otherwise None.
"""
if ctx.agent_states is None or self.name not in ctx.agent_states:
if not ctx.is_resumable:
return None
if self.name not in ctx.agent_states:
return None
else:
return state_type.model_validate(ctx.agent_states.get(self.name))