Interface AgentResponseGuardrail
- All Superinterfaces:
Guardrail
An implementation has a public constructor, optionally taking a GuardrailContext
parameter, which gives access to the guardrail's configured name and config section. The per-call
data is delivered to decide(akka.javasdk.agent.AgentResponseGuardrail.CallContext) via AgentResponseGuardrail.CallContext.
The runtime shares one instance across concurrent calls from different sessions and agents. An implementation must be thread safe.
To bind this guardrail to an agent that returns Agent.StreamEffect, set
report-only = true on the entry. Otherwise, the service fails to start.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfacePer-call context passed to anAgentResponseGuardrailduringdecide(akka.javasdk.agent.AgentResponseGuardrail.CallContext).Nested classes/interfaces inherited from interface akka.javasdk.agent.Guardrail
Guardrail.GuardrailException, Guardrail.Message, Guardrail.Result -
Method Summary
Modifier and TypeMethodDescriptionDecides whether the reply described byctxmay be returned.default CompletionStage<Decision> Async variant ofdecide(akka.javasdk.agent.AgentResponseGuardrail.CallContext), for implementations that prefer composing futures.
-
Method Details
-
decide
Decides whether the reply described byctxmay be returned.Use
Decision.Denyto refuse the reply. ReturningDecision.Failand throwing are equivalent: both mean the guardrail reached no verdict, which is distinct from refusing the reply.This is the method to implement. It may block: guardrails are always evaluated on virtual threads.
- Returns:
- the decision
-
decideAsync
Async variant ofdecide(akka.javasdk.agent.AgentResponseGuardrail.CallContext), for implementations that prefer composing futures.The default implementation delegates to
decide(akka.javasdk.agent.AgentResponseGuardrail.CallContext). When this method is overridden,decide(akka.javasdk.agent.AgentResponseGuardrail.CallContext)is no longer used, and it is then safe to have it throwUnsupportedOperationExceptionor returnnull.Completing with
Decision.Fail, failing the returned stage, and throwing are equivalent: all three mean the guardrail reached no verdict, which is distinct from refusing the reply.- Returns:
- a CompletionStage with the decision
-