Repository navigation
Description
Describe the bug
When a ReActAgent reaches maxIters, the summary path creates a ModelCallInput with tools = null and sends it through the regular MiddlewareBase.onModelCall chain.
However, the ModelCallInput API only describes tools as "the tool schemas" and does not document that the list may be null. A middleware that treats it as a normal collection, for example by calling input.tools().stream(), fails with a NullPointerException. The max-iteration summary never reaches the model.
The relevant code is currently:
ReActAgent.CallExecution.summaryStream():
.apply(new ModelCallInput(messages, null, options, model))This behavior exists in v2.0.0-RC5 and is still present on the current main branch.
To Reproduce
- Register an
onModelCallmiddleware that processes the tool schema collection:
@Override
public Flux<AgentEvent> onModelCall(
Agent agent,
RuntimeContext ctx,
ModelCallInput input,
Function<ModelCallInput, Flux<AgentEvent>> next) {
input.tools().stream().forEach(schema -> inspect(schema));
return next.apply(input);
}- Configure a
ReActAgentwith a lowmaxItersvalue and a model response that keeps the reasoning/acting loop running until the limit is reached. - Execute the agent.
- When
summarizing()invokessummaryStream(), the middleware receivestools = nulland throws before the summary model call.
Expected behavior
A model call with no available tools should expose an empty, non-null collection to middleware. For example, the summary path could use List.of(), or ModelCallInput could normalize a null tools value in its constructor.
If null is intentionally part of the public contract, that nullability should be explicit in the API and middleware documentation. A non-null empty list is preferable because middleware chains commonly transform or inspect tool schemas as collections.
Error messages
java.lang.NullPointerException: Cannot invoke "java.util.List.stream()"
because the return value of
"io.agentscope.core.middleware.ModelCallInput.tools()" is null
at <custom middleware>.onModelCall(...)
at io.agentscope.core.middleware.MiddlewareChain.lambda$build$0(...)
at io.agentscope.core.ReActAgent$CallExecution.summaryStream(...)
at io.agentscope.core.ReActAgent$CallExecution.summarizing(...)
Environment
- AgentScope-Java Version: 2.0.0-RC5
- Java Version: 21
- OS: Linux
Additional context
The normal reasoning path passes the list returned by Toolkit.getToolSchemas(...), while only the max-iteration summary path deliberately passes null. This makes the generic onModelCall middleware contract path-dependent.
A focused regression test could register a middleware that asserts input.tools() != null, force maxIters to be reached, and verify that the summary model call completes.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fix(middleware): normalize model call tools (agentscope-ai#2756)