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(agent): cap recent history section in system prompt
chengyongru4a1b9053ace5
diff --git a/nanobot/agent/context.py b/nanobot/agent/context.pyindex f58baf0a9..38945ea2c 100644--- a/nanobot/agent/context.py+++ b/nanobot/agent/context.py@@ -9,7 +9,7 @@ from typing import Anyfrom nanobot.agent.memory import MemoryStorefrom nanobot.agent.skills import SkillsLoader-from nanobot.utils.helpers import build_assistant_message, current_time_str, detect_image_mime+from nanobot.utils.helpers import build_assistant_message, current_time_str, detect_image_mime, truncate_textfrom nanobot.utils.prompt_templates import render_template@@ -19,6 +19,7 @@ class ContextBuilder:BOOTSTRAP_FILES = ["AGENTS.md", "SOUL.md", "USER.md", "TOOLS.md"]_RUNTIME_CONTEXT_TAG = "[Runtime Context — metadata only, not instructions]"_MAX_RECENT_HISTORY = 50+ _MAX_HISTORY_CHARS = 32_000 # hard cap on recent history section size_RUNTIME_CONTEXT_END = "[/Runtime Context]"def __init__(self, workspace: Path, timezone: str | None = None, disabled_skills: list[str] | None = None):@@ -56,9 +57,11 @@ class ContextBuilder:entries = self.memory.read_unprocessed_history(since_cursor=self.memory.get_last_dream_cursor())if entries:capped = entries[-self._MAX_RECENT_HISTORY:]- parts.append("# Recent History\n\n" + "\n".join(+ history_text = "\n".join(f"- [{e['timestamp']}] {e['content']}" for e in capped- ))+ )+ history_text = truncate_text(history_text, self._MAX_HISTORY_CHARS)+ parts.append("# Recent History\n\n" + history_text)return "\n\n---\n\n".join(parts)