refactor(agent): internalize tool contract prompt

This commit is contained in:
Xubin Ren
2026-05-21 15:21:39 +08:00
parent 581faa34f7
commit d29fcaf5d1
6 changed files with 53 additions and 12 deletions
+3 -2
View File
@@ -22,7 +22,7 @@ from nanobot.utils.prompt_templates import render_template
class ContextBuilder:
"""Builds the context (system prompt + messages) for the agent."""
BOOTSTRAP_FILES = ["AGENTS.md", "SOUL.md", "USER.md", "TOOLS.md"]
BOOTSTRAP_FILES = ["AGENTS.md", "SOUL.md", "USER.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
@@ -47,6 +47,8 @@ class ContextBuilder:
if bootstrap:
parts.append(bootstrap)
parts.append(render_template("agent/tool_contract.md"))
memory = self.memory.get_memory_context()
if memory and not self._is_template_content(self.memory.read_memory(), "memory/MEMORY.md"):
parts.append(f"# Memory\n\n{memory}")
@@ -210,4 +212,3 @@ class ContextBuilder:
if not images:
return text
return images + [{"type": "text", "text": text}]