diff --git a/libs/aws/langchain_aws/chat_models/bedrock_converse.py b/libs/aws/langchain_aws/chat_models/bedrock_converse.py index 4bbe4b23..7982438e 100644 --- a/libs/aws/langchain_aws/chat_models/bedrock_converse.py +++ b/libs/aws/langchain_aws/chat_models/bedrock_converse.py @@ -525,6 +525,12 @@ def bind_tools( tool_choice: Optional[Union[dict, str, Literal["auto", "any"]]] = None, **kwargs: Any, ) -> Runnable[LanguageModelInput, BaseMessage]: + try: + formatted_tools: list[dict] = [ + convert_to_openai_tool(tool) for tool in tools + ] + except Exception: + formatted_tools = _format_tools(tools) if tool_choice: tool_choice = _format_tool_choice(tool_choice) tool_choice_type = list(tool_choice.keys())[0] @@ -546,7 +552,7 @@ def bind_tools( f"for the latest documentation on models that support tool choice." ) kwargs["tool_choice"] = _format_tool_choice(tool_choice) - return self.bind(tools=_format_tools(tools), **kwargs) + return self.bind(tools=formatted_tools, **kwargs) def with_structured_output( self, @@ -922,7 +928,7 @@ def _format_tools( if isinstance(tool, dict) and "toolSpec" in tool: formatted_tools.append(tool) else: - spec = convert_to_openai_function(tool) + spec = convert_to_openai_tool(tool)["function"] spec["inputSchema"] = {"json": spec.pop("parameters")} formatted_tools.append({"toolSpec": spec}) return formatted_tools