Skip to content

Commit 29478c3

Browse files
committed
Fixes a problem where formatted tools would break
It seems like the first time we are calling _format_tools everything works fine, but on a second run, the _snake_case_to_camel_case converts the input parameters to camelCase and breaks the tools.
1 parent 73edd60 commit 29478c3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

libs/aws/langchain_aws/chat_models/bedrock_converse.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ class ChatBedrockConverse(BaseChatModel):
106106
config: Any = None
107107
"""An optional botocore.config.Config instance to pass to the client."""
108108

109+
formatted_tools: List[
110+
Dict[Literal["toolSpec"], Dict[str, Union[Dict[str, Any], str]]]
111+
] = Field(default_factory=list, exclude=True)
112+
""""Formatted tools to be stored and used in the toolConfig parameter."""
113+
109114
class Config:
110115
"""Configuration for this pydantic object."""
111116

@@ -203,7 +208,8 @@ def bind_tools(
203208
) -> Runnable[LanguageModelInput, BaseMessage]:
204209
if tool_choice:
205210
kwargs["tool_choice"] = _format_tool_choice(tool_choice)
206-
return self.bind(tools=_format_tools(tools), **kwargs)
211+
self.formatted_tools = _format_tools(tools)
212+
return self.bind(tools=self.formatted_tools, **kwargs)
207213

208214
def with_structured_output(
209215
self,
@@ -257,7 +263,7 @@ def _converse_params(
257263
}
258264
if not toolConfig and tools:
259265
toolChoice = _format_tool_choice(toolChoice) if toolChoice else None
260-
toolConfig = {"tools": _format_tools(tools), "toolChoice": toolChoice}
266+
toolConfig = {"tools": self.formatted_tools, "toolChoice": toolChoice}
261267
return _drop_none(
262268
{
263269
"modelId": modelId or self.model_id,

0 commit comments

Comments
 (0)