Asking
A middleware that asks typed questions of type Q and takes answers of type Ans, as org.llm4s.agent.graph.tool.AgentTool.Asking does for a tool: it suspends the run for a reviewer - to approve or edit an answer, or to supply missing information - instead of only blocking or failing.
A hook asks by returning ask - from beforeAgent, afterAgent or wrapModelCall - or askAbout from wrapToolCall. The run suspends at the end of the superstep with a question of its own, keyed by the asking task's interrupt id like any other, so several pending questions are answered together or one at a time. The answer is decoded as Ans when the run is resumed: one that does not decode is refused, the thread unchanged.
Once answered, the hook's whole stack runs again from the outermost middleware - nothing about a stack's position is checkpointed, as for approvals - and answered gives this middleware its question and answer, so it continues instead of asking again. Answers given earlier in the same stack run are kept while it runs again, so two asking middleware in one stack each ask once. A middleware outside the asking one therefore runs twice, and must not depend on running once.
What runs again is the asking task: beforeAgent re-runs the turn's input (nothing of the turn is stored while it waits), afterAgent the final answer, wrapToolCall the tool call (its arguments checked again), and wrapModelCall the model call - so a model wrapper that asks after calling next calls the model again once answered, unless it returns a completion of its own (the calls made before asking are counted in the thread's usage, and announced, while the question waits). A question from a tool wrapper while the tool continues after its own question is refused, as the call's error result.
Attributes
- Source
- AgentMiddleware.scala
- Graph
-
- Supertypes
- Known subtypes
Members list
Value members
Concrete methods
This middleware's question and its answer, when its hook runs again after a resume; None before.
This middleware's question and its answer, when its hook runs again after a resume; None before.
Attributes
- Source
- AgentMiddleware.scala
answered for a tool call's context.
answered for a boundary or model hook's context.
Suspends the run with question; return it as the result of beforeAgent, afterAgent or wrapModelCall. A question that does not encode is that Left instead.
Suspends the run with question; return it as the result of beforeAgent, afterAgent or wrapModelCall. A question that does not encode is that Left instead.
Attributes
- Source
- AgentMiddleware.scala
Suspends the tool call with question; return it as the result of wrapToolCall.
Suspends the tool call with question; return it as the result of wrapToolCall.
Attributes
- Source
- AgentMiddleware.scala
Inherited methods
Admits the turn's query before anything of the turn is stored (#2854): returns it, possibly rewritten, or refuses it. Each middleware's stage runs in stack order on the query the one before returned, and all of them before any beforeAgent.
Admits the turn's query before anything of the turn is stored (#2854): returns it, possibly rewritten, or refuses it. Each middleware's stage runs in stack order on the query the one before returned, and all of them before any beforeAgent.
Right(query)admits the turn with that text: it is what the turn's first checkpoint, its run queue entry and every later hook hold, and the query as submitted is stored nowhere. Redact here, not inbeforeAgent.- block refuses it: the turn ends
AgentStatus.Blocked(id, reason), and nothing of the query is stored - the blocked run records which middleware refused, and itsGuardrailBlockedevent, and no text. - any other
Leftrefuses to start the turn:agent.runreturns it as itsLeft, the thread unchanged and no run started. A blank query returned is refused the same way.
It decides and rewrites, and nothing else: it has no thread state to read, returns no update, cannot ask a question (a middleware that asks from here is refused) and has no tool to call; its context offers only the turn's identity and a way to count a model call. Run before the turn is stored, it runs once for the turn, however often the turn's input step runs afterwards - a recover or a resume runs beforeAgent again, never this - and its verdict is final: a later change of mind is beforeAgent's.
It runs before the thread is claimed, so a turn the runtime then refuses (ThreadBusy, PendingInterrupts, ...) has had its stages run, and a model call one of them made is counted in no thread's usage.
It runs before the query is stored whenever the turn starts through Agent.run, start or stream, and when a queue's submitter calls Agent.admit first. A turn that is stored before the agent sees it - a query put on a run queue as it is, a delegated child's task - runs the stage as the first thing of its input step instead: the verdict is the same, but that query was already stored by whoever stored it, and the stage runs again if that step does (a recover of a step that failed).
Attributes
- Inherited from:
- AgentMiddleware
- Source
- AgentMiddleware.scala
Sees the run's final answer: returns it, possibly changed, with an update to this middleware's writes. A Left blocks the turn, removing it; block blocks it as an outcome, AgentStatus.Blocked.
Sees the run's final answer: returns it, possibly changed, with an update to this middleware's writes. A Left blocks the turn, removing it; block blocks it as an outcome, AgentStatus.Blocked.
Attributes
- Inherited from:
- AgentMiddleware
- Source
- AgentMiddleware.scala
Sees the run's input, as admitted, before anything else of the turn runs: returns it, possibly changed, with an update to this middleware's writes that the turn's first model call sees. A Left blocks the turn; block blocks it as an outcome, AgentStatus.Blocked. The query it is given is already in the turn's first checkpoint: to keep text out of the store, rewrite or refuse it in admit.
Sees the run's input, as admitted, before anything else of the turn runs: returns it, possibly changed, with an update to this middleware's writes that the turn's first model call sees. A Left blocks the turn; block blocks it as an outcome, AgentStatus.Blocked. The query it is given is already in the turn's first checkpoint: to keep text out of the store, rewrite or refuse it in admit.
Attributes
- Inherited from:
- AgentMiddleware
- Source
- AgentMiddleware.scala
Where this middleware must run relative to other, when both are present; None, the default, when it does not matter. A requirement is checked, never arranged: AgentBuilder.build() refuses a stack in which this middleware does not run outside other, and a Placement.OutsideAtBoundary is checked across an agent family too, which runsBefore cannot arrange. Register the two in the right order, or name other in runsBefore. other is the middleware itself, so match it by its type, as a MiddlewareRef names one, or by other.id.
Where this middleware must run relative to other, when both are present; None, the default, when it does not matter. A requirement is checked, never arranged: AgentBuilder.build() refuses a stack in which this middleware does not run outside other, and a Placement.OutsideAtBoundary is checked across an agent family too, which runsBefore cannot arrange. Register the two in the right order, or name other in runsBefore. other is the middleware itself, so match it by its type, as a MiddlewareRef names one, or by other.id.
Attributes
- Inherited from:
- AgentMiddleware
- Source
- AgentMiddleware.scala
Content for the system prompt of each model request: collected before every model step from the committed state, in stack order, and never stored. Each middleware bounds its own; the agent bounds them all together (maxPromptSectionTokens). Left fails the run.
Content for the system prompt of each model request: collected before every model step from the committed state, in stack order, and never stored. Each middleware bounds its own; the agent bounds them all together (maxPromptSectionTokens). Left fails the run.
Attributes
- Inherited from:
- AgentMiddleware
- Source
- AgentMiddleware.scala
Middleware this one must run inside of (be wrapped by), named and arranged as runsBefore's are.
Middleware this one must run inside of (be wrapped by), named and arranged as runsBefore's are.
Attributes
- Inherited from:
- AgentMiddleware
- Source
- AgentMiddleware.scala
Middleware this one must run outside of (wrap): the stack is arranged so. Each is named by id or by type (MiddlewareRef) and must be in the same stack, unless the reference is optional (ifPresent).
Middleware this one must run outside of (wrap): the stack is arranged so. Each is named by id or by type (MiddlewareRef) and must be in the same stack, unless the reference is optional (ifPresent).
Attributes
- Inherited from:
- AgentMiddleware
- Source
- AgentMiddleware.scala
Tools this middleware contributes; they join the loop's tool set and are validated like any other.
Tools this middleware contributes; they join the loop's tool set and are validated like any other.
Attributes
- Inherited from:
- AgentMiddleware
- Source
- AgentMiddleware.scala
Wraps one model call. A wrapper may rewrite the request (inject a note, filter tools), call next more than once (retry, fallback), transform its response, add an update to its writes (ModelResponse.addUpdate), or return Left, which fails the run. Only an AgentMiddleware.Asking wrapper suspends, by asking its question. Every call next makes is counted in the thread's usage, whichever response the wrapper returns.
Wraps one model call. A wrapper may rewrite the request (inject a note, filter tools), call next more than once (retry, fallback), transform its response, add an update to its writes (ModelResponse.addUpdate), or return Left, which fails the run. Only an AgentMiddleware.Asking wrapper suspends, by asking its question. Every call next makes is counted in the thread's usage, whichever response the wrapper returns.
Filtering ModelRequest.tools shapes what the model is offered and is not a permission control: a tool the model calls anyway still runs through wrapToolCall, where denial belongs.
Attributes
- Inherited from:
- AgentMiddleware
- Source
- AgentMiddleware.scala
Wraps one tool call, after its arguments were validated. A wrapper denies with ToolOutcome.Error("Denied: ..."), asks for approval with NeedsApproval(reason) (unless context.approved), fails the run with Fatal - its Left: the run fails with GraphError.ToolFailed - and short-circuits by not calling next. It may call next more than once (retry) and transform the outcome next returns, adding an update to its writes with ToolOutcome.addUpdate. next takes no request: the call is read-only.
Wraps one tool call, after its arguments were validated. A wrapper denies with ToolOutcome.Error("Denied: ..."), asks for approval with NeedsApproval(reason) (unless context.approved), fails the run with Fatal - its Left: the run fails with GraphError.ToolFailed - and short-circuits by not calling next. It may call next more than once (retry) and transform the outcome next returns, adding an update to its writes with ToolOutcome.addUpdate. next takes no request: the call is read-only.
Attributes
- Inherited from:
- AgentMiddleware
- Source
- AgentMiddleware.scala
The state keys this middleware's hooks may write: an update from beforeAgent, wrapModelCall or afterAgent, or one wrapToolCall adds to a Success. A hook's write to any other key fails the run.
The state keys this middleware's hooks may write: an update from beforeAgent, wrapModelCall or afterAgent, or one wrapToolCall adds to a Success. A hook's write to any other key fails the run.
Attributes
- Inherited from:
- AgentMiddleware
- Source
- AgentMiddleware.scala
Inherited and Abstract methods
This middleware's identifier, unique in its stack; must match [a-zA-Z0-9_-]{1,64}.
This middleware's identifier, unique in its stack; must match [a-zA-Z0-9_-]{1,64}.
Attributes
- Inherited from:
- AgentMiddleware
- Source
- AgentMiddleware.scala
