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-1985
Xubin Ren570ca474837f
diff --cc nanobot/agent/loop.pyindex 225b9d854,85a6bcfa5..0ad60e7c9--- a/nanobot/agent/loop.py+++ b/nanobot/agent/loop.py@@@ -402,44 -404,12 +413,48 @@@ class AgentLoopsession.clear()self.sessions.save(session)self.sessions.invalidate(session.key)++ if snapshot:+ self._schedule_background(self.memory_consolidator.archive_messages(snapshot))+return OutboundMessage(channel=msg.channel, chat_id=msg.chat_id,content="New session started.")+ if cmd == "/status":+ history = session.get_history(max_messages=0)+ msg_count = len(history)+ active_subs = self.subagents.get_running_count()++ uptime_s = int(time.time() - self._start_time)+ uptime = (+ f"{uptime_s // 3600}h {(uptime_s % 3600) // 60}m"+ if uptime_s >= 3600+ else f"{uptime_s // 60}m {uptime_s % 60}s"+ )++ last_in = self._last_usage.get("prompt_tokens", 0)+ last_out = self._last_usage.get("completion_tokens", 0)++ ctx_used = last_in+ ctx_total_tokens = max(self.context_window_tokens, 0)+ ctx_pct = int((ctx_used / ctx_total_tokens) * 100) if ctx_total_tokens > 0 else 0+ ctx_used_str = f"{ctx_used // 1000}k" if ctx_used >= 1000 else str(ctx_used)+ ctx_total_str = f"{ctx_total_tokens // 1024}k" if ctx_total_tokens > 0 else "n/a"++ lines = [+ f"π nanobot v{__version__}",+ f"π§ Model: {self.model}",+ f"π Tokens: {last_in} in / {last_out} out",+ f"π Context: {ctx_used_str}/{ctx_total_str} ({ctx_pct}%)",+ f"π¬ Session: {msg_count} messages",+ f"πΎ Subagents: {active_subs} active",+ f"πͺ’ Queue: {self.bus.inbound.qsize()} pending",+ f"β± Uptime: {uptime}",+ ]+ return OutboundMessage(+ channel=msg.channel,+ chat_id=msg.chat_id,+ content="\n".join(lines),+ )if cmd == "/help":lines = ["π nanobot commands:",diff --cc nanobot/channels/telegram.pyindex cdf4a5a12,c2b919954..c76350354--- a/nanobot/channels/telegram.py+++ b/nanobot/channels/telegram.py@@@ -378,9 -417,27 +419,24 @@@ class TelegramChannel(BaseChannel)is_progress = msg.metadata.get("_progress", False)for chunk in split_message(msg.content, TELEGRAM_MAX_MESSAGE_LEN):- # Final response: simulate streaming via draft, then persist- if not is_progress:- await self._send_with_streaming(chat_id, chunk, reply_params, thread_kwargs)- else:- await self._send_text(chat_id, chunk, reply_params, thread_kwargs)+ # Use plain send for final responses too; draft streaming can create duplicates.+ await self._send_text(chat_id, chunk, reply_params, thread_kwargs)+ async def _call_with_retry(self, fn, *args, **kwargs):+ """Call an async Telegram API function with retry on pool/network timeout."""+ for attempt in range(1, _SEND_MAX_RETRIES + 1):+ try:+ return await fn(*args, **kwargs)+ except TimedOut:+ if attempt == _SEND_MAX_RETRIES:+ raise+ delay = _SEND_RETRY_BASE_DELAY * (2 ** (attempt - 1))+ logger.warning(+ "Telegram timeout (attempt {}/{}), retrying in {:.1f}s",+ attempt, _SEND_MAX_RETRIES, delay,+ )+ await asyncio.sleep(delay)+async def _send_text(self,chat_id: int,