Computes the start state of the loop agent from the agent state.
(
self,
agent_state: Optional[LoopAgentState],
)
| 137 | yield self._create_agent_state_event(ctx) |
| 138 | |
| 139 | def _get_start_state( |
| 140 | self, |
| 141 | agent_state: Optional[LoopAgentState], |
| 142 | ) -> tuple[int, int]: |
| 143 | """Computes the start state of the loop agent from the agent state.""" |
| 144 | if not agent_state: |
| 145 | return 0, 0 |
| 146 | |
| 147 | times_looped = agent_state.times_looped |
| 148 | start_index = 0 |
| 149 | if agent_state.current_sub_agent: |
| 150 | try: |
| 151 | sub_agent_names = [sub_agent.name for sub_agent in self.sub_agents] |
| 152 | start_index = sub_agent_names.index(agent_state.current_sub_agent) |
| 153 | except ValueError: |
| 154 | # A sub-agent was removed so the agent name is not found. |
| 155 | # For now, we restart from the beginning. |
| 156 | logger.warning( |
| 157 | 'Sub-agent %s was not found. Restarting from the beginning.', |
| 158 | agent_state.current_sub_agent, |
| 159 | ) |
| 160 | return times_looped, start_index |
| 161 | |
| 162 | @override |
| 163 | async def _run_live_impl( |