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
refactor: merge user-role branches in _save_turn
Re-binbc558d0592c1
diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.pyindex 69c2916a9..6fe37e910 100644--- a/nanobot/agent/loop.py+++ b/nanobot/agent/loop.py@@ -444,24 +444,19 @@ class AgentLoop:from datetime import datetimefor m in messages[skip:]:entry = {k: v for k, v in m.items() if k != "reasoning_content"}- if entry.get("role") == "tool" and isinstance(entry.get("content"), str):- content = entry["content"]- if len(content) > self._TOOL_RESULT_MAX_CHARS:- entry["content"] = content[:self._TOOL_RESULT_MAX_CHARS] + "\n... (truncated)"- if (- entry.get("role") == "user"- and isinstance(entry.get("content"), str)- and entry["content"].startswith(ContextBuilder._RUNTIME_CONTEXT_TAG)- ):- continue- if entry.get("role") == "user" and isinstance(entry.get("content"), list):- entry["content"] = [- {"type": "text", "text": "[image]"} if (- c.get("type") == "image_url"- and c.get("image_url", {}).get("url", "").startswith("data:image/")- ) else c- for c in entry["content"]- ]+ role, content = entry.get("role"), entry.get("content")+ if role == "tool" and isinstance(content, str) and len(content) > self._TOOL_RESULT_MAX_CHARS:+ entry["content"] = content[:self._TOOL_RESULT_MAX_CHARS] + "\n... (truncated)"+ elif role == "user":+ if isinstance(content, str) and content.startswith(ContextBuilder._RUNTIME_CONTEXT_TAG):+ continue+ if isinstance(content, list):+ entry["content"] = [+ {"type": "text", "text": "[image]"} if (+ c.get("type") == "image_url"+ and c.get("image_url", {}).get("url", "").startswith("data:image/")+ ) else c for c in content+ ]entry.setdefault("timestamp", datetime.now().isoformat())session.messages.append(entry)session.updated_at = datetime.now()