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:
parent
2898b95ca7
commit
161f6af9ce
@ -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
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user