Annotation Interface ErrorHandler
Marks a method as an error handler for a workflow agent.
The annotated method must be static, an
ErrorContext as argument and return an instance of ErrorRecoveryResult.
Besides the ErrorContext, it can declare parameters resolved through a SupplierParameterResolver.
It will be invoked when an error occurs during the agent's operation, allowing for custom error handling logic.
Example:
public interface StoryCreatorWithErrorRecovery {
@SequenceAgent(outputKey = "story",
subAgents = { CreativeWriter.class, AudienceEditor.class, StyleEditor.class })
String write(@V("topic") String topic, @V("style") String style, @V("audience") String audience);
@ErrorHandler
static ErrorRecoveryResult errorHandler(ErrorContext errorContext) {
if (errorContext.agentName().equals("generateStory") &&
errorContext.exception() instanceof MissingArgumentException mEx && mEx.argumentName().equals("topic")) {
errorContext.agenticScope().writeState("topic", "dragons and wizards");
return ErrorRecoveryResult.retry();
}
return ErrorRecoveryResult.throwException();
}
}