Skip to content

[Feature]: Preserve max-iteration terminal semantics when summary generation fails #2754

Closed

Description

@DennisWLX

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:

  1. Tag the fallback message returned by handleSummaryError() with GenerateReason.MAX_ITERATIONS.
  2. 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.
  3. Document that reaching maxIters is 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_ITERATIONS and 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 AssistantMessage as 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/core/agentenhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions