Skip to content

Commit 33c0f06

Browse files
authored
feat: pass through disable_parallel_tool_use tool_choice when present (brainlid#1) (brainlid#390)
1 parent 8832cd4 commit 33c0f06

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

lib/chat_models/chat_anthropic.ex

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,24 @@ defmodule LangChain.ChatModels.ChatAnthropic do
399399
end
400400

401401
defp get_tool_choice(%ChatAnthropic{
402-
tool_choice: %{"type" => "tool", "name" => name} = _tool_choice
402+
tool_choice: %{"type" => "tool", "name" => name} = tool_choice
403403
})
404-
when is_binary(name) and byte_size(name) > 0,
405-
do: %{"type" => "tool", "name" => name}
404+
when is_binary(name) and byte_size(name) > 0 do
405+
%{"type" => "tool", "name" => name}
406+
|> Utils.conditionally_add_to_map(
407+
"disable_parallel_tool_use",
408+
Map.get(tool_choice, "disable_parallel_tool_use")
409+
)
410+
end
406411

407-
defp get_tool_choice(%ChatAnthropic{tool_choice: %{"type" => type} = _tool_choice})
408-
when is_binary(type) and byte_size(type) > 0,
409-
do: %{"type" => type}
412+
defp get_tool_choice(%ChatAnthropic{tool_choice: %{"type" => type} = tool_choice})
413+
when is_binary(type) and byte_size(type) > 0 do
414+
%{"type" => type}
415+
|> Utils.conditionally_add_to_map(
416+
"disable_parallel_tool_use",
417+
Map.get(tool_choice, "disable_parallel_tool_use")
418+
)
419+
end
410420

411421
defp get_tool_choice(%ChatAnthropic{}), do: nil
412422

test/chat_models/chat_anthropic_test.exs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,30 @@ defmodule LangChain.ChatModels.ChatAnthropicTest do
238238
assert data.tool_choice == %{"type" => "tool", "name" => "get_weather"}
239239
end
240240

241+
test "includes disable_parallel_tool_use when set in tool_choice" do
242+
{:ok, anthropic} =
243+
ChatAnthropic.new(%{
244+
model: @test_model,
245+
tool_choice: %{"type" => "auto", "disable_parallel_tool_use" => true}
246+
})
247+
248+
data = ChatAnthropic.for_api(anthropic, [], [])
249+
assert data.model == @test_model
250+
assert data.tool_choice == %{"type" => "auto", "disable_parallel_tool_use" => true}
251+
end
252+
253+
test "includes disable_parallel_tool_use with specific tool" do
254+
{:ok, anthropic} =
255+
ChatAnthropic.new(%{
256+
model: @test_model,
257+
tool_choice: %{"type" => "tool", "name" => "get_weather", "disable_parallel_tool_use" => true}
258+
})
259+
260+
data = ChatAnthropic.for_api(anthropic, [], [])
261+
assert data.model == @test_model
262+
assert data.tool_choice == %{"type" => "tool", "name" => "get_weather", "disable_parallel_tool_use" => true}
263+
end
264+
241265
test "adds tool definitions to map" do
242266
tool =
243267
Function.new!(%{

0 commit comments

Comments
 (0)