AdmissionContext

org.llm4s.agent.graph.middleware.AdmissionContext
See theAdmissionContext companion object
@Experimental
final class AdmissionContext extends UsageAccounting

What a middleware's admit stage is given (#2854): who the turn is for, and a way to have the stage's own model calls counted.

It is less than a hook's ModelContext on purpose. Admission runs before the turn has a run, a task or a checkpoint, so that a query it refuses or rewrites is never stored as submitted: there is no thread state to read or update, no event to emit, no question to ask and no tool to call, and so nothing here offers them. A stage that needs any of those belongs in beforeAgent.

A stage that calls a model - an LLM judge - wraps its client with accounted. Its calls are counted in the thread's usage and announced with a durable ModelCallCompleted as a hook's are, when the turn's input step commits; they are made before the run exists, so its token budget (RunBudgets.maxTokens) does not refuse them, though it counts them.

Value parameters

agent

the agent whose stack the stage is in

principal

who the run is for (RunConfig.principal)

tenantId

the tenant of the run being admitted (RunConfig.tenantId)

threadId

the thread the turn is for

Attributes

Companion
object
Source
AdmissionContext.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def accounted(client: LLMClient): LLMClient

client, with the usage of every complete and streamComplete through it counted in the thread's usage, as ModelContext.accounted counts a hook's. close does not close client: the stage that owns it does.

client, with the usage of every complete and streamComplete through it counted in the thread's usage, as ModelContext.accounted counts a hook's. close does not close client: the stage that owns it does.

Attributes

Source
AdmissionContext.scala
def recordUsage(model: ModelName, usage: TokenUsage, estimatedCost: Option[BigDecimal]): Unit

Records usage that arrived without a client call, as one request to model.

Records usage that arrived without a client call, as one request to model.

Attributes

Source
AdmissionContext.scala

Concrete fields

val agent: AgentId

Attributes

Source
AdmissionContext.scala

Attributes

Source
AdmissionContext.scala