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
Merge branch 'main' into pr-1751
Re-bin231b02963d10
diff --cc nanobot/agent/loop.pyindex 531192102,ac8700c10..597f85206--- a/nanobot/agent/loop.py+++ b/nanobot/agent/loop.py@@@ -5,9 -5,6 +5,8 @@@ from __future__ import annotationimport asyncioimport jsonimport re+import os+import sys- import weakreffrom contextlib import AsyncExitStackfrom pathlib import Pathfrom typing import TYPE_CHECKING, Any, Awaitable, Callable@@@ -394,33 -375,8 +377,17 @@@ class AgentLoopif cmd == "/help":return OutboundMessage(channel=msg.channel, chat_id=msg.chat_id,content="π nanobot commands:\n/new β Start a new conversation\n/stop β Stop the current task\n/help β Show available commands")+ if cmd == "/restart":+ await self.bus.publish_outbound(OutboundMessage(+ channel=msg.channel, chat_id=msg.chat_id, content="π Restarting..."+ ))+ async def _r():+ await asyncio.sleep(1)+ os.execv(sys.executable, [sys.executable] + sys.argv)+ asyncio.create_task(_r())+ return None- unconsolidated = len(session.messages) - session.last_consolidated- if (unconsolidated >= self.memory_window and session.key not in self._consolidating):- self._consolidating.add(session.key)- lock = self._consolidation_locks.setdefault(session.key, asyncio.Lock())-- async def _consolidate_and_unlock():- try:- async with lock:- await self._consolidate_memory(session)- finally:- self._consolidating.discard(session.key)- _task = asyncio.current_task()- if _task is not None:- self._consolidation_tasks.discard(_task)-- _task = asyncio.create_task(_consolidate_and_unlock())- self._consolidation_tasks.add(_task)+ await self.memory_consolidator.maybe_consolidate_by_tokens(session)self._set_tool_context(msg.channel, msg.chat_id, msg.metadata.get("message_id"))if message_tool := self.tools.get("message"):diff --cc nanobot/channels/telegram.pyindex f37ab1d2b,9f9384304..316e166a6--- a/nanobot/channels/telegram.py+++ b/nanobot/channels/telegram.py@@@ -162,18 -163,11 +163,12 @@@ class TelegramChannel(BaseChannel)BotCommand("new", "Start a new conversation"),BotCommand("stop", "Stop the current task"),BotCommand("help", "Show available commands"),+ BotCommand("restart", "Restart the bot"),]- def __init__(- self,- config: TelegramConfig,- bus: MessageBus,- groq_api_key: str = "",- ):+ def __init__(self, config: TelegramConfig, bus: MessageBus):super().__init__(config, bus)self.config: TelegramConfig = config- self.groq_api_key = groq_api_keyself._app: Application | None = Noneself._chat_ids: dict[str, int] = {} # Map sender_id to chat_id for repliesself._typing_tasks: dict[str, asyncio.Task] = {} # chat_id -> typing loop task