Skip to content

Commit f1dbef2

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 c1eef52 commit f1dbef2

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
@@ -312,6 +312,11 @@ class Joke(BaseModel):
312312
config: Any = None
313313
"""An optional botocore.config.Config instance to pass to the client."""
314314

315+
formatted_tools: List[
316+
Dict[Literal["toolSpec"], Dict[str, Union[Dict[str, Any], str]]]
317+
] = Field(default_factory=list, exclude=True)
318+
""""Formatted tools to be stored and used in the toolConfig parameter."""
319+
315320
class Config:
316321
"""Configuration for this pydantic object."""
317322

@@ -411,7 +416,8 @@ def bind_tools(
411416
) -> Runnable[LanguageModelInput, BaseMessage]:
412417
if tool_choice:
413418
kwargs["tool_choice"] = _format_tool_choice(tool_choice)
414-
return self.bind(tools=_format_tools(tools), **kwargs)
419+
self.formatted_tools = _format_tools(tools)
420+
return self.bind(tools=self.formatted_tools, **kwargs)
415421

416422
def with_structured_output(
417423
self,
@@ -465,7 +471,7 @@ def _converse_params(
465471
}
466472
if not toolConfig and tools:
467473
toolChoice = _format_tool_choice(toolChoice) if toolChoice else None
468-
toolConfig = {"tools": _format_tools(tools), "toolChoice": toolChoice}
474+
toolConfig = {"tools": self.formatted_tools, "toolChoice": toolChoice}
469475
return _drop_none(
470476
{
471477
"modelId": modelId or self.model_id,

0 commit comments

Comments
 (0)