Repository navigation
Description
Is your feature request related to a problem? Please describe.
Yes. When a ReActAgent reaches maxIters, summarizing() emits an ExceedMaxItersEvent and attempts one final summary model call.
If that summary succeeds, the returned message is tagged with GenerateReason.MAX_ITERATIONS. If the summary fails, however, handleSummaryError() catches the exception and returns a plain AssistantMessage containing text such as:
Maximum iterations (100) reached. Error generating summary: ...
That fallback message is not tagged with GenerateReason.MAX_ITERATIONS and carries no structured summary-failure information. The agent then completes normally, so adapters commonly emit an ordinary agent result followed by agent end.
Consumers that determine run status from the final result can therefore classify an exhausted and unsuccessfully summarized run as successful. The only reliable signal is the earlier event, which requires every adapter and orchestrator to retain cross-event state.
Describe the solution you'd like
Please preserve max-iteration terminal semantics even when summary generation fails.
At minimum:
- Tag the fallback message returned by
handleSummaryError()withGenerateReason.MAX_ITERATIONS. - Preserve a structured indication that summary generation failed, for example through message metadata or a dedicated event that includes the failure category without exposing sensitive provider details.
- Document that reaching
maxItersis a terminal partial/failure outcome even though the agent returns a graceful final message.
A possible shape is:
AssistantMessage.builder()
.name(getName())
.content(...)
.generateReason(GenerateReason.MAX_ITERATIONS)
.metadata(Map.of("summaryStatus", "failed"))
.build();The exact metadata/event API is open for discussion; the key requirement is that callers should not need to parse English text or correlate a previous event to identify the terminal outcome.
It would also be useful to add tests for both branches:
- max iterations + successful summary -> final message has
MAX_ITERATIONS; - max iterations + failed summary -> fallback message still has
MAX_ITERATIONSand exposes structured summary failure.
Describe alternatives you've considered
- Only consume
ExceedMaxItersEvent: works, but forces adapters to maintain state across events and is easy to miss when only the final agent result is persisted. - Parse the fallback text: brittle, locale-dependent, and couples consumers to an implementation string.
- Propagate the summary exception instead of returning a message: preserves failure semantics but removes the useful graceful fallback response. A structured fallback result provides both.
- Treat any returned
AssistantMessageas success: this is the current behavior in many integrations and is the source of the ambiguity.
Additional context
In ReActAgent.CallExecution.summarizing(), the successful post-summary branch explicitly calls withGenerateReason(GenerateReason.MAX_ITERATIONS). The handleSummaryError() branch builds a new AssistantMessage without the equivalent reason.
This request is independent of the specific cause of a summary failure. The model provider, a middleware, a hook, or stream processing can all fail during the summary call; terminal semantics should remain consistent for all of them.
Observed with AgentScope-Java 2.0.0-RC5; the same behavior is present on the current main branch.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity