Skip to content

latent.serve.protocol

ServingProtocol — the contract an agent must satisfy to be served over the wire.

:class:~latent.protocol.AgentProtocol says an agent can produce a stream. ServingProtocol adds the one thing deploying it behind latent serve additionally requires: a readiness probe. The serving loop calls it to gate the initial registration (a pod that can't serve never enters the registry) and on every heartbeat (so the version's lease tracks health, not just process liveness).

It lives in latent.serve — not latent.protocol — on purpose. The core agent contract stays minimal: an agent that is only ever run in-process (eval harnesses, Prefect flows, tests) never carries this surface. Only agents you actually deploy over the wire opt into it, and latent serve enforces it at the boundary with isinstance(agent, ServingProtocol).

Classes

ServingProtocol

ServingProtocol()

An :class:~latent.protocol.AgentProtocol that can also report readiness.

@runtime_checkable so latent serve can isinstance-gate an agent before deploying it. The check verifies the presence of ready — every :class:~latent.agents.base.BaseAgent subclass carries it (the default reports ready once constructed), so any such agent passes; a foreign object without the method at all fails the isinstance gate directly.

Functions

health_representative

health_representative(make_agent: AgentFactory, name: str) -> ServingProtocol

Build the one long-lived agent a served deployment uses as its health probe.

Request handlers build a fresh agent per request (ephemeral, stateless); this single instance is the deployment's stable readiness representative — its :meth:~ServingProtocol.ready is called at startup (gating the first registration) and on every heartbeat.

Fails fast here, before the server binds, with a :class:TypeError if the agent doesn't satisfy :class:ServingProtocol at all — so a mis-configured deployment dies at startup rather than at the first heartbeat. An agent that inherits the default ready() (ready once constructed) serves fine; only an agent with external deps needs to override it.

Methods

ServingProtocol.ready

ready() -> bool

Report whether this agent can serve a request right now.

Return True when the agent's dependencies — model credentials, datastores, tools — are reachable; False (or raise) to keep the pod out of the registry until it recovers. Must be cheap and side-effect-free: the serving loop calls it at startup and on every heartbeat.

Deployment-level, not per-request — a check of the environment, not of any single conversation's state.