Skip to content

Your lightweight open-source personal agent.

Merge branch 'main' into pr-1751

Re-bin231b02963d10
diff --cc nanobot/agent/loop.py
index 531192102,ac8700c10..597f85206
--- a/nanobot/agent/loop.py
+++ b/nanobot/agent/loop.py
@@@ -5,9 -5,6 +5,8 @@@ from __future__ import annotation
import asyncio
import json
import re
+import os
+import sys
- import weakref
from contextlib import AsyncExitStack
from pathlib import Path
from typing import TYPE_CHECKING, Any, Awaitable, Callable
@@@ -394,33 -375,8 +377,17 @@@ class AgentLoop
if 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.py
index 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_key
self._app: Application | None = None
self._chat_ids: dict[str, int] = {} # Map sender_id to chat_id for replies
self._typing_tasks: dict[str, asyncio.Task] = {} # chat_id -> typing loop task