MCPcopy
hub / github.com/agent0ai/agent-zero / managed_wait

Function managed_wait

helpers/wait.py:42–68  ·  view source on GitHub ↗
(agent, target_time, is_duration_wait, log, get_heading_callback)

Source from the content-addressed store, hash-verified

40
41
42async def managed_wait(agent, target_time, is_duration_wait, log, get_heading_callback):
43
44 while Localization.get().now() < target_time:
45 before_intervention = Localization.get().now()
46 await agent.handle_intervention()
47 after_intervention = Localization.get().now()
48
49 if is_duration_wait:
50 pause_duration = after_intervention - before_intervention
51 if pause_duration.total_seconds() > 1.5: # Adjust for pauses longer than the sleep cycle
52 target_time += pause_duration
53 PrintStyle.info(
54 f"Wait extended by {pause_duration.total_seconds():.1f}s to {Localization.get().serialize_datetime(target_time)}...",
55 )
56
57 current_time = Localization.get().now()
58 if current_time >= target_time:
59 break
60
61 remaining_seconds = (target_time - current_time).total_seconds()
62 if log:
63 log.update(heading=get_heading_callback(format_remaining_time(remaining_seconds)))
64 sleep_duration = min(1.0, remaining_seconds)
65
66 await asyncio.sleep(sleep_duration)
67
68 return target_time

Callers 1

executeMethod · 0.90

Calls 7

format_remaining_timeFunction · 0.85
serialize_datetimeMethod · 0.80
nowMethod · 0.45
getMethod · 0.45
handle_interventionMethod · 0.45
infoMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected