Skip to content

Commit 4456976

Browse files
authored
[agent] fix requestLLMWithoutTools to work properly across all providers (#268)
1 parent 79891cd commit 4456976

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/session/AIAgentLLMSession.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ public sealed class AIAgentLLMSession(
117117

118118
public open suspend fun requestLLMWithoutTools(): Message.Response {
119119
validateSession()
120-
val promptWithDisabledTools = prompt.withUpdatedParams {
121-
/*
122-
If tools are empty, they will not be added by the LLM client to the requests,
123-
which means tool choice parameter cannot be used (it throws an exception without a tools parameter present).
124-
So instead set it to null in this case, which behaves the same (there are no tools to call, after all).
125-
*/
126-
toolChoice = if (tools.isNotEmpty()) LLMParams.ToolChoice.None else null
127-
}
120+
/*
121+
Not all LLM providers support tool list when tool choice is set to "none", so we are rewriting all tool messages to regular messages,
122+
for all requests without tools.
123+
*/
124+
val promptWithDisabledTools = prompt
125+
.withUpdatedParams { toolChoice = null }
126+
.let { preparePrompt(it, emptyList()) }
127+
128128
return executeSingle(promptWithDisabledTools, tools)
129129
}
130130

0 commit comments

Comments
 (0)