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): trim redundant system prompt context
chengyongru32f5cc76a43d
diff --git a/nanobot/agent/context.py b/nanobot/agent/context.pyindex 7277705b9..825999fd8 100644--- a/nanobot/agent/context.py+++ b/nanobot/agent/context.py@@ -113,7 +113,7 @@ class ContextBuilder:if include_memory:memory = self.memory.read_memory()if memory and not self._is_template_content(memory, "memory/MEMORY.md"):- parts.append(f"# Memory\n\n## Long-term Memory\n{memory}")+ parts.append(memory)with self.skills.snapshot():active_skills = self.skills.get_always_skills()diff --git a/nanobot/agent/skills.py b/nanobot/agent/skills.pyindex cc19ae238..5c010680a 100644--- a/nanobot/agent/skills.py+++ b/nanobot/agent/skills.py@@ -252,7 +252,7 @@ class SkillsLoader:workspace: Path | None = None,) -> str:"""- Build a summary of all skills (name, description, path, availability).+ Build a summary of available skills (name, description, path).This is used for progressive loading - the agent can read the fullskill content using read_file when needed.@@ -268,7 +268,7 @@ class SkillsLoader:return self._build_skills_summary(exclude, workspace=workspace)def _build_skills_summary(self, exclude: set[str] | None, *, workspace: Path | None) -> str:- all_skills = self.list_skills(filter_unavailable=False)+ all_skills = self.list_skills(filter_unavailable=True)if not all_skills:return ""@@ -300,15 +300,9 @@ class SkillsLoader:lines = [f"### {label} (`{display_root}`)"]for entry in entries:skill_name = entry["name"]- meta = self._get_skill_meta(skill_name)- available = self._check_requirements(meta)desc = self.get_skill_description(skill_name)- suffix = ""- if not available:- missing = self._get_missing_requirements(meta)- suffix = f" (unavailable: {missing})" if missing else " (unavailable)"relative_path = Path(entry["path"]).relative_to(root).as_posix()- lines.append(f"- **{skill_name}** — {desc}{suffix} `{relative_path}`")+ lines.append(f"- **{skill_name}** — {desc} `{relative_path}`")sections.append("\n".join(lines))return "\n\n".join(sections)diff --git a/nanobot/templates/agent/identity.md b/nanobot/templates/agent/identity.mdindex 8ca90c663..8c05799b5 100644--- a/nanobot/templates/agent/identity.md+++ b/nanobot/templates/agent/identity.md@@ -1,5 +1,6 @@## Runtime{{ runtime }}+{{ platform_policy }}## Workspace{% if agent_workspace_path != workspace_path %}@@ -17,7 +18,6 @@ Nanobot's agent workspace is at: {{ agent_workspace_path }}Only Dream memory-consolidation tasks may edit the profile and long-term memory files listed above.-{{ platform_policy }}{% if channel == 'telegram' or channel == 'qq' or channel == 'discord' %}## Format HintThis conversation is on a messaging app. Use short paragraphs. Avoid large headings (#, ##). Use **bold** sparingly. No tables — use plain lists.diff --git a/nanobot/templates/agent/platform_policy.md b/nanobot/templates/agent/platform_policy.mdindex a47e104e4..ac4d8fc54 100644--- a/nanobot/templates/agent/platform_policy.md+++ b/nanobot/templates/agent/platform_policy.md@@ -1,10 +1,8 @@{% if system == 'Windows' %}-## Platform Policy (Windows)-- You are running on Windows. Do not assume GNU tools like `grep`, `sed`, or `awk` exist.+- Do not assume GNU tools like `grep`, `sed`, or `awk` exist.- Prefer Windows-native commands or file tools when they are more reliable.- If terminal output is garbled, retry with UTF-8 output enabled.{% else %}-## Platform Policy (POSIX)-- You are running on a POSIX system. Prefer UTF-8 and standard shell tools.+- Prefer UTF-8 and standard shell tools.- Use file tools when they are simpler or more reliable than shell commands.{% endif %}diff --git a/tests/agent/test_context_prompt_cache.py b/tests/agent/test_context_prompt_cache.pyindex c582f03b4..95950bc7c 100644--- a/tests/agent/test_context_prompt_cache.py+++ b/tests/agent/test_context_prompt_cache.py@@ -270,7 +270,7 @@ def test_template_memory_md_is_skipped(tmp_path) -> None:builder = ContextBuilder(workspace)prompt = builder.build_system_prompt()- assert "## Long-term Memory" not in prompt+ assert "# Long-term Memory" not in promptassert "History log: memory/history.jsonl" in promptassert "This file is automatically updated by nanobot" not in prompt@@ -297,6 +297,6 @@ def test_customized_memory_md_is_injected(tmp_path, monkeypatch) -> None:monkeypatch.setattr(builder.memory, "read_memory", tracked_read_memory)prompt = builder.build_system_prompt()- assert "# Memory\n\n## Long-term Memory" in prompt+ assert prompt.count("# Long-term Memory") == 1assert "User prefers dark mode" in promptassert calls == 1diff --git a/tests/agent/test_skills_loader.py b/tests/agent/test_skills_loader.pyindex 477ba9531..986be14f4 100644--- a/tests/agent/test_skills_loader.py+++ b/tests/agent/test_skills_loader.py@@ -530,7 +530,7 @@ def test_prompt_reads_skills_once_and_refreshes_on_next_build(monkeypatch.setattr("nanobot.agent.skills.shutil.which", which)first = build_prompt()assert "First instructions" in first- assert "unavailable: CLI: prompt-test-cli" in first+ assert "**beta**" not in firstassert discoveries == 1assert all(reads.count(path) == 1 for path in documents)assert len(parses) == len(documents)@@ -546,7 +546,7 @@ def test_prompt_reads_skills_once_and_refreshes_on_next_build(second = build_prompt()assert "Updated instructions" in second and "First instructions" not in secondassert "Updated description" in second- assert "unavailable: CLI: prompt-test-cli" not in second+ assert "**beta**" in secondassert "**gamma**" in secondassert discoveries == 2assert all(reads.count(path) == 1 for path in documents)