diff --git a/deeptutor/agents/loop/pipeline.py b/deeptutor/agents/loop/pipeline.py index 2b1291362..c36cb8191 100644 --- a/deeptutor/agents/loop/pipeline.py +++ b/deeptutor/agents/loop/pipeline.py @@ -487,9 +487,15 @@ class AgenticLoopPipeline: # Assemble once, then render: the context-budget breakdown is measured # from these very blocks, so a second ``blocks()`` call could drift from # the prompt actually sent. + # Native schemas already describe every mounted tool; a text manifest + # on top would only repeat them (and re-append on each tool change). + native = ( + include_tool_manifest and bool(enabled_tools) and self._can_use_native_tool_calling() + ) + self._prompt_assembler.native_tool_schemas = native self._last_prompt_blocks = self._prompt_assembler.blocks( context=context, - tool_manifest=self._tool_manifest(enabled_tools), + tool_manifest="" if native else self._tool_manifest(enabled_tools), kb_note=self._kb_system_note(context), deferred_tools_manifest=( self._deferred_tools_manifest() if include_tool_manifest else "" diff --git a/deeptutor/agents/loop/prompt_blocks.py b/deeptutor/agents/loop/prompt_blocks.py index 4077df8f0..72156b7c4 100644 --- a/deeptutor/agents/loop/prompt_blocks.py +++ b/deeptutor/agents/loop/prompt_blocks.py @@ -57,6 +57,10 @@ class LoopPromptAssembler: # directive can name. self.language = "zh" if language.lower().startswith("zh") else "en" self.output_language = (language or "en").strip().lower() or "en" + # Set by the pipeline when this request carries native tool schemas. + # The schemas already describe every mounted tool, so a text manifest + # would only repeat them (and re-append on every tool change). + self.native_tool_schemas = False def system_prompt( self, @@ -171,7 +175,7 @@ class LoopPromptAssembler: # conversation expects the tutor to already know what "上次" was. if context.learning_journal_context: blocks.append(PromptBlock("learning_journal", context.learning_journal_context)) - if include_tool_manifest: + if include_tool_manifest and not self.native_tool_schemas: tools = tool_manifest or self._fallback_empty_tool_list() if kb_note: tools = f"{kb_note}\n\n{tools}" diff --git a/deeptutor/capabilities/mastery/pipeline.py b/deeptutor/capabilities/mastery/pipeline.py index 4e1827ba6..6abd143a0 100644 --- a/deeptutor/capabilities/mastery/pipeline.py +++ b/deeptutor/capabilities/mastery/pipeline.py @@ -52,11 +52,6 @@ class MasteryPromptAssembler(LoopPromptAssembler): three conflicting rule sets at once. """ - def blocks(self, **kwargs): - if getattr(self, "native_tool_schemas", False): - kwargs["include_tool_manifest"] = False - return super().blocks(**kwargs) - def session_modes_block(self) -> str: return self._t("session_frame") @@ -348,9 +343,6 @@ class MasteryLoopPipeline(AgenticLoopPipeline): return briefing.replace(snapshot, "", 1).strip() if snapshot else briefing def _build_system_prompt(self, enabled_tools, context, *, include_tool_manifest=True): - self._prompt_assembler.native_tool_schemas = ( - bool(enabled_tools) and self._can_use_native_tool_calling() - ) prompt = super()._build_system_prompt( enabled_tools, context, diff --git a/deeptutor/tools/builtin/__init__.py b/deeptutor/tools/builtin/__init__.py index f649d1942..d0ba8a032 100644 --- a/deeptutor/tools/builtin/__init__.py +++ b/deeptutor/tools/builtin/__init__.py @@ -41,7 +41,11 @@ class BrainstormTool(_PromptHintsMixin, BaseTool): def get_definition(self) -> ToolDefinition: return ToolDefinition( name="brainstorm", - description="Broadly explore multiple possibilities for a topic and give a short rationale for each.", + description=( + "Broadly explore multiple possibilities for a topic and give a short " + "rationale for each. Use for alternative angles or early-stage options " + "before committing to a solution." + ), parameters=[ ToolParameter( name="topic", @@ -249,8 +253,10 @@ class RAGTool(_PromptHintsMixin, BaseTool): name="rag", description=( "Retrieve relevant passages from one of the knowledge bases the " - "user attached to this turn. Call once per knowledge base you " - "want to consult; the system runs them in parallel." + "user attached to this turn. Use when the answer is likely covered " + "by them (definitions, formulas, textbook explanations). Call once " + "per knowledge base you want to consult; the system runs them in " + "parallel." ), parameters=[ ToolParameter(name="query", type="string", description="Search query."), @@ -820,7 +826,11 @@ class WebSearchTool(_PromptHintsMixin, BaseTool): def get_definition(self) -> ToolDefinition: return ToolDefinition( name="web_search", - description="Search the web and return summarised results with citations.", + description=( + "Search the web and return summarised results with citations. Use " + "when the knowledge base is insufficient or the task needs recent " + "events, real-world examples, or external references." + ), parameters=[ ToolParameter(name="query", type="string", description="Search query."), ], @@ -887,7 +897,11 @@ class PaperSearchToolWrapper(_PromptHintsMixin, BaseTool): def get_definition(self) -> ToolDefinition: return ToolDefinition( name="paper_search", - description="Search arXiv preprints by keyword and return concise metadata.", + description=( + "Search arXiv preprints by keyword and return concise metadata. Use " + "for research papers, state-of-the-art methods, or scholarly " + "references; skip for standard textbook questions." + ), parameters=[ ToolParameter(name="query", type="string", description="Search query."), ToolParameter( @@ -978,8 +992,10 @@ class ZoteroSearchToolWrapper(_PromptHintsMixin, BaseTool): return ToolDefinition( name="zotero_search", description=( - "Search a Zotero user library by title, creator, or year. Requires the " - "numeric Zotero user ID; an API key is needed only for private libraries." + "Search a Zotero user library by title, creator, or year. Use when " + "the user asks for an item from their Zotero library; skip for public " + "web or arXiv searches. Requires the numeric Zotero user ID; an API " + "key is needed only for private libraries." ), parameters=[ ToolParameter(name="query", type="string", description="Search query."), @@ -1369,7 +1385,8 @@ class WriteMemoryTool(_PromptHintsMixin, BaseTool): description=( "Save an explicit user preference (writing style, language " "choice, depth, format) to long-term memory. Call ONLY when " - "the user clearly states a preference — never speculate." + "the user clearly states a preference — never speculate or " + "infer one from a single, possibly situational comment." ), parameters=[ ToolParameter( @@ -1937,7 +1954,9 @@ class GithubTool(_PromptHintsMixin, BaseTool): name="github", description=( "Read-only queries against GitHub PRs / issues / repos / " - "CI runs via the gh CLI. This tool cannot write — no " + "CI runs via the gh CLI, for a specific GitHub resource. Do " + "not use it for general code-concept questions — answer those " + "directly or with web_search. This tool cannot write — no " "comments, no closes, no merges." ), parameters=[ diff --git a/deeptutor/tools/exec_tool.py b/deeptutor/tools/exec_tool.py index 7604e0d2c..ab34b1b9c 100644 --- a/deeptutor/tools/exec_tool.py +++ b/deeptutor/tools/exec_tool.py @@ -58,7 +58,9 @@ class ExecTool(BaseTool): name="exec", description=( "Run complete source code or an explicit shell script inside " - "the turn's isolated workspace. Put source or shell text in " + "the turn's isolated workspace — for calculations, generated " + "files, data processing, existing scripts, and CLI/environment " + "checks. Put source or shell text in " "`code`; `language` defaults to python and also accepts c, cpp, " "or shell. Python/C/C++ source is written to a file before it is " "run, so never embed it in python -c or a heredoc. Generated " diff --git a/deeptutor/tools/media_gen_tool.py b/deeptutor/tools/media_gen_tool.py index 0154abe52..8c793e520 100644 --- a/deeptutor/tools/media_gen_tool.py +++ b/deeptutor/tools/media_gen_tool.py @@ -143,7 +143,10 @@ class ImagegenTool(BaseTool): name="imagegen", description=( "Generate one or more images from a text description using the " - "configured image-generation model. Write a vivid, self-contained " + "configured image-generation model, for illustrations, artwork, " + "concept images, posters, or photorealistic scenes (use exec for " + "programmatic charts, diagrams, or image post-processing). " + "Write a vivid, self-contained " "`prompt` describing the subject, style, and composition. Generated " "images are saved under the active workspace's outputs/. After " "generation, call workspace_present with each returned exact path " @@ -225,7 +228,8 @@ class VideogenTool(BaseTool): name="videogen", description=( "Generate a short video from a text description using the configured " - "video-generation model. Write a vivid, self-contained `prompt` " + "video-generation model (use exec for programmatic rendering or " + "post-processing). Write a vivid, self-contained `prompt` " "describing the scene, motion, and style. Rendering is slow (it may " "take a minute or more). The video is saved under the active " "workspace's outputs/. After generation, call workspace_present with " diff --git a/tests/agents/chat/test_context_budget.py b/tests/agents/chat/test_context_budget.py index 967adddba..6fadc7698 100644 --- a/tests/agents/chat/test_context_budget.py +++ b/tests/agents/chat/test_context_budget.py @@ -473,7 +473,10 @@ async def test_turn_result_carries_the_context_budget(monkeypatch: pytest.Monkey assert budget["free_tokens"] == 128000 - budget["used_tokens"] keys = {segment["key"] for segment in budget["segments"]} # The measured request is the one the client actually received. - assert {"system_prompt", "tool_manifest", "system_tools", "messages"} <= keys + assert {"system_prompt", "system_tools", "messages"} <= keys + # Native tool calling carries the tool descriptions in the schemas, so no + # text manifest duplicates them. + assert "tool_manifest" not in keys sent_system = client.calls[0]["messages"][0]["content"] assert "Explain gradient descent" not in sent_system diff --git a/tests/agents/chat/test_kb_manifest_note.py b/tests/agents/chat/test_kb_manifest_note.py index e577a816f..4cda8f257 100644 --- a/tests/agents/chat/test_kb_manifest_note.py +++ b/tests/agents/chat/test_kb_manifest_note.py @@ -73,7 +73,11 @@ async def test_manifest_reaches_runtime_context_without_changing_system( await pipeline._prepare_kb_manifests(context) messages = pipeline._build_loop_messages(context=context, enabled_tools=["rag", "kb_files"]) - prompt = next(m["content"] for m in messages if m.get("_context_snapshot") == "tools") + snapshots = {m.get("_context_snapshot"): m["content"] for m in messages} + # Native tool calling drops the tool manifest, but the KB inventory survives + # in its own snapshot. + assert "tools" not in snapshots + prompt = snapshots["knowledge_base_note"] assert "[Knowledge Base Inventory]" not in messages[0]["content"] assert "[Knowledge Base Inventory]" in prompt