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: use json_repair for robust LLM response parsing
Re-bin49fec3684ad1
diff --git a/README.md b/README.mdindex c08d3afbe..9066d5ac1 100644--- a/README.md+++ b/README.md@@ -16,7 +16,7 @@⚡️ Delivers core agent functionality in just **~4,000** lines of code — **99% smaller** than Clawdbot's 430k+ lines.-📏 Real-time line count: **3,656 lines** (run `bash core_agent_lines.sh` to verify anytime)+📏 Real-time line count: **3,663 lines** (run `bash core_agent_lines.sh` to verify anytime)## 📢 Newsdiff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.pyindex 7deef59ad..6342f567f 100644--- a/nanobot/agent/loop.py+++ b/nanobot/agent/loop.py@@ -3,6 +3,7 @@import asynciofrom contextlib import AsyncExitStackimport json+import json_repairfrom pathlib import Pathfrom typing import Any@@ -420,9 +421,15 @@ Respond with ONLY valid JSON, no markdown fences."""model=self.model,)text = (response.content or "").strip()+ if not text:+ logger.warning("Memory consolidation: LLM returned empty response, skipping")+ returnif text.startswith("```"):text = text.split("\n", 1)[-1].rsplit("```", 1)[0].strip()- result = json.loads(text)+ result = json_repair.loads(text)+ if not isinstance(result, dict):+ logger.warning(f"Memory consolidation: unexpected response type, skipping. Response: {text[:200]}")+ returnif entry := result.get("history_entry"):memory.append_history(entry)diff --git a/nanobot/providers/litellm_provider.py b/nanobot/providers/litellm_provider.pyindex a39893be4..ed4cf49a1 100644--- a/nanobot/providers/litellm_provider.py+++ b/nanobot/providers/litellm_provider.py@@ -1,6 +1,7 @@"""LiteLLM provider implementation for multi-provider support."""import json+import json_repairimport osfrom typing import Any@@ -173,10 +174,7 @@ class LiteLLMProvider(LLMProvider):# Parse arguments from JSON string if neededargs = tc.function.argumentsif isinstance(args, str):- try:- args = json.loads(args)- except json.JSONDecodeError:- args = {"raw": args}+ args = json_repair.loads(args)tool_calls.append(ToolCallRequest(id=tc.id,diff --git a/pyproject.toml b/pyproject.tomlindex 17c739f21..147e799bb 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -39,6 +39,7 @@ dependencies = ["python-socks[asyncio]>=2.4.0","prompt-toolkit>=3.0.0","mcp>=1.0.0",+ "json-repair>=0.30.0",][project.optional-dependencies]