1
0
mirror of https://github.com/hwchase17/langchain.git synced 2025-05-05 23:28:47 +00:00

[rfc] core: make tool_call_id optional

This commit is contained in:
vbarda 2024-11-12 15:04:47 -05:00
parent 2898b95ca7
commit 161f6af9ce
2 changed files with 5 additions and 2 deletions
libs/core/langchain_core
messages
tools

View File

@ -50,7 +50,7 @@ class ToolMessage(BaseMessage):
to request multiple tool calls in parallel.
""" # noqa: E501
tool_call_id: str
tool_call_id: Optional[str] = None
"""Tool call that this message is responding to."""
type: Literal["tool"] = "tool"
@ -119,7 +119,7 @@ class ToolMessage(BaseMessage):
else:
pass
tool_call_id = values["tool_call_id"]
tool_call_id = values.get("tool_call_id")
if isinstance(tool_call_id, (UUID, int, float)):
values["tool_call_id"] = str(tool_call_id)
return values

View File

@ -892,6 +892,9 @@ def _format_output(
content: Any, artifact: Any, tool_call_id: Optional[str], name: str, status: str
) -> Union[ToolMessage, Any]:
if tool_call_id:
if isinstance(content, ToolMessage):
content.tool_call_id = tool_call_id
return content
if not _is_message_content_type(content):
content = _stringify(content)
return ToolMessage(