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
Fix: Ensure UTF-8 encoding for all file operations
chtangwinc7b5dd93502a
diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.pyindex e5a518386..1cd57306d 100644--- a/nanobot/agent/loop.py+++ b/nanobot/agent/loop.py@@ -206,7 +206,7 @@ class AgentLoop:"type": "function","function": {"name": tc.name,- "arguments": json.dumps(tc.arguments)+ "arguments": json.dumps(tc.arguments, ensure_ascii=False)}}for tc in response.tool_calls@@ -388,6 +388,7 @@ class AgentLoop:)final_content, _ = await self._run_agent_loop(initial_messages)+if final_content is None:final_content = "Background task completed."diff --git a/nanobot/agent/subagent.py b/nanobot/agent/subagent.pyindex 203836a89..ffefc080f 100644--- a/nanobot/agent/subagent.py+++ b/nanobot/agent/subagent.py@@ -146,7 +146,7 @@ class SubagentManager:"type": "function","function": {"name": tc.name,- "arguments": json.dumps(tc.arguments),+ "arguments": json.dumps(tc.arguments, ensure_ascii=False),},}for tc in response.tool_calls@@ -159,7 +159,7 @@ class SubagentManager:# Execute toolsfor tool_call in response.tool_calls:- args_str = json.dumps(tool_call.arguments)+ args_str = json.dumps(tool_call.arguments, ensure_ascii=False)logger.debug(f"Subagent [{task_id}] executing: {tool_call.name} with arguments: {args_str}")result = await tools.execute(tool_call.name, tool_call.arguments)messages.append({diff --git a/nanobot/config/loader.py b/nanobot/config/loader.pyindex 560c1f514..134e95fe5 100644--- a/nanobot/config/loader.py+++ b/nanobot/config/loader.py@@ -31,7 +31,7 @@ def load_config(config_path: Path | None = None) -> Config:if path.exists():try:- with open(path) as f:+ with open(path, encoding="utf-8") as f:data = json.load(f)data = _migrate_config(data)return Config.model_validate(data)diff --git a/nanobot/cron/service.py b/nanobot/cron/service.pyindex 14666e820..3c7745261 100644--- a/nanobot/cron/service.py+++ b/nanobot/cron/service.py@@ -66,7 +66,7 @@ class CronService:if self.store_path.exists():try:- data = json.loads(self.store_path.read_text())+ data = json.loads(self.store_path.read_text(encoding="utf-8"))jobs = []for j in data.get("jobs", []):jobs.append(CronJob(@@ -148,7 +148,7 @@ class CronService:]}- self.store_path.write_text(json.dumps(data, indent=2))+ self.store_path.write_text(json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8")async def start(self) -> None:"""Start the cron service."""diff --git a/nanobot/session/manager.py b/nanobot/session/manager.pyindex 752fce423..42df1b1c7 100644--- a/nanobot/session/manager.py+++ b/nanobot/session/manager.py@@ -121,7 +121,7 @@ class SessionManager:created_at = Nonelast_consolidated = 0- with open(path) as f:+ with open(path, encoding="utf-8") as f:for line in f:line = line.strip()if not line:@@ -151,7 +151,7 @@ class SessionManager:"""Save a session to disk."""path = self._get_session_path(session.key)- with open(path, "w") as f:+ with open(path, "w", encoding="utf-8") as f:metadata_line = {"_type": "metadata","created_at": session.created_at.isoformat(),@@ -159,9 +159,10 @@ class SessionManager:"metadata": session.metadata,"last_consolidated": session.last_consolidated}- f.write(json.dumps(metadata_line) + "\n")+ f.write(json.dumps(metadata_line, ensure_ascii=False) + "\n")for msg in session.messages:- f.write(json.dumps(msg) + "\n")+ f.write(json.dumps(msg, ensure_ascii=False) + "\n")+self._cache[session.key] = session@@ -181,7 +182,7 @@ class SessionManager:for path in self.sessions_dir.glob("*.jsonl"):try:# Read just the metadata line- with open(path) as f:+ with open(path, encoding="utf-8") as f:first_line = f.readline().strip()if first_line:data = json.loads(first_line)