Loads the agent state from the invocation context. Args: ctx: The invocation context. state_type: The type of the agent state. Returns: The current state if exists; otherwise, None.
(
self,
ctx: InvocationContext,
state_type: Type[AgentState],
)
| 176 | """ |
| 177 | |
| 178 | def _load_agent_state( |
| 179 | self, |
| 180 | ctx: InvocationContext, |
| 181 | state_type: Type[AgentState], |
| 182 | ) -> Optional[AgentState]: |
| 183 | """Loads the agent state from the invocation context. |
| 184 | |
| 185 | Args: |
| 186 | ctx: The invocation context. |
| 187 | state_type: The type of the agent state. |
| 188 | |
| 189 | Returns: |
| 190 | The current state if exists; otherwise, None. |
| 191 | """ |
| 192 | if ctx.agent_states is None or self.name not in ctx.agent_states: |
| 193 | return None |
| 194 | else: |
| 195 | return state_type.model_validate(ctx.agent_states.get(self.name)) |
| 196 | |
| 197 | def _create_agent_state_event( |
| 198 | self, |