diff --git a/libs/aws/langchain_aws/chat_models/bedrock_converse.py b/libs/aws/langchain_aws/chat_models/bedrock_converse.py index 16747e87..4c447faf 100644 --- a/libs/aws/langchain_aws/chat_models/bedrock_converse.py +++ b/libs/aws/langchain_aws/chat_models/bedrock_converse.py @@ -312,6 +312,11 @@ class Joke(BaseModel): config: Any = None """An optional botocore.config.Config instance to pass to the client.""" + formatted_tools: List[ + Dict[Literal["toolSpec"], Dict[str, Union[Dict[str, Any], str]]] + ] = Field(default_factory=list, exclude=True) + """"Formatted tools to be stored and used in the toolConfig parameter.""" + class Config: """Configuration for this pydantic object.""" @@ -411,7 +416,8 @@ def bind_tools( ) -> Runnable[LanguageModelInput, BaseMessage]: if tool_choice: kwargs["tool_choice"] = _format_tool_choice(tool_choice) - return self.bind(tools=_format_tools(tools), **kwargs) + self.formatted_tools = _format_tools(tools) + return self.bind(tools=self.formatted_tools, **kwargs) def with_structured_output( self, @@ -465,7 +471,7 @@ def _converse_params( } if not toolConfig and tools: toolChoice = _format_tool_choice(toolChoice) if toolChoice else None - toolConfig = {"tools": _format_tools(tools), "toolChoice": toolChoice} + toolConfig = {"tools": self.formatted_tools, "toolChoice": toolChoice} return _drop_none( { "modelId": modelId or self.model_id,