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 main
Jack Lu3ee061b8793b
diff --cc nanobot/agent/subagent.pyindex 5aff25c63,a99ba4d94..9b543dc40--- a/nanobot/agent/subagent.py+++ b/nanobot/agent/subagent.py@@@ -126,8 -126,9 +127,9 @@@ class SubagentManagermodel=self.model,temperature=self.temperature,max_tokens=self.max_tokens,+ reasoning_effort=self.reasoning_effort,)-+if response.has_tool_calls:# Add assistant message with tool callstool_call_dicts = [@@@ -201,47 -202,32 +203,32 @@@ Summarize this naturally for the user.chat_id=f"{origin['channel']}:{origin['chat_id']}",content=announce_content,)-+await self.bus.publish_inbound(msg)logger.debug("Subagent [{}] announced result to {}:{}", task_id, origin['channel'], origin['chat_id'])-- def _build_subagent_prompt(self, task: str) -> str:++ def _build_subagent_prompt(self) -> str:"""Build a focused system prompt for the subagent."""- import time as _time- from datetime import datetime- now = datetime.now().strftime("%Y-%m-%d %H:%M (%A)")- tz = _time.strftime("%Z") or "UTC"+ from nanobot.agent.context import ContextBuilder+ from nanobot.agent.skills import SkillsLoader- return f"""# Subagent+ time_ctx = ContextBuilder._build_runtime_context(None, None)+ parts = [f"""# Subagent- ## Current Time- {now} ({tz})+ {time_ctx}You are a subagent spawned by the main agent to complete a specific task.-- ## Rules- 1. Stay focused - complete only the assigned task, nothing else- 2. Your final response will be reported back to the main agent- 3. Do not initiate conversations or take on side tasks- 4. Be concise but informative in your findings-- ## What You Can Do- - Read and write files in the workspace- - Execute shell commands- - Search the web and fetch web pages- - Complete the task thoroughly-- ## What You Cannot Do- - Send messages directly to users (no message tool available)- - Spawn other subagents- - Access the main agent's conversation history+ Stay focused on the assigned task. Your final response will be reported back to the main agent.## Workspace- Your workspace is at: {self.workspace}- Skills are available at: {self.workspace}/skills/ (read SKILL.md files as needed)+ {self.workspace}"""]- When you have completed the task, provide a clear summary of your findings or actions."""+ skills_summary = SkillsLoader(self.workspace).build_skills_summary()+ if skills_summary:+ parts.append(f"## Skills\n\nRead SKILL.md with read_file to use a skill.\n\n{skills_summary}")+ return "\n\n".join(parts)+async def cancel_by_session(self, session_key: str) -> int:"""Cancel all subagents for the given session. Returns count cancelled."""tasks = [self._running_tasks[tid] for tid in self._session_tasks.get(session_key, [])diff --cc nanobot/channels/dingtalk.pyindex 371c45b0b,279702996..8d02fa6cd--- a/nanobot/channels/dingtalk.py+++ b/nanobot/channels/dingtalk.py@@@ -2,11 -2,15 +2,15 @@@import asyncioimport json+ import mimetypes+ import osimport time+ from pathlib import Pathfrom typing import Any+ from urllib.parse import unquote, urlparse-from loguru import loggerimport httpx+from loguru import loggerfrom nanobot.bus.events import OutboundMessagefrom nanobot.bus.queue import MessageBusdiff --cc nanobot/channels/feishu.pyindex 9911d08d2,c632fb7d2..5a86e732d--- a/nanobot/channels/feishu.py+++ b/nanobot/channels/feishu.py@@@ -324,17 -324,18 +324,18 @@@ class FeishuChannel(BaseChannel)# Keep running until stoppedwhile self._running:await asyncio.sleep(1)-+async def stop(self) -> None:- """Stop the Feishu bot."""+ """+ Stop the Feishu bot.++ Notice: lark.ws.Client does not expose stop method, simply exiting the program will close the client.++ Reference: https://github.com/larksuite/oapi-sdk-python/blob/v2_main/lark_oapi/ws/client.py#L86+ """self._running = False- if self._ws_client:- try:- self._ws_client.stop()- except Exception as e:- logger.warning("Error stopping WebSocket client: {}", e)logger.info("Feishu bot stopped")-+def _add_reaction_sync(self, message_id: str, emoji_type: str) -> None:"""Sync helper for adding reaction (runs in thread pool)."""try:diff --cc nanobot/providers/litellm_provider.pyindex 931e0386a,aff2ac7bf..79277bc64--- a/nanobot/providers/litellm_provider.py+++ b/nanobot/providers/litellm_provider.py@@@ -12,9 -13,10 +12,9 @@@ from litellm import acompletiofrom nanobot.providers.base import LLMProvider, LLMResponse, ToolCallRequestfrom nanobot.providers.registry import find_by_model, find_gateway-# Standard OpenAI chat-completion message keys plus reasoning_content for# thinking-enabled models (Kimi k2.5, DeepSeek-R1, etc.).- _ALLOWED_MSG_KEYS = frozenset({"role", "content", "tool_calls", "tool_call_id", "name", "reasoning_content"})+ _ALLOWED_MSG_KEYS = frozenset({"role", "content", "tool_calls", "tool_call_id", "name", "reasoning_content", "thinking_blocks"})_ALNUM = string.ascii_letters + string.digitsdef _short_tool_id() -> str:@@@ -262,17 -269,19 +267,19 @@@ class LiteLLMProvider(LLMProvider)"completion_tokens": response.usage.completion_tokens,"total_tokens": response.usage.total_tokens,}-+reasoning_content = getattr(message, "reasoning_content", None) or None-+ thinking_blocks = getattr(message, "thinking_blocks", None) or None+return LLMResponse(content=message.content,tool_calls=tool_calls,finish_reason=choice.finish_reason or "stop",usage=usage,reasoning_content=reasoning_content,+ thinking_blocks=thinking_blocks,)-+def get_default_model(self) -> str:"""Get the default model."""return self.default_model