Skip to content

[Bug]: Toolkit.callTool returns a ToolResultBlock with null id and name (bypasses executeWithInfrastructure) #3114

Closed

Description

@anirbandas18

Describe the bug

Toolkit.callTool(ToolCallParam) returns a ToolResultBlock whose id and name are null, while Toolkit.callTools(...) stamps both correctly for the same tool and the same call.

Root cause: the two public entry points do not share the stage that stamps them.

  • Toolkit.callTools(...) → ToolExecutor.executeAll(...) → executeWithInfrastructure(...), which applies .map(result -> result.withIdAndName(toolCall.getId(), toolCall.getName())).
  • Toolkit.callTool(param) → ToolExecutor.execute(param) directly, which bypasses executeWithInfrastructure(...) entirely.

withIdAndName(...) is called in exactly two places in ToolExecutor, both inside executeWithInfrastructure(...), so nothing on the callTool path ever stamps the result.

This matters because the id and name are what pair a result back to its call: ToolResultMessageBuilder.buildToolResultMsg(...) and the tool-call pairing model both key off them. A caller following the usage example in Toolkit.callTool's own javadoc gets back a block it cannot correlate.

To Reproduce

  1. Add the following test to agentscope-core/src/test/java/io/agentscope/core/tool/CallToolIdNameReproTest.java:
package io.agentscope.core.tool;

import io.agentscope.core.message.ToolResultBlock;
import io.agentscope.core.message.ToolUseBlock;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;

/** Repro: Toolkit.callTool vs Toolkit.callTools — id/name stamping on the returned block. */
class CallToolIdNameReproTest {

    static class EchoTools {
        @Tool(name = "echo", description = "Echoes back")
        public String echo() {
            return "ok";
        }
    }

    private static ToolUseBlock call(String id) {
        return ToolUseBlock.builder()
                .id(id).name("echo").input(Map.of()).content("{}").build();
    }

    @Test
    void compare() {
        Toolkit toolkit = new Toolkit();
        toolkit.registerTool(new EchoTools());

        ToolResultBlock viaCallTool = toolkit
                .callTool(ToolCallParam.builder().toolUseBlock(call("call-single")).build())
                .block();

        List<ToolResultBlock> viaCallTools =
                toolkit.callTools(List.of(call("call-batch")), null, null, null).block();
        ToolResultBlock batch = viaCallTools.get(0);

        System.out.println("REPRO callTool  id=" + viaCallTool.getId()
                + " name=" + viaCallTool.getName() + " state=" + viaCallTool.getState());
        System.out.println("REPRO callTools id=" + batch.getId()
                + " name=" + batch.getName() + " state=" + batch.getState());
    }
}
  1. Run it from the repository root:
mvn -pl agentscope-core test -Dtest=CallToolIdNameReproTest -Dsurefire.failIfNoSpecifiedTests=false

Expected behavior

Both entry points stamp the result identically:

REPRO callTool  id=call-single name=echo state=RUNNING
REPRO callTools id=call-batch  name=echo state=RUNNING

Error messages

No exception is thrown. Actual output on main at c5db8f72:

REPRO callTool  id=null name=null state=RUNNING
REPRO callTools id=call-batch name=echo state=RUNNING

Environment (please complete the following information):

  • AgentScope-Java Version: 2.0.3-SNAPSHOT (reproduced on main at commit c5db8f72)
  • Java Version: 25 (the issue is version-independent)
  • OS: macOS (the issue is OS-independent)

Additional context

The stale javadoc on ToolExecutor.execute(...) suggests how the paths drifted apart — it still reads:

/**
 * Execute a single tool call with full infrastructure support.
 */
