Skip to main content

Layer 2 · intelligence

gateway

blocks/2-intelligence/gateway.yaml

layer 2intelligence
3entities
9commands
9events
3views
12refusals
3KPIs

The one place model calls pass. A gateway holds upstreams, each an endpoint of agentic.model behind it. Every call by a caller principal on a route is decided once and recorded under its InferenceId: admitted, over-budget, rate-limited or no-upstream. An admitted call is completed with its usage and outcome; a refused call stays on record and cannot complete. A gateway that drains admits no new call.

Depends on​

  • model · layer 2 · 14 references
  • principal · layer 1 · 5 references
  • shared · layer 0 · 10 references

Used by​

No block depends on this one.

Entities​

Call​

The record of one call, under the InferenceId it carries into agentic.model. Every call has one, whether it was admitted or not. Recorded until a call that was admitted completes; a refused call stays Recorded.

Identified by inference_id (InferenceId).

fieldtypemeaning
gateway_idGatewayId
callerPrincipalId
route_idRouteId
admissionAdmission
budget_leftMoneyWhat the caller's budget held when the call was decided.
upstream_idUpstreamIdThe upstream the gateway named for the route; for a no-upstream call it may name nothing that exists.
usageoptional Usage
outcomeoptional InferenceOutcome

Relations:

  • route references Route of model (one, by route_id)
  • upstream references Upstream (one, by upstream_id)
  • caller_principal references Principal of principal (one, by caller)

Lifecycle of Call

CompletedRecordedcompleteCompletedRecordedcomplete
Ends in Completed.

Gateway​

One gateway. Serving admits calls, Draining finishes what runs and admits nothing, Stopped is final.

Identified by gateway_id (GatewayId).

fieldtype
nameName

Relations:

  • upstreams owns Upstream (many, by gateway_id)
  • calls owns Call (many, by gateway_id)

Lifecycle of Gateway

DrainingServingStoppeddrainstopstopDrainingServingStoppeddrainstopstop
Ends in Stopped.

Upstream​

An endpoint behind one gateway. Attached takes calls, Saturated has reached its rate limit and takes none until it recovers, Detached is gone.

Identified by upstream_id (UpstreamId).

fieldtype
gateway_idGatewayId
endpoint_idEndpointId

Relations:

  • endpoint references Endpoint of model (one, by endpoint_id)

Lifecycle of Upstream

AttachedDetachedSaturatedsaturaterestoredetachdetachAttachedDetachedSaturatedsaturaterestoredetachdetach
Ends in Detached.

Commands​

AdmitCall​

Admit a call. Decide one call and record it. The gateway names the upstream it picked for the route and reports what the caller's budget holds; the answers are admitted, over-budget, rate-limited and no-upstream, and each leaves a record. A call on an unknown gateway, or on one that does not serve, is an error and leaves no record, except that a call naming an upstream that does not exist is recorded no-upstream whatever state the gateway is in. Not specified yet: how the gateway picks an upstream for a route is not modelled; and a draining gateway cannot refuse a call that names a missing upstream before recording it. ESS limit (0.99.17): a missing row answers before any row's state, and an outcome over the upstream's fields needs the missing-row outcome beside it (design/ess-repro/missing-row-before-state/; an ESS draft story lets a missing-row refusal answer before the held-state outcomes of its command).

Called by: Gateway.

fieldtype
inference_idInferenceId
gateway_idGatewayId
callerPrincipalId
route_idRouteId
upstream_idUpstreamId
budget_leftMoney
requestContent
outcomewhenresult
unknown-gateway refusedno Gateway for gateway_idUnknownGateway: No gateway of this identity was opened.
no-upstreamno Upstream for upstream_idcreates a Call in Recorded; emits CallDecided
gateway-not-serving refusedthe Gateway of gateway_id has state != ServingGatewayNotServing: The gateway is draining or stopped, so it admits no new call and takes no new upstream.
no-upstream-detachedthe Upstream of upstream_id has state == Detachedcreates a Call in Recorded; emits CallDecided
no-upstream-foreignthe Upstream of upstream_id has gateway_id != input.gateway_idcreates a Call in Recorded; emits CallDecided
rate-limitedthe Upstream of upstream_id has state == Saturatedcreates a Call in Recorded; emits CallDecided
over-budgetbudget_left.micro_usd == 0creates a Call in Recorded; emits CallDecided
admittedotherwisecreates a Call in Recorded; emits CallDecided

AttachUpstream​

Attach an upstream.

Called by: Gateway operator.

fieldtype
upstream_idUpstreamId
gateway_idGatewayId
endpoint_idEndpointId
outcomewhenresult
unknown-gateway refusedno Gateway for gateway_idUnknownGateway: No gateway of this identity was opened.
unknown-endpoint refusedno Endpoint for endpoint_idUnknownEndpoint: No endpoint of this identity is declared in agentic.model.
gateway-not-serving refusedthe Gateway of gateway_id has state != ServingGatewayNotServing: The gateway is draining or stopped, so it admits no new call and takes no new upstream.
attachedotherwisecreates a Upstream in Attached; emits UpstreamAttached

CompleteCall​

Complete a call.

Called by: Gateway.

fieldtype
inference_idInferenceId
outcomeInferenceOutcome
usageUsage
outcomewhenresult
not-admitted refusedadmission != AdmittedCallNotAdmitted: The call was refused at admission, so there is nothing to complete.
completedotherwisemoves the Call Recorded → Completed; emits CallCompleted
wrong-state refusedthe Call is in a state that does not allow itCallStateConflict: The call is not in a state this command acts from; it had already completed.

