Package com.tnsai.agents.execution
Class ToolCallBatchPartitioner
java.lang.Object
com.tnsai.agents.execution.ToolCallBatchPartitioner
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
- A call is parallel-safe iff its
ToolCallBatchPartitioner.ToolCallClassifierreports 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. - 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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceStrategy interface: callers implement to connect their Tool/ActionMetadata lookup with the partitioner. -
Field Summary
FieldsModifier and TypeFieldDescriptionStandard keys the default path extractor scans. -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionpartition(List<ChatResponse.ToolCall> calls) Partitionscallsinto ordered parallel groups.
-
Field Details
-
DEFAULT_PATH_KEYS
Standard keys the default path extractor scans.
-
-
Constructor Details
-
ToolCallBatchPartitioner
-
-
Method Details
-
partition
Partitionscallsinto 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
-