Package dev.agenor.runtime.guardrail
Class GuardrailAnnotationProcessor
java.lang.Object
dev.agenor.runtime.guardrail.GuardrailAnnotationProcessor
Reads the
WithGuardrails annotation from an LLMAgent subclass
and injects a GuardrailChain into the agent at registration time.
Called by AgenorRuntime.registerAgent() whenever the registered
agent is an instance of LLMAgent:
// Inside AgenorRuntime.registerAgent():
if (agent instanceof LLMAgent llmAgent) {
GuardrailAnnotationProcessor.process(llmAgent);
}
Wiring logic
- If the agent class has no
@WithGuardrailsannotation → no-op. - Instantiate each listed
InputGuardrailandOutputGuardrailclass via its public no-arg constructor (reflection). - If the agent already has a programmatically configured chain, the annotation-derived guardrails are prepended to it.
- Otherwise a new chain is built and injected via
LLMAgent.setGuardrailChain(dev.agenor.runtime.guardrail.GuardrailChain).
Error handling
If a guardrail class listed in the annotation cannot be instantiated (missing no-arg constructor, abstract class, etc.) aGuardrailAnnotationProcessor.GuardrailWiringException is thrown, which aborts agent registration
with a clear message.- Since:
- 0.13.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown when a guardrail class listed in@WithGuardrailscannot be instantiated at agent bootstrap time. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidProcesses theWithGuardrailsannotation onagent's class and injects the resulting chain.
-
Method Details
-
process
Processes theWithGuardrailsannotation onagent's class and injects the resulting chain.This method is a no-op if the agent class carries no annotation.
- Parameters:
agent- the LLM agent being registered; nevernull- Throws:
GuardrailAnnotationProcessor.GuardrailWiringException- if any guardrail class cannot be instantiated
-