sec0-sdk/middleware.
callToolViaGateway
The standard bridge function for routing tool calls through the gateway:
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
gatewayBaseUrl | string | Yes | Gateway base URL |
server | string | Yes | Tool server name |
toolAtVersion | string | Yes | Tool name@version |
args | any | No | Tool arguments |
authHeader | string | No | Authorization header |
cause.traceId | string | Yes | Parent trace ID |
cause.spanId | string | Yes | Parent span ID |
agentState | AgentStatePayload | No | Agent state to forward |
tenant | string | No | Tenant override |
runId | string | No | Graph run identifier |
nodeId | string | No | Graph node identifier |
traceparent | string | No | W3C traceparent header |
baggage | string | No | W3C baggage header |
idempotencySalt | string | No | Extra entropy for idempotency |
timeoutMs | number | No | Request timeout (ms) |
AP2 Mandate Forwarding
Identity Context Forwarding
callToolViaGatewayWithAgent
A convenience wrapper that accepts an agent block instead of a raw agentState:
buildIdempotencyKey
Generate a deterministic idempotency key for a tool call:
runId, nodeId, toolAtVersion, and a short digest of args. Pass a stable runId and nodeId when you want deterministic replay protection; if runId is omitted, the helper generates one and the result changes across runs.
Using Bridge with Instrumentation Decorators
When using decorators, theAgentManager makes gateway calls seamless:
manager.invoke() call automatically:
- Resolves the gateway hop config from
app.hops - Builds the agent state from the current context
- Injects auth headers, idempotency keys, and cause context (per automation flags)
- Issues the gateway call with full custody chain