Agentflow icon indicating copy to clipboard operation
Agentflow copied to clipboard

ToolNode.all_tools_sync() silently drops remote tools (async path includes them)

Open Mothilal-M opened this issue 4 months ago • 1 comments

Summary

ToolNode.all_tools_sync() rebuilds the tool list from local + MCP tools only and never appends self.remote_tools. The async path does. Any code path that reaches the model through the sync variant therefore advertises zero remote tools, even though set_remote_tool() succeeded and remote_tool_names is populated.

The failure is silent: no exception, no warning, no log line. The agent simply behaves as though the remote tools do not exist.

The asymmetry

agentflow/core/graph/tool_node/base.py (v0.9.0)

# line 191 - async path: remote tools included
async def _all_tools_async(self, tags: set[str] | None = None) -> list[dict]:
    tools: list[dict] = self.get_local_tool(tags=tags)
    tools.extend(await self._get_mcp_tool(tags=tags))
    tools.extend(self.remote_tools)          # <-- here
    return tools

# line 247 - sync path: remote tools dropped
def all_tools_sync(self, tags: set[str] | None = None) -> list[dict]:
    tools: list[dict] = self.get_local_tool(tags=tags)
    if self._client:
        result = asyncio.run(self._get_mcp_tool(tags=tags))
        if result:
            tools.extend(result)
    return tools                              # <-- no remote_tools

The docstring describes all_tools_sync as "a synchronous wrapper around the async all_tools() method", which is what led us to assume parity.

Repro

node = ToolNode(tools=[], client=mcp_client)
node.set_remote_tool([
    {"type": "function",
     "function": {"name": "write_file",
                  "description": "Write a file.",
                  "parameters": {"type": "object", "properties": {}, "required": []}}}
])

print(node.remote_tool_names)                                  # ['write_file']
print([t["function"]["name"] for t in await node.all_tools()]) # [..., 'write_file']
print([t["function"]["name"] for t in node.all_tools_sync()])  # [...]  <- missing

Impact

Remote tools are the mechanism for client-side execution, so this makes the whole feature vanish depending on which accessor the surrounding code happens to call. Ours is a VS Code extension: the model was offered 10 MCP tools and none of the 11 workspace tools, so the assistant would chat happily but never read or edit a file — with nothing in any log to explain why. It reads as a prompt-quality problem, not a bug, which is what made it expensive to find.

Suggested fix

Mirror the async builder:

def all_tools_sync(self, tags: set[str] | None = None) -> list[dict]:
    tools: list[dict] = self.get_local_tool(tags=tags)
    if self._client:
        result = asyncio.run(self._get_mcp_tool(tags=tags))
        if result:
            tools.extend(result)
    tools.extend(self.remote_tools)
    return tools

A regression test asserting set(sync) == set(async) after set_remote_tool() would keep the two paths from drifting again.

Workaround

Overriding all_tools_sync in a ToolNode subclass and appending self.remote_tools restores the behaviour.

Related, possibly worth documenting separately

We reached static attachment (CompiledGraph.attach_remote_tools) because dynamic registration is unavailable to us:

agentflow_cli/src/app/routers/graph/services/graph_service.py (v0.5.0)

if settings.MODE == "production" or has_auth:
    raise HTTPException(403, "Dynamic tool setup is disabled in production/multi-tenant mode.")

has_auth is true whenever agentflow.json declares any auth method other than none, so POST /v1/graph/setup returns 403 for every authenticated agent, not only multi-tenant ones — and the TypeScript client's documented registerTool() + setup() flow cannot be used. That may well be intentional, but it isn't mentioned in the remote-tools documentation, and the 403 message points at "production/multi-tenant mode" rather than at the auth backend, which sent us looking at MODE first. A note in the docs, or widening the message to name the real trigger, would save the next person the detour.

Environment

  • 10xscale-agentflow 0.9.0
  • 10xscale-agentflow-cli 0.5.0
  • Python 3.13.14

Mothilal-M avatar Jul 27 '26 13:07 Mothilal-M

Thank you for this — it's about as good as a bug report gets. The asymmetry is real and the diagnosis is exactly right: all_tools_sync rebuilt the list without remote_tools while the async path included them, so which accessor the surrounding code happened to call decided whether the feature existed.

Fixed by mirroring the async builder, as you suggested, and I took the parity test too — set(sync) == set(async) after set_remote_tool(), so the two paths can't drift again. I also fixed the attach_remote_tools docstring, which showed a tool shape ({"name": ..., "type": ..., "config": ...}) that set_remote_tool can't read; it would have populated remote_tool_names with Nones. Same silent-failure family.

Your point about the 403 was well taken and not just a docs miss. The message now names the condition that actually fired, so an authenticated development agent sees "an auth backend is configured in agentflow.json" rather than being sent to audit MODE. The remote-tools concept page didn't mention the restriction at all, so it now states plainly that every authenticated agent is affected — not only multi-tenant ones — and shows the static attach_remote_tools() path as the supported alternative.

The detail about this reading as a prompt-quality problem rather than a bug is the part that stuck with me. A capability that vanishes with no log line is expensive precisely because it doesn't look like a bug, and that's what made the fix worth pairing with the message and doc changes rather than shipping alone.

Iamsdt avatar Jul 27 '26 17:07 Iamsdt