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-866
Re-bin8c1545437982
diff --cc nanobot/agent/loop.pyindex e9e225c97,2348df77f..f8eb000a5--- a/nanobot/agent/loop.py+++ b/nanobot/agent/loop.py@@@ -1,29 -1,36 +1,35 @@@"""Agent loop: the core processing engine."""+ from __future__ import annotations+import asyncio- from contextlib import AsyncExitStackimport json- from pathlib import Pathimport re- from typing import Any, Awaitable, Callable+ from contextlib import AsyncExitStack+ from pathlib import Path+ from typing import TYPE_CHECKING, Awaitable, Callable-import json_repairfrom loguru import logger- from nanobot.bus.events import InboundMessage, OutboundMessage- from nanobot.bus.queue import MessageBus- from nanobot.providers.base import LLMProviderfrom nanobot.agent.context import ContextBuilder+ from nanobot.agent.memory import MemoryStore+ from nanobot.agent.subagent import SubagentManager+ from nanobot.agent.tools.cron import CronTool+ from nanobot.agent.tools.filesystem import EditFileTool, ListDirTool, ReadFileTool, WriteFileTool+ from nanobot.agent.tools.message import MessageToolfrom nanobot.agent.tools.registry import ToolRegistry- from nanobot.agent.tools.filesystem import ReadFileTool, WriteFileTool, EditFileTool, ListDirToolfrom nanobot.agent.tools.shell import ExecTool- from nanobot.agent.tools.web import WebSearchTool, WebFetchTool- from nanobot.agent.tools.message import MessageToolfrom nanobot.agent.tools.spawn import SpawnTool- from nanobot.agent.tools.cron import CronTool- from nanobot.agent.memory import MemoryStore- from nanobot.agent.subagent import SubagentManager+ from nanobot.agent.tools.web import WebFetchTool, WebSearchTool+ from nanobot.bus.events import InboundMessage, OutboundMessage+ from nanobot.bus.queue import MessageBus+ from nanobot.providers.base import LLMProviderfrom nanobot.session.manager import Session, SessionManager+ if TYPE_CHECKING:+ from nanobot.config.schema import ExecToolConfig+ from nanobot.cron.service import CronService+class AgentLoop:"""@@@ -473,21 -519,31 +528,25 @@@try:response = await self.provider.chat(messages=[- {"role": "system", "content": "You are a memory consolidation agent. Respond only with valid JSON."},+ {"role": "system", "content": "You are a memory consolidation agent. Call the save_memory tool with your consolidation of the conversation."},{"role": "user", "content": prompt},],+ tools=save_memory_tool,model=self.model,)- text = (response.content or "").strip()- if not text:- logger.warning("Memory consolidation: LLM returned empty response, skipping")- return- if text.startswith("```"):- text = text.split("\n", 1)[-1].rsplit("```", 1)[0].strip()- result = json_repair.loads(text)- if not isinstance(result, dict):- logger.warning("Memory consolidation: unexpected response type, skipping. Response: {}", text[:200])++ if not response.has_tool_calls:+ logger.warning("Memory consolidation: LLM did not call save_memory tool, skipping")return- if entry := result.get("history_entry"):- # Defensive: ensure entry is a string (LLM may return dict)+ args = response.tool_calls[0].arguments+ if entry := args.get("history_entry"):+ if not isinstance(entry, str):+ entry = json.dumps(entry, ensure_ascii=False)memory.append_history(entry)- if update := result.get("memory_update"):- # Defensive: ensure update is a string+ if update := args.get("memory_update"):+ if not isinstance(update, str):+ update = json.dumps(update, ensure_ascii=False)if update != current_memory:memory.write_long_term(update)