DetachUpstream​

Detach an upstream.

Called by: Gateway operator.

fieldtype
upstream_idUpstreamId
outcomewhenresult
detachedotherwisemoves the Upstream Attached, Saturated → Detached; emits UpstreamDetached
wrong-state refusedthe Upstream is in a state that does not allow itUpstreamStateConflict: The upstream is not in a state this command acts from.

DrainGateway​

Drain a gateway.

Called by: Gateway operator.

fieldtype
gateway_idGatewayId
outcomewhenresult
drainingotherwisemoves the Gateway Serving → Draining; emits GatewayDrained
wrong-state refusedthe Gateway is in a state that does not allow itGatewayStateConflict: The gateway is not in a state this command acts from.

OpenGateway​

Open a gateway.

Called by: Gateway operator.

fieldtype
gateway_idGatewayId
nameName
outcomewhenresult
openedotherwisecreates a Gateway in Serving; emits GatewayOpened

RestoreUpstream​

Restore an upstream.

Called by: Gateway.

fieldtype
upstream_idUpstreamId
outcomewhenresult
restoredotherwisemoves the Upstream Saturated → Attached; emits UpstreamRestored
wrong-state refusedthe Upstream is in a state that does not allow itUpstreamStateConflict: The upstream is not in a state this command acts from.

SaturateUpstream​

Mark an upstream saturated.

Called by: Gateway.

fieldtype
upstream_idUpstreamId
outcomewhenresult
saturatedotherwisemoves the Upstream Attached → Saturated; emits UpstreamSaturated
wrong-state refusedthe Upstream is in a state that does not allow itUpstreamStateConflict: The upstream is not in a state this command acts from.

StopGateway​

Stop a gateway.

Called by: Gateway operator.

fieldtype
gateway_idGatewayId
outcomewhenresult
stoppedotherwisemoves the Gateway Draining, Serving → Stopped; emits GatewayStopped
wrong-state refusedthe Gateway is in a state that does not allow itGatewayStateConflict: The gateway is not in a state this command acts from.

Events​

eventfieldsemitted by
CallCompletedinference_id InferenceId, outcome InferenceOutcome, usage UsageCompleteCall
CallDecidedinference_id InferenceId, gateway_id GatewayId, caller PrincipalId, route_id RouteId, admission Admission, upstream_id UpstreamId, request ContentAdmitCall
GatewayDrainedgateway_id GatewayIdDrainGateway
GatewayOpenedgateway_id GatewayId, name NameOpenGateway
GatewayStoppedgateway_id GatewayIdStopGateway
UpstreamAttachedupstream_id UpstreamId, gateway_id GatewayId, endpoint_id EndpointIdAttachUpstream
UpstreamDetachedupstream_id UpstreamIdDetachUpstream
UpstreamRestoredupstream_id UpstreamIdRestoreUpstream
UpstreamSaturatedupstream_id UpstreamIdSaturateUpstream

Views​

viewrowsfields
Calls
Calls
each Callinference_id InferenceId, gateway_id GatewayId, caller PrincipalId, route_id RouteId, admission Admission, budget_left Money, upstream_id UpstreamId, usage optional Usage, outcome optional InferenceOutcome, state State
Gateways
Gateways
each Gatewaygateway_id GatewayId, name Name, state State
Upstreams
Upstreams
each Upstreamupstream_id UpstreamId, gateway_id GatewayId, endpoint_id EndpointId, state State

Types​

typeisvalues or fields
Admission
How the gateway decided one call.
one ofAdmitted, OverBudget, RateLimited, NoUpstream

KPIs​

3 KPIs from the KPI catalogue. A gate must be zero for a variant of an architecture to count.

Completeness​

KPIunitbettergatestatus
call_record_share
Share of model calls that have a gateway record.
How: Inferences started that have a CallDecided and a CallCompleted of the gateway, divided by inferences started. The gateway is the one place calls pass, so it must be 1.
sharehighergateplanned
source: design

Quality​

KPIunitbettergatestatus
rate_limited_seconds
Time requests waited because an upstream was saturated.
How: Sum over upstreams of the seconds between UpstreamSaturated and the next UpstreamRestored, weighted by the calls held back in that interval.
secondslower–simulated
source: design
call_denied_share
Share of model calls the gateway refused at admission.
How: CallDecided events with a refusal divided by all CallDecided events, by reason (budget, route, rate).
sharelower–planned
source: design

Settings​

The settings a part of this block carries in an architecture document. agenticspec sim check refuses any other setting (setting_unknown) and a value outside its type (setting_invalid), and a part that lacks a setting marked required in the default column; the contract copies a setting into the ports it narrows. The last rows of each table are the settings every part takes. What no setting here types (a file, a path, an audience, the use of a model) goes into the part's notes, a map with free keys and values that the check takes as written and nothing reads.

A part gateway:

settingtypeunitdefaultcontractwhat
rate_limit_per_minutenumber of at least 0calls per minutegateway.callThe model calls the gateway admits per minute; without it, no limit.
countinteger of at least 11How many copies of the part run.
perpartOne copy of the part for each copy of the named part.
notesnotesFree notes on the part, a map with keys and values of any kind: what no setting of its block types. The check takes any map; the simulator, the search and the contract never read it.