Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(harness): 代调已注册的召回工具时提示直接调用

xukang3d65bfc216dd
diff --git a/jiuwenswarm/agents/harness/common/rails/progressive_tool_rail.py b/jiuwenswarm/agents/harness/common/rails/progressive_tool_rail.py
index 73d8a4737f..c6219d11a8 100644
--- a/jiuwenswarm/agents/harness/common/rails/progressive_tool_rail.py
+++ b/jiuwenswarm/agents/harness/common/rails/progressive_tool_rail.py
@@ -82,6 +82,11 @@ _OFFICE_CLAW_SCHEDULE_THREAD_PIN_TOOLS = frozenset(
)
+def _is_pinned_schema_tool(tool_name: str, registered_card: Any) -> bool:
+ """True when the recall tool is registered and therefore directly callable."""
+ return tool_name == _PINNED_SCHEMA_TOOL_NAME and registered_card is not None
+
+
def _json_safe_value(value: Any) -> Any:
"""Convert tool invoke results (e.g. ToolOutput) to JSON-serializable values."""
if value is None or isinstance(value, (str, int, float, bool)):
@@ -1600,7 +1605,9 @@ class ProgressiveToolRail(DeepAgentRail):
"tool_name": tool_name,
}
- if tool_name in self.eager_tools:
+ if tool_name in self.eager_tools or _is_pinned_schema_tool(
+ tool_name, registered_card
+ ):
return {
"success": False,
"error": f"工具 '{tool_name}' 是常驻可见工具,可直接调用,无需通过 invoke_tool。",
diff --git a/tests/unit_tests/agentserver/test_progressive_recall_tool_visibility.py b/tests/unit_tests/agentserver/test_progressive_recall_tool_visibility.py
index 3768b8af03..d7eedc4be6 100644
--- a/tests/unit_tests/agentserver/test_progressive_recall_tool_visibility.py
+++ b/tests/unit_tests/agentserver/test_progressive_recall_tool_visibility.py
@@ -12,6 +12,9 @@ from openjiuwen.harness.prompts.sections import SectionName
from jiuwenswarm.agents.harness.common.rails.progressive_tool_rail import (
ProgressiveToolRail,
)
+from jiuwenswarm.agents.harness.common.tools.invoke_tool_tool import (
+ InvokeToolInput,
+)
_RECALL = "recall_compressed_context"
_MISSING = object()
@@ -223,3 +226,41 @@ async def test_lazy_load_off_keeps_input_order_for_non_disabled_tools() -> None:
await rail.before_model_call(ctx)
assert _names(ctx.inputs.tools) == [_RECALL, "ordinary_deferred", "read_file"]
+
+
+async def test_invoke_tool_tells_model_to_call_registered_recall_directly() -> None:
+ """A schema-visible recall tool is not deferred, so invoke_tool must not say it is missing."""
+ recall = _card(_RECALL)
+ deferred = _card("ordinary_deferred")
+ rail = ProgressiveToolRail(eager_tools=["read_file"])
+ rail._cached_all_tool_infos = [recall, deferred]
+ rail._cached_deferred_tool_infos = [deferred]
+
+ registered = await rail._invoke_target_tool(
+ None,
+ InvokeToolInput(tool_name=_RECALL, arguments={}),
+ )
+ assert registered["success"] is False
+ assert "可直接调用" in registered["error"]
+
+ rail._cached_all_tool_infos = []
+ missing = await rail._invoke_target_tool(
+ None,
+ InvokeToolInput(tool_name=_RECALL, arguments={}),
+ )
+ assert "未注册" in missing["error"]
+
+ rail._cached_all_tool_infos = [recall]
+ rail._disabled_tools = {_RECALL}
+ disabled = await rail._invoke_target_tool(
+ None,
+ InvokeToolInput(tool_name=_RECALL, arguments={}),
+ )
+ assert "禁用" in disabled["error"]
+
+ ordinary = await rail._invoke_target_tool(
+ None,
+ InvokeToolInput(tool_name="ordinary_deferred", arguments={}),
+ )
+ assert "可直接调用" not in ordinary["error"]