Skip to content

Your lightweight open-source personal agent.

refactor(loop): extract _build_retry_wait_callback

chengyongrud2cb8ac17fd2
diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.py
index 10f94eeac..8943a06dd 100644
--- a/nanobot/agent/loop.py
+++ b/nanobot/agent/loop.py
@@ -591,6 +591,25 @@ class AgentLoop:
return _bus_progress
+ async def _build_retry_wait_callback(
+ self, msg: InboundMessage
+ ) -> Callable[[str], Awaitable[None]]:
+ """Build a retry-wait callback that publishes to the message bus."""
+
+ async def _on_retry_wait(content: str) -> None:
+ meta = dict(msg.metadata or {})
+ meta["_retry_wait"] = True
+ await self.bus.publish_outbound(
+ OutboundMessage(
+ channel=msg.channel,
+ chat_id=msg.chat_id,
+ content=content,
+ metadata=meta,
+ )
+ )
+
+ return _on_retry_wait
+
async def _dispatch_command_inline(
self,
msg: InboundMessage,
@@ -1192,18 +1211,7 @@ class AgentLoop:
)
_bus_progress = await self._build_bus_progress_callback(msg)
-
- async def _on_retry_wait(content: str) -> None:
- meta = dict(msg.metadata or {})
- meta["_retry_wait"] = True
- await self.bus.publish_outbound(
- OutboundMessage(
- channel=msg.channel,
- chat_id=msg.chat_id,
- content=content,
- metadata=meta,
- )
- )
+ _on_retry_wait = await self._build_retry_wait_callback(msg)
# Persist the triggering user message up front so a mid-turn crash
# doesn't silently lose the prompt on recovery. ``media`` rides along