Mono<ToolResultBlock> execute(ToolCallParam param) {

but execute(...) is the method that applies none of it; executeWithInfrastructure(...) is where the infrastructure lives, and it is private. This looks like an incomplete extraction: executeAll(...) was repointed at the new wrapper and Toolkit.callTool(...) was left on the inner method.

Beyond the missing id/name, the same divergence means the callTool path also skips applyScheduling, applyTimeout, applyRetry and applyShutdownGuard. The practical consequences are that a configured ExecutionConfig timeout and retry policy are silently inert for direct calls, and a tool invoked this way is not covered by the graceful-shutdown guard. I have kept this report scoped to the id/name defect because it is unambiguous and independently verifiable; the retry behaviour overlaps with #2829, whose author notes they are preparing a fix in this area.

Two notes for whoever picks this up:

  • If the intended contract is that Toolkit.callTool(...) is a deliberately thin, infrastructure-free entry point, then the id/name stamping and the execute(...) javadoc should still be corrected, and the difference documented on Toolkit.callTool(...) so callers are not surprised.
  • Repointing Toolkit.callTool(...) at executeWithInfrastructure(...) would fix all of the above at once, but it is an observable behaviour change for external callers currently relying on the no-timeout semantics, so it likely belongs in a minor release rather than a patch.

Nothing in the repository calls Toolkit.callTool(...) today — the only occurrences are the usage examples in its own javadoc — so the exposure is entirely to external users following the documented example.

Activity

  1. oss-maintainer commented on Sep 12, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Confirmed

    Verified against main @ 7399ed61.

    Root cause: the two public entry points in Toolkit do not share the stage that stamps id/name.

    • agentscope-core/src/main/java/io/agentscope/core/tool/Toolkit.java:490-492 — callTool(ToolCallParam) delegates straight to ToolExecutor.execute(param).
    • Toolkit.java:511-525 → ToolExecutor.java:323-324,340-341 — callTools(...) goes through executeAll(...), which routes each call through executeWithInfrastructure(...).
    • agentscope-core/src/main/java/io/agentscope/core/tool/ToolExecutor.java:398 — withIdAndName(toolCall.getId(), toolCall.getName()) is applied only inside executeWithInfrastructure(...); the execute()/executeCore() path (lines 167-291) never stamps the block.
    • ToolExecutor.java:391-394 — applyScheduling, applyTimeout, applyRetry, applyShutdownGuard live in the same wrapper, so the callTool path skips them too: a configured ExecutionConfig timeout/retry is silently inert and the call is outside the graceful-shutdown guard.
    • ToolExecutor.java:162 — the stale javadoc ("Execute a single tool call with full infrastructure support") confirms the extraction was left half-done, as the report suggests.

    Your analysis of the divergence is accurate, including that ReActAgent uses callTools(...) (ReActAgent.java:3453,3467), so nothing in-tree hits the broken path today.

    Impact: latent — zero in-repo callers, but external users following the javadoc example on Toolkit.callTool(...) get a ToolResultBlock they cannot correlate back to the tool call, since ToolResultMessageBuilder.buildToolResultMsg(...) and tool-call pairing key off id/name. Severity: medium (low while latent, high once the documented API is adopted).

    One decision needed before a fix is proposed — which contract is intended?

    1. callTool(...) is a full-featured entry point: repoint it at executeWithInfrastructure(...). This fixes id/name, timeout, retry and shutdown guard in one change, but it is an observable behaviour change for callers that currently get no-timeout semantics.
    2. callTool(...) stays deliberately thin: stamp id/name on the execute(...) path only, correct the ToolExecutor.execute(...) javadoc, and document the infrastructure gap on Toolkit.callTool(...).

    We would rather not pick for you: option 1 may belong in a minor release rather than a patch, and option 2 leaves the timeout/retry surprise in place. Retrying on tool failure is deliberately out of scope here since it overlaps #2829.

    Please reply with the intended option (or needs-discussion) and we will generate a fix proposal accordingly.


    Automated evaluation by github-manager-bot

  2. added
    bug
    area/core/tool
    on Sep 12, 2026
  3. anirbandas18 commented on Sep 13, 2026

    @anirbandas18
    Author

    needs-discussion

  4. KIM406-CMD commented on Sep 24, 2026

    @KIM406-CMD
    Contributor

    needs-discussion

    Quick update: after discussion in #3130, the intended approach is the minimal fix first — the single-call path will preserve id/name on the returned ToolResultBlock, keeping the public callTool error contract unchanged. The full-infrastructure routing will follow in a separate PR. This issue will close automatically once #3130 merges.

  5. aiyili commented on Oct 21, 2026

    @aiyili
    Contributor

    Hi, I'd like to work on this. The evaluation pins the root cause: Toolkit.callTool(ToolCallParam) bypasses executeWithInfrastructure, so id/name are never stamped. Plan: route the single-call path through the same stamping stage (or stamp at the ToolExecutor.execute boundary), keeping infrastructure behavior identical between the two entry points, plus a regression test asserting callTool returns a block with non-null id/name matching the call. PR coming shortly.

  6. KIM406-CMD commented on Oct 21, 2026

    @KIM406-CMD
    Contributor

    @aiyili Hi @aiyili, thanks for offering to take this on.
    I already opened PR #3130 for this issue: #3130
    It follows the same approach you outlined — routing the single-call path through executeWithInfrastructure so id/name are populated consistently, plus regression tests asserting callTool returns a block with non-null id/name matching the call.
    The PR is linked with Closes #3114, and I'm currently resolving the remaining merge conflict in ToolkitTest.java. Would you be open to collaborating by reviewing #3130 or suggesting changes there? That way we can avoid duplicate PRs. Happy to incorporate your feedback.

  7. added a commit that references this issue on Oct 22, 2026
    31734f2
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/toolbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions