fix(agent): trim redundant system prompt context

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-16 00:01:24 +08:00
1 parent 841d2b880c
commit 32f5cc76a4
6 files changed
+11 -19

No files matched your search

+1 -1
View File
@@ -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()
+3 -9
View File
@@ -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 full
skill 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)
+1 -1
View File
@@ -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 Hint
This conversation is on a messaging app. Use short paragraphs. Avoid large headings (#, ##). Use **bold** sparingly. No tables — use plain lists.
+2 -4
View File
@@ -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 %}
+2 -2
View File
@@ -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 prompt
assert "History log: memory/history.jsonl" in prompt
assert "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") == 1
assert "User prefers dark mode" in prompt
assert calls == 1
+2 -2
View File
@@ -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 first
assert discoveries == 1
assert 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 second
assert "Updated description" in second
assert "unavailable: CLI: prompt-test-cli" not in second
assert "**beta**" in second
assert "**gamma**" in second
assert discoveries == 2
assert all(reads.count(path) == 1 for path in documents)