Skip to content

Commit 89313d8

Browse files
authored
Fix empty list condition check (#1192)
Adds `isNotEmpty` condition to ensure lists are non-empty before call condition ## Motivation and Context fix `onMultipleToolResults` and `onMultipleAssistantMessages` ## Breaking Changes None --- #### Type of the changes - [ ] New feature (non-breaking change which adds functionality) - [x] Bug fix (non-breaking change which fixes an issue) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Tests improvement - [ ] Refactoring #### Checklist - [x] The pull request has a description of the proposed change - [x] I read the [Contributing Guidelines](https://github.com/JetBrains/koog/blob/main/CONTRIBUTING.md) before opening the pull request - [x] The pull request uses **`develop`** as the base branch - [ ] Tests for the changes have been added - [x] All new and existing tests passed
1 parent 3d1fd3d commit 89313d8

File tree

1 file changed

+3
-1
lines changed
  • agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/dsl/extension

1 file changed

+3
-1
lines changed

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/dsl/extension/AIAgentEdges.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public infix fun <IncomingOutput, OutgoingInput> AIAgentEdgeBuilderIntermediate<
162162
return onIsInstance(List::class)
163163
.transformed { it.filterIsInstance<Message.Tool.Call>() }
164164
// skipping this edge in case we have list of only assistant messages
165-
.onCondition { it.any() }
165+
.onCondition { it.isNotEmpty() }
166166
.onCondition { toolCalls -> block(toolCalls) }
167167
}
168168

@@ -178,6 +178,7 @@ public infix fun <IncomingOutput, IntermediateOutput, OutgoingInput> AIAgentEdge
178178
): AIAgentEdgeBuilderIntermediate<IncomingOutput, List<ReceivedToolResult>, OutgoingInput> {
179179
return onIsInstance(List::class)
180180
.transformed { it.filterIsInstance<ReceivedToolResult>() }
181+
.onCondition { it.isNotEmpty() }
181182
.onCondition { toolResults -> block(toolResults) }
182183
}
183184

@@ -206,6 +207,7 @@ public infix fun <IncomingOutput, OutgoingInput> AIAgentEdgeBuilderIntermediate<
206207
): AIAgentEdgeBuilderIntermediate<IncomingOutput, List<Message.Assistant>, OutgoingInput> {
207208
return onIsInstance(List::class)
208209
.transformed { it.filterIsInstance<Message.Assistant>() }
210+
.onCondition { it.isNotEmpty() }
209211
.onCondition { toolResults -> block(toolResults) }
210212
}
211213

0 commit comments

Comments
 (0)