mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-20 10:03:16 +00:00
fix(core): preserve ToolMessage.status
field in convert_to_messages
(#32840)
This commit is contained in:
@@ -286,6 +286,9 @@ def _create_message_from_message_type(
|
|||||||
message = FunctionMessage(content=content, **kwargs)
|
message = FunctionMessage(content=content, **kwargs)
|
||||||
elif message_type == "tool":
|
elif message_type == "tool":
|
||||||
artifact = kwargs.get("additional_kwargs", {}).pop("artifact", None)
|
artifact = kwargs.get("additional_kwargs", {}).pop("artifact", None)
|
||||||
|
status = kwargs.get("additional_kwargs", {}).pop("status", None)
|
||||||
|
if status is not None:
|
||||||
|
kwargs["status"] = status
|
||||||
message = ToolMessage(content=content, artifact=artifact, **kwargs)
|
message = ToolMessage(content=content, artifact=artifact, **kwargs)
|
||||||
elif message_type == "remove":
|
elif message_type == "remove":
|
||||||
message = RemoveMessage(**kwargs)
|
message = RemoveMessage(**kwargs)
|
||||||
|
@@ -740,6 +740,7 @@ def test_convert_to_messages() -> None:
|
|||||||
"tool_call_id": "tool_id2",
|
"tool_call_id": "tool_id2",
|
||||||
"content": "Bye!",
|
"content": "Bye!",
|
||||||
"artifact": {"foo": 123},
|
"artifact": {"foo": 123},
|
||||||
|
"status": "success",
|
||||||
},
|
},
|
||||||
{"role": "remove", "id": "message_to_remove", "content": ""},
|
{"role": "remove", "id": "message_to_remove", "content": ""},
|
||||||
{
|
{
|
||||||
@@ -773,7 +774,12 @@ def test_convert_to_messages() -> None:
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
ToolMessage(tool_call_id="tool_id", content="Hi!"),
|
ToolMessage(tool_call_id="tool_id", content="Hi!"),
|
||||||
ToolMessage(tool_call_id="tool_id2", content="Bye!", artifact={"foo": 123}),
|
ToolMessage(
|
||||||
|
tool_call_id="tool_id2",
|
||||||
|
content="Bye!",
|
||||||
|
artifact={"foo": 123},
|
||||||
|
status="success",
|
||||||
|
),
|
||||||
RemoveMessage(id="message_to_remove"),
|
RemoveMessage(id="message_to_remove"),
|
||||||
HumanMessage(
|
HumanMessage(
|
||||||
content="Now the turn for Larry to ask a question about the book!",
|
content="Now the turn for Larry to ask a question about the book!",
|
||||||
|
Reference in New Issue
Block a user