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
feat: add /status command to show runtime info
robbyczgw-claa628741459bd
diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.pyindex e05a73e49..b152e3f3f 100644--- a/nanobot/agent/loop.py+++ b/nanobot/agent/loop.py@@ -7,12 +7,14 @@ import jsonimport osimport reimport sys+import timefrom contextlib import AsyncExitStackfrom pathlib import Pathfrom typing import TYPE_CHECKING, Any, Awaitable, Callablefrom loguru import logger+from nanobot import __version__from nanobot.agent.context import ContextBuilderfrom nanobot.agent.memory import MemoryConsolidatorfrom nanobot.agent.subagent import SubagentManager@@ -78,6 +80,8 @@ class AgentLoop:self.exec_config = exec_config or ExecToolConfig()self.cron_service = cron_serviceself.restrict_to_workspace = restrict_to_workspace+ self._start_time = time.time()+ self._last_usage: dict[str, int] = {}self.context = ContextBuilder(workspace)self.sessions = session_manager or SessionManager(workspace)@@ -197,6 +201,11 @@ class AgentLoop:tools=tool_defs,model=self.model,)+ if response.usage:+ self._last_usage = {+ "prompt_tokens": int(response.usage.get("prompt_tokens", 0) or 0),+ "completion_tokens": int(response.usage.get("completion_tokens", 0) or 0),+ }if response.has_tool_calls:if on_progress:@@ -392,12 +401,49 @@ class AgentLoop:self.sessions.invalidate(session.key)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:","/new β Start a new conversation","/stop β Stop the current task","/restart β Restart the bot",+ "/status β Show bot status","/help β Show available commands",]return OutboundMessage(diff --git a/nanobot/channels/telegram.py b/nanobot/channels/telegram.pyindex 916685b10..d04205297 100644--- a/nanobot/channels/telegram.py+++ b/nanobot/channels/telegram.py@@ -165,6 +165,7 @@ class TelegramChannel(BaseChannel):BotCommand("stop", "Stop the current task"),BotCommand("help", "Show available commands"),BotCommand("restart", "Restart the bot"),+ BotCommand("status", "Show bot status"),]def __init__(self, config: TelegramConfig, bus: MessageBus):@@ -223,6 +224,7 @@ class TelegramChannel(BaseChannel):self._app.add_handler(CommandHandler("new", self._forward_command))self._app.add_handler(CommandHandler("stop", self._forward_command))self._app.add_handler(CommandHandler("restart", self._forward_command))+ self._app.add_handler(CommandHandler("status", self._forward_command))self._app.add_handler(CommandHandler("help", self._on_help))# Add message handler for text, photos, voice, documents@@ -434,6 +436,7 @@ class TelegramChannel(BaseChannel):"π nanobot commands:\n""/new β Start a new conversation\n""/stop β Stop the current task\n"+ "/status β Show bot status\n""/help β Show available commands")