Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix: useasyncio.create_task to avoid block
chengyongru98a762452a8d
diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.pyindex 8f6ef7834..80abae112 100644--- a/nanobot/agent/loop.py+++ b/nanobot/agent/loop.py@@ -21,7 +21,7 @@ from nanobot.agent.tools.spawn import SpawnToolfrom nanobot.agent.tools.cron import CronToolfrom nanobot.agent.memory import MemoryStorefrom nanobot.agent.subagent import SubagentManager-from nanobot.session.manager import SessionManager+from nanobot.session.manager import Session, SessionManagerclass AgentLoop:@@ -243,20 +243,31 @@ class AgentLoop:# Handle slash commandscmd = msg.content.strip().lower()if cmd == "/new":- await self._consolidate_memory(session, archive_all=True)+ # Capture messages before clearing (avoid race condition with background task)+ messages_to_archive = session.messages.copy()session.clear()self.sessions.save(session)# Clear cache to force reload from disk on next requestself.sessions._cache.pop(session.key, None)++ # Consolidate in background (non-blocking)+ async def _consolidate_and_cleanup():+ # Create a temporary session with archived messages+ temp_session = Session(key=session.key)+ temp_session.messages = messages_to_archive+ await self._consolidate_memory(temp_session, archive_all=True)++ asyncio.create_task(_consolidate_and_cleanup())return OutboundMessage(channel=msg.channel, chat_id=msg.chat_id,- content="New session started. Memory consolidated.")+ content="New session started. Memory consolidation in progress.")if cmd == "/help":return OutboundMessage(channel=msg.channel, chat_id=msg.chat_id,content="π nanobot commands:\n/new β Start a new conversation\n/help β Show available commands")# Consolidate memory before processing if session is too large+ # Run in background to avoid blocking main conversationif len(session.messages) > self.memory_window:- await self._consolidate_memory(session)+ asyncio.create_task(self._consolidate_memory(session))# Update tool contextsself._set_tool_context(msg.channel, msg.chat_id)