DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(api): warn when a deferred tool's definition fails to load (#1731)
evan188199-tech70d65c002901
diff --git a/deeptutor/api/utils/tool_options.py b/deeptutor/api/utils/tool_options.pyindex cccac4709..f94c7fe80 100644--- a/deeptutor/api/utils/tool_options.py+++ b/deeptutor/api/utils/tool_options.py@@ -94,7 +94,18 @@ async def build_tool_options(for tool in registry.deferred_tools():try:definition = tool.get_definition()- except Exception:+ except Exception as exc:+ # The definition is the only place a deferred tool's name lives,+ # so identify the failure by provider and adapter class instead+ # of dropping it from the options without a trace.+ kind, provider_id = provider_identity(tool)+ logger.warning(+ "tool options skipped %s tool %r (provider %r): get_definition() failed: %s",+ kind or "unknown",+ type(tool).__name__,+ provider_id or "unknown",+ exc,+ )continuekind, provider_id = provider_identity(tool)if (kind or "mcp") != "mcp":diff --git a/tests/api/test_tool_options.py b/tests/api/test_tool_options.pyindex a8d954ae9..8317e2b29 100644--- a/tests/api/test_tool_options.py+++ b/tests/api/test_tool_options.py@@ -8,6 +8,7 @@ the legacy spelling that must keep working for clients built before them.from __future__ import annotations+import loggingfrom typing import Anyimport pytest@@ -162,6 +163,24 @@ async def test_unreadable_tool_is_skipped(stub_registry) -> None:assert isinstance(payload["builtin_tools"], list)+async def test_unreadable_tool_is_skipped_with_warning(stub_registry, caplog) -> None:+ """A skipped tool must be named in a warning, not vanish silently."""+ stub_registry([_BrokenTool("mcp_broken_thing"), _McpTool("mcp_notion_search", "notion")])++ with caplog.at_level(logging.WARNING, logger="deeptutor.api.utils.tool_options"):+ payload = await tool_options_mod.build_tool_options()++ # The warning names the provider the tool came from and the failure reason.+ warnings = [r.getMessage() for r in caplog.records if r.levelno == logging.WARNING]+ assert any(+ "broken" in message and "server went away mid-listing" in message for message in warnings+ ), warnings+ # Good tools keep flowing and the return structure is unchanged.+ assert [row["name"] for row in payload["mcp_tools"]] == ["mcp_notion_search"]+ assert set(payload) == {"tools", "builtin_tools", "mcp_tools"}++@pytest.mark.asyncioasync def test_optional_tool_filter_is_explicit_and_does_not_change_default(stub_registry) -> None:"""Partner policy must not leak into the shared admin grant catalog."""