Class ToolCallBatchPartitioner

java.lang.Object
com.tnsai.agents.execution.ToolCallBatchPartitioner

public final class ToolCallBatchPartitioner extends Object
Splits a batch of ChatResponse.ToolCalls into ordered execution groups.

Each returned group may be executed in parallel; groups themselves must be executed serially in order. Call ordering inside and across groups is preserved — group i+1 observes all side effects of group i.

Classification per call

  1. A call is parallel-safe iff its ToolCallBatchPartitioner.ToolCallClassifier reports the underlying tool as idempotent, parallelizable, not requires-confirmation, AND the call's path set is disjoint from every already-in-flight call in the current group.
  2. Unsafe calls (or safe calls that overlap on a path) break the group — they land alone in a new group so prior writes have drained first.

Path overlap

The partitioner asks the classifier for the paths each call reads or writes (filesystem paths, URLs, resource identifiers). Two calls that mention the same path cannot be safely parallelised when either writes — even read + write on the same path is serialised because the read would race the write.

Default path extraction looks for common argument keys: path, file, filePath, filename, url, uri, resource.

Thread safety

Partitioner instances are stateless w.r.t. member fields and safe to share. ToolCallBatchPartitioner.ToolCallClassifier implementations must be thread-safe if shared.
Since:
0.3.0
  • Field Details

    • DEFAULT_PATH_KEYS

      public static final Set<String> DEFAULT_PATH_KEYS
      Standard keys the default path extractor scans.
  • Constructor Details

  • Method Details

    • partition

      Partitions calls into ordered parallel groups.

      Empty input returns an empty list. A single call returns a single one-element group.

      Parameters:
      calls - the batch as the LLM produced it
      Returns:
      list of groups; groups run serially, each inner list runs in parallel