Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend): surface capabilities hidden by kind filters (#15499)

Bently46190655e231
diff --git a/autogpt_platform/backend/backend/copilot/capabilities/index.py b/autogpt_platform/backend/backend/copilot/capabilities/index.py
index 3ea6dc691d..aa83fb1cd5 100644
--- a/autogpt_platform/backend/backend/copilot/capabilities/index.py
+++ b/autogpt_platform/backend/backend/copilot/capabilities/index.py
@@ -36,6 +36,8 @@ _NAME_WEIGHT = 2 # repeat name tokens so the name outweighs the purpose text
DEFAULT_LIMIT = 8
DEFAULT_FALLBACK_LIMIT = 3
+# Entries of other kinds a ``kind`` filter hid that are listed beside it.
+OTHER_KINDS_LIMIT = 3
# Platform tools that help connect an account and never do a service's job,
# so a query naming a service does not pull them into its list.
CONNECTION_HELPER_TOOLS = frozenset({"connect_integration"})
@@ -59,6 +61,11 @@ class SearchResult(BaseModel):
hits: list[SearchHit]
fallback: list[SearchHit] = []
service: str | None = None
+ # Set only when ``kind`` filtered the search: entries of other kinds it
+ # hid that cover more of the query than ``hits`` do, or as much and are
+ # connected, and how many there were before the cap.
+ other_kinds: list[SearchHit] = []
+ hidden_by_kind: int = 0
@property
def ids(self) -> list[str]:
@@ -138,6 +145,41 @@ class CapabilityIndex:
limit: int = DEFAULT_LIMIT,
fallback_limit: int = DEFAULT_FALLBACK_LIMIT,
prefer_mcp: bool = False,
+ ) -> SearchResult:
+ """Rank entries for *query*, listing relevant alternatives hidden by
+ a ``kind`` filter under ``other_kinds``."""
+ result = self._search(
+ query,
+ context=context,
+ kind=kind,
+ connections=connections,
+ permissions=permissions,
+ limit=limit,
+ fallback_limit=fallback_limit,
+ prefer_mcp=prefer_mcp,
+ )
+ if kind is not None and result.query:
+ self._add_other_kinds(
+ result,
+ context=context,
+ kind=kind,
+ connections=connections,
+ permissions=permissions,
+ prefer_mcp=prefer_mcp,
+ )
+ return result
+
+ def _search(
+ self,
+ query: str,
+ *,
+ context: CapabilityContext,
+ kind: CapabilityKindName | None,
+ connections: ConnectionState | None,
+ permissions: "CopilotPermissions | None",
+ limit: int,
+ fallback_limit: int,
+ prefer_mcp: bool = False,
) -> SearchResult:
query = " ".join((query or "").split())
if not query:
@@ -216,6 +258,49 @@ class CapabilityIndex:
query=query, hits=hits[:limit], fallback=fallback, service=service
)
+ def _add_other_kinds(
+ self,
+ result: SearchResult,
+ *,
+ context: CapabilityContext,
+ kind: CapabilityKindName,
+ connections: ConnectionState | None,
+ permissions: "CopilotPermissions | None",
+ prefer_mcp: bool,
+ ) -> None:
+ """Fill ``result.other_kinds`` from the same search without *kind*.
+
+ Include better-covering entries, or equally covering connected
+ entries and platform tools. Preserve context, permissions and the
+ service-query restriction. Exact-name lookups need no alternatives.
+ Search all entries before counting so filtered-kind hits cannot
+ displace alternatives; cap only the displayed ``other_kinds``.
+ """
+ if any(hit.reason != "search" for hit in result.hits):
+ return
+ best = max((hit.coverage for hit in result.hits), default=0.0)
+ unfiltered = self._search(
+ result.query,
+ context=context,
+ kind=None,
+ connections=connections,
+ permissions=permissions,
+ limit=len(self.entries),
+ fallback_limit=0,
+ prefer_mcp=prefer_mcp,
+ )
+ hidden = sorted(
+ (
+ hit
+ for hit in unfiltered.hits
+ if hit.entry.kind != kind
+ and (hit.coverage > best or (hit.coverage >= best and _ready(hit)))
+ ),
+ key=lambda hit: (-hit.coverage, not hit.connected),
+ )
+ result.other_kinds = hidden[:OTHER_KINDS_LIMIT]
+ result.hidden_by_kind = len(hidden)
+
# ------------------------------------------------------------------
def _allowed_indices(
@@ -406,6 +491,11 @@ class CapabilityIndex:
return " ".join(named), indices, named
+def _ready(hit: SearchHit) -> bool:
+ """Whether *hit* runs without the user connecting anything first."""
+ return bool(hit.connected) or hit.entry.kind == "tool"
+
+
def _coverage(groups: list[list[str]], doc: frozenset[str]) -> float:
covered = 0.0
for token, *synonyms in groups:
diff --git a/autogpt_platform/backend/backend/copilot/capabilities/kind_filter_test.py b/autogpt_platform/backend/backend/copilot/capabilities/kind_filter_test.py
new file mode 100644
index 0000000000..666f78729b
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/capabilities/kind_filter_test.py
@@ -0,0 +1,183 @@
+"""A ``kind`` filter lists what it hid (SECRT-2820).
+
+Integrations such as Gmail are blocks, so ``kind="tool"`` dropped every one of
+them before scoring and the model went looking for an MCP server off the
+catalog. A filtered search now also runs without the filter and returns the
+better or connected entries of other kinds it hid as ``other_kinds``.
+"""
+
+import pytest
+
+from backend.copilot.permissions import CopilotPermissions
+
+from .index import OTHER_KINDS_LIMIT, CapabilityIndex
+from .models import CapabilityEntry, Connection, Implementation
+from .ranking import ConnectionState
+
+GOOGLE = ConnectionState(providers=frozenset({"google"}))
+
+
+def _block(block_id: str, name: str, purpose: str, provider: str, tags=()):
+ return CapabilityEntry(
+ id=f"block:{block_id}",
+ kind="block",
+ name=name,
+ purpose=purpose,
+ tags=[provider, *tags],
+ context="both",
+ implementations=[Implementation(kind="block", ref=block_id)],
+ connection=Connection(required=True, key_type="provider", key=provider),
+ )
+
+
+def _tool(name: str, purpose: str):
+ return CapabilityEntry(
+ id=f"tool:{name}",
+ kind="tool",
+ name=name,
+ purpose=purpose,
+ tags=sorted(set(name.split("_"))),
+ context="direct",
+ implementations=[Implementation(kind="tool", ref=name, context="direct")],
+ )
+
+
+GMAIL_BLOCKS = [
+ _block(
+ f"aaaaaaaa-aaaa-aaaa-aaaa-00000000000{n}",
+ name,
+ purpose,
+ "google",
+ tags=("email",),
+ )
+ for n, (name, purpose) in enumerate(
+ [
+ ("GmailReadBlock", "Read recent emails from a Gmail inbox."),
+ ("GmailListLabelsBlock", "List the labels of a Gmail account."),
+ ("GmailSendBlock", "Send an email from a Gmail account."),
+ ("GmailReplyBlock", "Reply to an email in a Gmail thread."),
+ ]
+ )
+]
+TOOLS = [
+ _tool("web_search", "Search the web for live info (news, recent docs)."),
+ _tool("web_fetch", "Fetch a url and return its page text."),
+ _tool("create_feature_request", "File a feature request; we follow up by email."),
+ # Unrelated tools, so a word the Gmail family shares is still rare enough
+ # for BM25 to weight it: in an index this small, a term in half of the
+ # entries scores zero.
+ *(_tool(f"filler_{n}", "Unrelated platform helper.") for n in range(6)),
+]
+DISCORD_BLOCK = _block(
+ "bbbbbbbb-bbbb-bbbb-bbbb-000000000001",
+ "SendDiscordMessageBlock",
+ "Send a message to a Discord channel.",
+ "discord",
+)
+
+
+def index() -> CapabilityIndex:
+ return CapabilityIndex([*GMAIL_BLOCKS, *TOOLS, DISCORD_BLOCK])
+
+
+def test_a_kind_filter_lists_the_connected_blocks_it_hid(index):
+ """Dev trace 2901dcfb: kind="tool" with Google connected listed only
+ unrelated tools, and the model web-searched for a Gmail MCP server."""
+ result = index.search("Gmail read recent emails", kind="tool", connections=GOOGLE)
+
+ assert all(hit.entry.kind == "tool" for hit in result.hits)
+ assert result.other_kinds[0].entry.name == "GmailReadBlock"
+ assert all(hit.connected for hit in result.other_kinds)
+ assert result.hidden_by_kind >= len(result.other_kinds) > 0
+
+
+def test_a_kind_filter_that_empties_the_list_still_lists_other_kinds(index):
+ result = index.search("discord", kind="mcp_server", connections=ConnectionState())
+
+ assert result.hits == []
+ assert [hit.entry.name for hit in result.other_kinds] == ["SendDiscordMessageBlock"]
+
+
+def test_other_kinds_are_capped_and_the_count_is_not(index):
+ result = index.search("gmail", kind="tool", connections=GOOGLE)
+
+ assert len(result.other_kinds) == OTHER_KINDS_LIMIT
+ assert result.hidden_by_kind == len(GMAIL_BLOCKS)
+
+
+def test_the_hidden_count_is_independent_of_the_main_result_limit(index):
+ result = index.search("gmail", kind="tool", connections=GOOGLE, limit=1)
+
+ assert len(result.other_kinds) == OTHER_KINDS_LIMIT
+ assert result.hidden_by_kind == len(GMAIL_BLOCKS)
+
+
+def test_hidden_connected_blocks_still_respect_permissions(index):
+ result = index.search(
+ "gmail",
+ kind="tool",
+ connections=GOOGLE,
+ permissions=CopilotPermissions(blocks=[b.name for b in GMAIL_BLOCKS]),
+ )
+
+ assert result.other_kinds == [] and result.hidden_by_kind == 0
+
+
+def test_a_by_name_kind_lookup_gets_no_other_kinds(index):
+ result = index.search("web_search", kind="tool", connections=GOOGLE)
+
+ assert result.hits[0].entry.name == "web_search"
+ assert result.other_kinds == [] and result.hidden_by_kind == 0
+
+
+def test_no_kind_means_no_other_kinds(index):
+ result = index.search("gmail", connections=GOOGLE)
+
+ assert result.other_kinds == [] and result.hidden_by_kind == 0
+
+
+def test_an_unconnected_weaker_match_is_not_listed(index):
+ """create_feature_request covers the whole query; GmailSendBlock only
+ "send" and "email", and nothing is connected."""
+ result = index.search(
+ "send email feature request", kind="tool", connections=ConnectionState()
+ )
+
+ assert result.hits[0].entry.name == "create_feature_request"
+ assert result.other_kinds == [] and result.hidden_by_kind == 0
+
+
+def test_a_connected_weaker_match_is_not_listed(index):
+ """Review on #15011: "fetch a url" is fully answered by web_fetch, yet a
+ connected Gmail block sharing one word was listed as hidden, and the
+ message sent the model off to search again."""
+ connected = _block(
+ "cccccccc-cccc-cccc-cccc-000000000001",
+ "GmailFetchBlock",
+ "Fetch emails from Gmail.",
+ "google",
+ )
+ result = index.with_entries([connected]).search(
+ "fetch a url", kind="tool", connections=GOOGLE
+ )
+
+ assert result.hits[0].entry.name == "web_fetch"
+ assert result.other_kinds == [] and result.hidden_by_kind == 0
+
+
+def test_a_block_filter_does_not_hide_a_platform_tool_it_ties(index):
+ """kind="block" must never leave the model with only blocks when a
+ first-party tool, which needs no connection, does the job as well."""
+ fetch_block = _block(
+ "dddddddd-dddd-dddd-dddd-000000000001",
+ "PageReaderBlock",
+ "Fetch a url and return its page text.",
+ "acme",
+ )
+ result = index.with_entries([fetch_block]).search(
+ "fetch a url", kind="block", connections=ConnectionState()
+ )
+
+ assert result.hits[0].entry.name == "PageReaderBlock"
+ assert [hit.entry.name for hit in result.other_kinds] == ["web_fetch"]
diff --git a/autogpt_platform/backend/backend/copilot/prompting.py b/autogpt_platform/backend/backend/copilot/prompting.py
index 14ad5ba176..a602599ded 100644
--- a/autogpt_platform/backend/backend/copilot/prompting.py
+++ b/autogpt_platform/backend/backend/copilot/prompting.py
@@ -220,8 +220,8 @@ user): it posts as the AutoGPT bot with no credential into a linked server's
channels or the user's own DMs. For anywhere else, or with nothing linked, use
the user's connected block, or tell them they can link the platform.
-If `find_capability` returns nothing for a named service, `web_search` for
-"<service> MCP server" and call `run_capability` with the server URL as `id`.
+If `find_capability` without `kind` returns nothing for a named service,
+`web_search` for "<service> MCP server" and call `run_capability` with the server URL as `id`.
Verify the hostname belongs to the vendor first; if several candidates exist,
ask the user which to use — never auto-pick a URL the user is about to sign
in to. Writes to servers outside the catalog pause for review.
diff --git a/autogpt_platform/backend/backend/copilot/tools/capability_tools_test.py b/autogpt_platform/backend/backend/copilot/tools/capability_tools_test.py
index ad05fc8de1..d1206a5040 100644
--- a/autogpt_platform/backend/backend/copilot/tools/capability_tools_test.py
+++ b/autogpt_platform/backend/backend/copilot/tools/capability_tools_test.py
@@ -11,15 +11,17 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from prisma.enums import ReviewStatus
+from backend.copilot.capabilities.index import CapabilityIndex
from backend.copilot.capabilities.mcp_review import COPILOT_MCP_NODE_PREFIX
from backend.copilot.capabilities.ranking import ConnectionState
-from backend.copilot.capabilities.registry import get_registry
+from backend.copilot.capabilities.registry import build_entries, get_registry
from backend.copilot.capabilities.sources import EAGER_CORE
from backend.copilot.context import set_execution_context
from backend.copilot.permissions import CopilotPermissions
from backend.copilot.prompting import SHARED_TOOL_NOTES
from backend.copilot.tools import (
DEFERRED_TOOL_NAMES,
+ TOOL_GROUPS,
TOOL_REGISTRY,
get_available_tools,
)
@@ -351,6 +353,85 @@ async def test_find_capability_no_results_points_to_open_world():
assert any("MCP server" in s for s in result.suggestions)
+# SECRT-2820: Gmail is a family of Google blocks, which a machine without
+# Google OAuth secrets disables; score against the whole catalogue.
+GOOGLE_STATE = ConnectionState(providers=frozenset({"google"}))
+SLACK_STATE = ConnectionState(providers=frozenset({"slack"}))
+
+
[email protected](scope="module")
+def full_index() -> CapabilityIndex:
+ return CapabilityIndex(
+ build_entries(TOOL_REGISTRY, TOOL_GROUPS, include_disabled_blocks=True)
+ )
+
+
+async def _find(index: CapabilityIndex, state: ConnectionState, **kwargs):
+ with (
+ patch(
+ "backend.copilot.tools.find_capability.load_connection_state",
+ AsyncMock(return_value=state),
+ ),
+ patch(
+ "backend.copilot.tools.find_capability.session_registry",
+ AsyncMock(return_value=index),
+ ),
+ ):
+ return await FindCapabilityTool()._execute(USER, make_session(USER), **kwargs)
+
+
+async def test_find_capability_kind_tool_surfaces_the_connected_gmail_blocks(
+ full_index,
+):
+ """Dev trace 2901dcfb: kind="tool" with Google connected listed eight
+ unrelated tools, and the model web-searched for a Gmail MCP server."""
+ result = await _find(
+ full_index, GOOGLE_STATE, query="Gmail list recent emails", kind="tool"
+ )
+ assert isinstance(result, CapabilityListResponse)
+ assert all(c["kind"] == "tool" for c in result.capabilities)
+ gmail = [c for c in result.other_kinds if c["name"].startswith("Gmail")]
+ assert gmail and all(c["connected"] is True for c in gmail)
+ assert len(result.other_kinds) <= 3
+ assert "kind='tool' hid" in result.message
+ assert "search again without kind" in result.message
+ assert "MCP server" not in result.message
+
+
+async def test_find_capability_by_name_kind_lookup_gets_no_hint(full_index):
+ result = await _find(full_index, GOOGLE_STATE, query="web_fetch", kind="tool")
+ assert isinstance(result, CapabilityListResponse)
+ assert result.capabilities[0]["name"] == "web_fetch"
+ assert result.other_kinds == []
+ assert "without kind" not in result.message
+
+
+async def test_find_capability_kind_emptied_list_never_suggests_an_mcp_server(
+ full_index,
+):
+ """Prod Sep 30: kind="mcp_server" for "slack" came back empty and the
+ no-results reply sent the model to an off-catalog MCP server."""
+ result = await _find(full_index, SLACK_STATE, query="slack", kind="mcp_server")
+ assert isinstance(result, CapabilityListResponse)
+ assert result.capabilities == [] and result.count == 0
+ slack = [c for c in result.other_kinds if "Slack" in c["name"]]
+ assert slack and all(c["connected"] is True for c in slack)
+ assert "search again without kind" in result.message
+ assert "Call describe_capability" not in result.message
+ assert "MCP server" not in result.message
+
+ nothing = await _find(full_index, SLACK_STATE, query="zzqx", kind="mcp_server")
+ assert isinstance(nothing, NoResultsResponse)
+ assert not any("MCP server" in s for s in nothing.suggestions)
+ assert any("without kind" in s for s in nothing.suggestions)
+
+
+def test_find_capability_kind_description_says_usually_omit():
+ description = FindCapabilityTool().parameters["properties"]["kind"]["description"]
+ assert description.startswith("Usually omit")
+ assert "'tool' hides blocks" in description
+
+
async def test_find_capability_returns_the_session_owner_s_skill(skills):
skills.return_value = [TRIAGE]
session = make_session(USER, expert_id="expert-1")
diff --git a/autogpt_platform/backend/backend/copilot/tools/find_capability.py b/autogpt_platform/backend/backend/copilot/tools/find_capability.py
index ec2d61c924..3f735a280c 100644
--- a/autogpt_platform/backend/backend/copilot/tools/find_capability.py
+++ b/autogpt_platform/backend/backend/copilot/tools/find_capability.py
@@ -85,7 +85,7 @@ class FindCapabilityTool(BaseTool):
"kind": {
"type": "string",
"enum": list(KINDS),
- "description": "Restrict to one kind of capability.",
+ "description": "Usually omit; 'tool' hides blocks.",
},
},
"required": ["query"],
@@ -134,44 +134,70 @@ class FindCapabilityTool(BaseTool):
permissions=get_current_permissions(),
prefer_mcp=session.expert_id is not None and context != "graph",
)
- if not result.hits and not result.fallback:
+ if not result.hits and not result.fallback and not result.other_kinds:
return NoResultsResponse(
message=f"No capability found for '{query}'",
- suggestions=[
- "Try the service name alone, or a broader action ('email', 'sheet', 'http')",
- "For a service with no result, web_search '<service> MCP server' and "
- "call run_capability with the server URL as the id",
- ],
+ suggestions=_no_result_suggestions(kind),
session_id=session_id,
)
linked = (
await chat_platform_links(user_id)
- if POST_TOOL in result.names
+ if any(
+ hit.entry.name == POST_TOOL
+ for hit in result.hits + result.fallback + result.other_kinds
+ )
else ChatPlatformLinks()
)
capabilities = [_listing(hit, connections, linked) for hit in result.hits]
fallback = [_listing(hit, connections, linked) for hit in result.fallback]
- return CapabilityListResponse(
- message=_message(
- result.service,
- len(result.hits),
- len(result.fallback),
- skills=any(hit.entry.kind == "skill" for hit in result.hits),
- experts=any(hit.entry.kind == "expert" for hit in result.hits),
- needs_grant=any(
- c.get("connected") == NEEDS_EXPERT_GRANT
- for c in capabilities + fallback
- ),
+ other_kinds = [_listing(hit, connections, linked) for hit in result.other_kinds]
+ message = _message(
+ result.service,
+ len(result.hits),
+ len(result.fallback),
+ skills=any(hit.entry.kind == "skill" for hit in result.hits),
+ experts=any(hit.entry.kind == "expert" for hit in result.hits),
+ needs_grant=any(
+ c.get("connected") == NEEDS_EXPERT_GRANT
+ for c in capabilities + fallback + other_kinds
),
+ )
+ if result.other_kinds:
+ message += (
+ f" kind='{kind}' hid {result.hidden_by_kind} match(es) of other "
+ "kinds that cover this as well or better, listed under "
+ "other_kinds; search again without kind before concluding "
+ "nothing covers this."
+ )
+ return CapabilityListResponse(
+ message=message,
query=query,
capabilities=capabilities,
count=len(result.hits),
fallback=fallback,
+ other_kinds=other_kinds,
service=result.service,
session_id=session_id,
)
+def _no_result_suggestions(kind: str | None) -> list[str]:
+ """What to try next. An off-catalog MCP server is the last resort, so it
+ is never suggested while a ``kind`` filter may be what emptied the list:
+ integrations such as Gmail and Slack are blocks, and kind='tool' or
+ 'mcp_server' hides them (SECRT-2820)."""
+ if kind is not None:
+ return [
+ f"Search again without kind: kind='{kind}' hides every other kind "
+ "of capability, including the user's connected blocks",
+ ]
+ return [
+ "Try the service name alone, or a broader action ('email', 'sheet', 'http')",
+ "For a service with no result, web_search '<service> MCP server' and "
+ "call run_capability with the server URL as the id",
+ ]
+
+
def _listing(
hit: SearchHit, connections: ConnectionState, linked: ChatPlatformLinks
) -> dict[str, Any]:
@@ -207,11 +233,12 @@ def _message(
text = " ".join(parts) + "."
if fallback:
text += f" {fallback} generic fallback(s) listed separately."
- text += (
- " Call describe_capability(id) before first use, then "
- "run_capability(id, input). connected=false means the user must sign in "
- "first: run_capability returns the sign-in card."
- )
+ if hits or fallback:
+ text += (
+ " Call describe_capability(id) before first use, then "
+ "run_capability(id, input). connected=false means the user must sign in "
+ "first: run_capability returns the sign-in card."
+ )
if needs_grant:
text += (
f" connected='{NEEDS_EXPERT_GRANT}' means the account already has "
diff --git a/autogpt_platform/backend/backend/copilot/tools/find_capability_kind_test.py b/autogpt_platform/backend/backend/copilot/tools/find_capability_kind_test.py
new file mode 100644
index 0000000000..b27d1acfaf
--- /dev/null
+++ b/autogpt_platform/backend/backend/copilot/tools/find_capability_kind_test.py
@@ -0,0 +1,85 @@
+from unittest.mock import AsyncMock
+
+import pytest
+
+from backend.copilot.capabilities.index import CapabilityIndex
+from backend.copilot.capabilities.ranking import ConnectionState
+from backend.copilot.capabilities.registry import build_entries
+from backend.copilot.permissions import CopilotPermissions
+from backend.copilot.tools import TOOL_GROUPS, TOOL_REGISTRY, chat_platform
+
+from ._test_data import make_session
+from .chat_platform_hint import POST_TOOL, ChatPlatformLinks
+from .find_capability import FindCapabilityTool
+from .models import CapabilityListResponse
+
+USER = "kind-filter-user"
+
+
[email protected](scope="module")
+def index() -> CapabilityIndex:
+ with pytest.MonkeyPatch.context() as mp:
+ mp.setattr(chat_platform, "_any_chat_platform_configured", lambda: True)
+ return CapabilityIndex(build_entries(TOOL_REGISTRY, TOOL_GROUPS))
+
+
+def links(index, monkeypatch):
+ target = "backend.copilot.tools.find_capability"
+ monkeypatch.setattr(f"{target}.session_registry", AsyncMock(return_value=index))
+ monkeypatch.setattr(
+ f"{target}.load_connection_state", AsyncMock(return_value=ConnectionState())
+ )
+ reader = AsyncMock(
+ return_value=ChatPlatformLinks(
+ servers=frozenset({"discord", "slack", "telegram"}),
+ dms=frozenset({"teams"}),
+ )
+ )
+ monkeypatch.setattr(f"{target}.chat_platform_links", reader)
+ return reader
+
+
[email protected]("expert_id", [None, "kind-filter-expert"])
+ "query",
+ ["send a discord message", "post a report to slack", "send a telegram message"],
+)
+async def test_hidden_chat_tool_keeps_the_users_platform_links(links, query, expert_id):
+ result = await FindCapabilityTool()._execute(
+ USER, make_session(USER, expert_id=expert_id), query=query, kind="block"
+ )
+
+ assert isinstance(result, CapabilityListResponse)
+ assert result.capabilities and all(
+ c["kind"] == "block" for c in result.capabilities
+ )
+ tool = next(c for c in result.other_kinds if c["id"] == f"tool:{POST_TOOL}")
+ assert tool["linked"] == ["discord", "slack", "telegram"]
+ assert tool["dm_linked"] == ["teams"]
+ assert "search again without kind" in result.message
+ links.assert_awaited_once_with(USER)
+
+
+ "context,permissions",
+ [("graph", None), ("direct", CopilotPermissions(tools=[POST_TOOL]))],
+)
+async def test_hidden_chat_tool_still_respects_context_and_permissions(
+ links, monkeypatch, context, permissions
+):
+ monkeypatch.setattr(
+ "backend.copilot.tools.find_capability.get_current_permissions",
+ lambda: permissions,
+ )
+ result = await FindCapabilityTool()._execute(
+ USER,
+ make_session(USER),
+ query="send a discord message",
+ kind="block",
+ context=context,
+ )
+
+ assert isinstance(result, CapabilityListResponse)
+ assert all(c["id"] != f"tool:{POST_TOOL}" for c in result.other_kinds)
+ links.assert_not_awaited()
diff --git a/autogpt_platform/backend/backend/copilot/tools/models.py b/autogpt_platform/backend/backend/copilot/tools/models.py
index e4eddf433c..545e5940f9 100644
--- a/autogpt_platform/backend/backend/copilot/tools/models.py
+++ b/autogpt_platform/backend/backend/copilot/tools/models.py
@@ -995,6 +995,8 @@ class CapabilityListResponse(ToolResponseBase):
count: int
# Generic primitives offered when the query named a service.
fallback: list[dict[str, Any]] = Field(default_factory=list)
+ # Connected or better-covering entries a ``kind`` filter hid.
+ other_kinds: list[dict[str, Any]] = Field(default_factory=list)
service: str | None = None