feat: add retryOnParsingError method to BaseAgent for enhanced error handling
This commit is contained in:
@@ -870,6 +870,7 @@ final var blogPostAgent = new Agent(
|
||||
| `postProcess(context)` | Runs after completion. | no-op |
|
||||
| `merge(contexts)` | Merges split contexts after branching. | `null` |
|
||||
| `chooseNextAgent(context)` | Selects the next agent or ends the flow. Required. | none |
|
||||
| `retryOnParsingError(context)` | When `true`, triggers an outer retry loop that resets both parse attempts and tool call rounds after a parsing failure, allowing the agent to request a fresh completion from scratch. The conversation can be modified before retrying. | `false` |
|
||||
|
||||
### Agent Tool Calling
|
||||
|
||||
|
||||
@@ -112,6 +112,10 @@ public interface BaseAgent {
|
||||
return AgentNext.END;
|
||||
}
|
||||
|
||||
default boolean retryOnParsingError(final AgentContext context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default List<AgentContext> execute(final Client client, final ExecutorService agentExecutorService, final AgentContext context) {
|
||||
final var splits = new ArrayList<Split>();
|
||||
|
||||
@@ -159,10 +163,13 @@ public interface BaseAgent {
|
||||
var toolCallData = supportsToolCalling ? this.toolCallData(split.context()) : null;
|
||||
this.rememberToolCallData(split.context(), toolCallData);
|
||||
|
||||
boolean retryOuterLoop;
|
||||
boolean parseable = false;
|
||||
Exception parseException = null;
|
||||
int parseAttempts = 0;
|
||||
int toolCallRounds = 0;
|
||||
do {
|
||||
retryOuterLoop = false;
|
||||
while (parseAttempts < 2) {
|
||||
LOGGER.debug("Conversation: {}", conversation);
|
||||
|
||||
@@ -261,11 +268,18 @@ public interface BaseAgent {
|
||||
}
|
||||
}
|
||||
if (!parseable) {
|
||||
if (this.retryOnParsingError(split.context())) {
|
||||
parseAttempts = 0;
|
||||
toolCallRounds = 0;
|
||||
retryOuterLoop = true;
|
||||
continue;
|
||||
}
|
||||
LOGGER.warn("{} Response is still not parseable after last attempt", this.name());
|
||||
split.context().getGraph().add("☢");
|
||||
split.context().setError(AgentErrorType.PARSING, parseException);
|
||||
return;
|
||||
}
|
||||
} while (retryOuterLoop);
|
||||
}
|
||||
|
||||
this.postProcess(split.context());
|
||||
|
||||
Reference in New Issue
Block a user