Add process_until_idle; add tests for cascading scenario. (#136)

* Add process_until_idle; add tests for cascading scenario.

* await publish

* update examples

* update examples

---------

Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com>
This commit is contained in:
Eric Zhu
2024-06-27 11:46:06 -07:00
committed by GitHub
parent ec17dd16ed
commit 8308c928cb
11 changed files with 109 additions and 223 deletions

View File

@@ -308,6 +308,8 @@ class SingleThreadedAgentRuntime(AgentRuntime):
message_envelope.future.set_result(message_envelope.message)
async def process_next(self) -> None:
"""Process the next message in the queue."""
if len(self._message_queue) == 0:
# Yield control to the event loop to allow other tasks to run
await asyncio.sleep(0)
@@ -371,6 +373,12 @@ class SingleThreadedAgentRuntime(AgentRuntime):
# Yield control to the message loop to allow other tasks to run
await asyncio.sleep(0)
async def process_until_idle(self) -> None:
"""Process messages until there is no unprocessed message and no message currently being processed."""
while len(self.unprocessed_messages) > 0 or self.outstanding_tasks > 0:
await self.process_next()
def agent_metadata(self, agent: AgentId) -> AgentMetadata:
return self._get_agent(agent).metadata