mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
anthropic[patch]: support parallel_tool_calls (#29257)
Need to: - Update docs - Decide if this is an explicit kwarg of bind_tools - Decide if this should be in standard test with flag for supporting
This commit is contained in:
@@ -819,6 +819,7 @@ class ChatAnthropic(BaseChatModel):
|
||||
tool_choice: Optional[
|
||||
Union[Dict[str, str], Literal["any", "auto"], str]
|
||||
] = None,
|
||||
parallel_tool_calls: Optional[bool] = None,
|
||||
**kwargs: Any,
|
||||
) -> Runnable[LanguageModelInput, BaseMessage]:
|
||||
r"""Bind tool-like objects to this chat model.
|
||||
@@ -832,6 +833,10 @@ class ChatAnthropic(BaseChatModel):
|
||||
- name of the tool as a string or as dict ``{"type": "tool", "name": "<<tool_name>>"}``: calls corresponding tool;
|
||||
- ``"auto"``, ``{"type: "auto"}``, or None: automatically selects a tool (including no tool);
|
||||
- ``"any"`` or ``{"type: "any"}``: force at least one tool to be called;
|
||||
parallel_tool_calls: Set to ``False`` to disable parallel tool use.
|
||||
Defaults to ``None`` (no specification, which allows parallel tool use).
|
||||
|
||||
.. versionadded:: 0.3.2
|
||||
kwargs: Any additional parameters are passed directly to
|
||||
:meth:`~langchain_anthropic.chat_models.ChatAnthropic.bind`.
|
||||
|
||||
@@ -968,6 +973,19 @@ class ChatAnthropic(BaseChatModel):
|
||||
f"Unrecognized 'tool_choice' type {tool_choice=}. Expected dict, "
|
||||
f"str, or None."
|
||||
)
|
||||
|
||||
if parallel_tool_calls is not None:
|
||||
disable_parallel_tool_use = not parallel_tool_calls
|
||||
if "tool_choice" in kwargs:
|
||||
kwargs["tool_choice"]["disable_parallel_tool_use"] = (
|
||||
disable_parallel_tool_use
|
||||
)
|
||||
else:
|
||||
kwargs["tool_choice"] = {
|
||||
"type": "any",
|
||||
"disable_parallel_tool_use": disable_parallel_tool_use,
|
||||
}
|
||||
|
||||
return self.bind(tools=formatted_tools, **kwargs)
|
||||
|
||||
def with_structured_output(
|
||||
|
||||
Reference in New Issue
Block a user