Skip to content

The agent that grows with you

feat(connectors): wire models for single-call execute and error families

Siddharth Balyan41cd1c5f99d4
diff --git a/tools/connectors/gateway/wire.py b/tools/connectors/gateway/wire.py
index e4729d84611..b5cd0032a71 100644
--- a/tools/connectors/gateway/wire.py
+++ b/tools/connectors/gateway/wire.py
@@ -29,13 +29,35 @@ ConnectorInitiator = Literal["agent_tool", "desktop_page", "card_retry"]
# Hermes dispatch caps batches lower, so client-side chunking is deliberately absent.
WIRE_BATCH_MAX = 25
-# A 200 execute envelope carries per-tool failures as results, not HTTP errors.
-ConnectorErrorCode = Literal[
- "TOOL_NOT_ALLOWED",
- "CONNECTION_REQUIRED",
- "TOOL_NOT_FOUND",
- "PROVIDER_ERROR",
-]
+# Any string: a gateway newer than this client may add codes, and an unknown code still renders.
+ConnectorErrorCode = str
+# `product`: the request or the user's setup is the cause. `backend`: the gateway or the vendor failed.
+ErrorFamily = Literal["product", "backend"]
+
+# Single-call execute failures: code -> (family, HTTP status). The legacy array envelope carries only
+# TOOL_NOT_ALLOWED, CONNECTION_REQUIRED, TOOL_NOT_FOUND and PROVIDER_ERROR, always under a 200.
+EXECUTE_ERROR_CODES: dict[str, tuple[ErrorFamily, int]] = {
+ "TOOL_NOT_ALLOWED": ("product", 403),
+ "CONNECTION_REQUIRED": ("product", 409),
+ "CONNECTION_EXPIRED": ("product", 409),
+ "ALIAS_REQUIRED": ("product", 422),
+ "ALIAS_UNKNOWN": ("product", 422),
+ "INVALID_ARGUMENTS": ("product", 422),
+ "TOOL_NOT_FOUND": ("product", 404),
+ "PROVIDER_ERROR": ("backend", 502),
+ "PROVIDER_RATE_LIMITED": ("backend", 429),
+ "PROVIDER_TIMEOUT": ("backend", 504),
+ "POLICY_UNAVAILABLE": ("backend", 503),
+ "GATEWAY_ERROR": ("backend", 500),
+}
+
+
+def execute_error_family(code: str, family: Optional[str] = None) -> Optional[str]:
+ """The gateway's family when it sent one, else the table's; ``None`` for an unknown code."""
+ if family in ("product", "backend"):
+ return family
+ known = EXECUTE_ERROR_CODES.get(code)
+ return known[0] if known else None
class _Wire(BaseModel):
@@ -103,6 +125,13 @@ class ConnectorToolError(_Wire):
# The account the link was minted for; absent when the link mint failed. Absent means nothing to watch.
connection_id: Optional[str] = Field(default=None, alias="connectionId")
hint: Optional[str] = None
+ family: Optional[str] = None
+
+
+class ConnectorExecuteFailure(ConnectorToolError):
+ """The body of a non-2xx single-call execute answer."""
+
+ request_id: Optional[str] = Field(default=None, alias="requestId")
class ConnectorExecuteCall(_Wire):
@@ -121,6 +150,23 @@ class ConnectorExecuteRequest(_Wire):
op: Optional[str] = Field(default=None, min_length=1, max_length=128)
+class ConnectorExecuteSingleRequest(_Wire):
+ call: ConnectorExecuteCall
+ return_to: Optional[ConnectorReturnTarget] = Field(default=None, alias="returnTo")
+ op: Optional[str] = Field(default=None, min_length=1, max_length=128)
+
+
+class ConnectorExecuteSingleResult(_Wire):
+ connector: str = ""
+ tool: str = ""
+ data: Any = None
+ account: Optional[str] = None
+
+
+class ConnectorExecuteSingleResponse(_Wire):
+ result: ConnectorExecuteSingleResult
+
+
class ConnectorExecuteResult(_Wire):
# Never correlate results by wire index.
index: int = 0