Files
hermes-agent/tools/connectors/__init__.py
Siddharth Balyan 086984caf5 refactor(data-use): carry the requirement on the dispatch result, not a global store
The process-global _PENDING dict keyed by (turn_id, tool_call_id), its lock
and its 512 cap existed only to move a value from connector dispatch to
_commit_tool_result. _dispatch_authorized_once already owns the one real
dispatch and returns _ManagedToolResult to both executors, so it now binds a
per-call ContextVar sink around the dispatch and stores what connector
dispatch recorded on that result (and on _ToolOutcome for the concurrent
path). A batch's entries add to the wrapper's sink, so the union needs no
take/re-record. Callers that bind no sink (execute_code RPC, MCP serve)
record nothing, which removes the unbounded-growth case the cap guarded.
2026-10-21 15:46:19 +05:30

44 lines
1.9 KiB
Python

"""Connector integration boundary for managed gateway accounts and local MCP servers.
Only the names below are cross-package surface; imports beyond it need a design decision.
Siblings: ``contract`` (states, actors, transition table), ``operation`` (the record),
``live`` (open operation per session), ``run`` (the lifecycle loop), ``managed`` / ``mcp``
(per-kind hooks), ``targets``, ``search``, ``dispatch``, ``gateway/`` (HTTP wire + client).
The surface is exported lazily (PEP 562): eager submodule imports here deadlocked the
concurrent registry scan and the Group Chat worker (see test_connectors_import_deadlock.py).
"""
import importlib
# name -> module owning it: the single source of truth for __all__ and __getattr__.
_LAZY_EXPORTS: dict[str, str] = {
"CONNECTOR_BATCH_SENTINEL": "tools.connectors.gateway.names",
"MANAGE_CONNECTIONS_SCHEMA": "tools.connectors.tool",
"connector_describe": "tools.connectors.gateway.bridge",
"connector_search_hits": "tools.connectors.gateway.bridge",
"connectors_available": "tools.connectors.gateway.config",
"dispatch_connector_batch": "tools.connectors.dispatch",
"dispatch_connector_call": "tools.connectors.dispatch",
"ensure_guest_identity": "tools.connectors.gateway.config",
"guest_identity_pending": "tools.connectors.gateway.config",
"is_connector_name": "tools.connectors.gateway.names",
"manage_connections": "tools.connectors.tool",
}
__all__ = sorted(_LAZY_EXPORTS)
def __getattr__(name: str):
"""Resolve and cache a public name on first access (PEP 562)."""
module_name = _LAZY_EXPORTS.get(name)
if module_name is None:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
value = getattr(importlib.import_module(module_name), name)
globals()[name] = value
return value
def __dir__() -> list[str]:
return sorted(set(globals()) | set(__all__))