Skip to content

feat(agent): support batched array loops - #4842

Open
March-77 wants to merge 2 commits into
alibaba:mainfrom
March-77:agent/issue-4664-array-loop-batching
Open

March-77 wants to merge 2 commits into
alibaba:mainfrom
March-77:agent/issue-4664-array-loop-batching

Conversation

@March-77

Copy link
Copy Markdown
Contributor

Describe what this PR does / why we need it

Adds opt-in batched dispatch to LoopAgent array loops. Callers can now use LoopMode.array(batchSize) when a sub-agent should process several input elements per iteration, such as processing 20 images in groups of 5.

The root cause of the limitation was that ArrayLoopStrategy.loopDispatch always selected exactly one list element and incremented its cursor by one. There was no API for controlling the number of elements sent to each iteration.

Does this pull request fix one issue?

Fixes #4664

Describe how you did it

  • Added LoopMode.array(int batchSize) and LoopMode.array(int batchSize, Converter<...>) overloads.
  • Added validated batch-size configuration to ArrayLoopStrategy.
  • Dispatches each opt-in batch as a valid JSON array and advances the cursor by the actual number of consumed elements.
  • Preserves the existing array() and array(converter) single-element message behavior.
  • Added deterministic unit tests for full batches, a short final batch, backward-compatible single-element dispatch, completion, and invalid batch sizes.

User impact: LoopAgent users can express bounded batch processing without wrapping or subclassing agents. Existing users see no behavior change unless they select a batched overload.

Describe how to verify it

JAVA_HOME=/opt/homebrew/opt/openjdk PATH=/opt/homebrew/opt/openjdk/bin:$PATH ./mvnw -pl spring-ai-alibaba-agent-framework test

Result: BUILD SUCCESS; 593 tests run, 0 failures, 0 errors, 167 environment-dependent tests skipped. Checkstyle and Spotless passed in the same build.

Special notes for reviews

The API change is additive and source compatible. Batched message serialization is only enabled when batchSize is explicitly provided; the final batch may contain fewer elements. Non-positive sizes fail fast with IllegalArgumentException.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b36636f380

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@oss-sentinel-ai oss-sentinel-ai left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Reviewed the changes in this PR (191 lines changed). The changes appear to be well-structured.

Observations

  • Changes span 191 lines
  • Please ensure all edge cases are covered
  • Verify test coverage for the modified code paths

Automated review by github-manager-bot

@March-77

Copy link
Copy Markdown
Contributor Author

@yuluo-yx 已重新核对当前 head、最新 main 变化、mergeability、CI、reviews 和 review threads;现有评审意见均已验证并清理,未发现需要追加代码修改的问题。烦请在方便时进行维护者审查,谢谢。

yuluo-yx pushed a commit to agentic-ai-java/argi that referenced this pull request Oct 15, 2026
Adapt the approach in alibaba/spring-ai-alibaba#4842 to ARGI's neutral
ChatMessage and JsonCodec APIs. Preserve legacy single-element dispatch,
use overflow-safe cursor arithmetic, and add offline regression tests.

Refs #156.
yuluo-yx pushed a commit to agentic-ai-java/argi that referenced this pull request Oct 17, 2026
Adapt the approach in alibaba/spring-ai-alibaba#4842 to ARGI's neutral
ChatMessage and JsonCodec APIs. Preserve legacy single-element dispatch,
use overflow-safe cursor arithmetic, and add offline regression tests.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 目前ReactAgent搭配Sequential Agent这些智能编排不支持循环调用

2 participants