From 9c03af2735c240fc2d951f762c1925aec094505e Mon Sep 17 00:00:00 2001 From: Debanjum Date: Fri, 5 Dec 2025 11:52:52 -0800 Subject: [PATCH] Disable parallel tool call by anthropic models as unsupported Khoj doesn't handle parallel tool calling right now. Models were told to call tools in serial but it wasn't enforced via the Anthropic API. So if model did try make parallel tool call, next response would fail as it expects a tool result for the other tool calls. But khoj just returned the first tool calls results. This mostly affected haiku due to its lower fine-grained instruction following capabilities. This changes enforces serial tool calls at the API layer to avoid this issue altogether for claude models. --- src/khoj/processor/conversation/anthropic/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/khoj/processor/conversation/anthropic/utils.py b/src/khoj/processor/conversation/anthropic/utils.py index de3aa02f..42a8a668 100644 --- a/src/khoj/processor/conversation/anthropic/utils.py +++ b/src/khoj/processor/conversation/anthropic/utils.py @@ -85,6 +85,8 @@ def anthropic_completion_with_backoff( # Cache tool definitions last_tool = model_kwargs["tools"][-1] last_tool["cache_control"] = {"type": "ephemeral"} + # Disable parallel tool call until we add support for it + model_kwargs["tool_choice"] = {"type": "auto", "disable_parallel_tool_use": True} elif response_schema: tool = create_tool_definition(response_schema) model_kwargs["tools"] = [