mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-08 14:31:55 +00:00
core[minor]: rename ToolMessage.raw_output -> artifact (#24185)
This commit is contained in:
@@ -457,8 +457,11 @@
|
||||
|
||||
ToolMessage(content='42', tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL')
|
||||
|
||||
|
||||
Example: A ToolMessage where only part of the tool output is sent to the model
|
||||
and the full output is passed in to raw_output.
|
||||
and the full output is passed in to artifact.
|
||||
|
||||
.. versionadded:: 0.2.17
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -472,7 +475,7 @@
|
||||
|
||||
ToolMessage(
|
||||
content=tool_output["stdout"],
|
||||
raw_output=tool_output,
|
||||
artifact=tool_output,
|
||||
tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL',
|
||||
)
|
||||
|
||||
@@ -485,6 +488,9 @@
|
||||
'title': 'Additional Kwargs',
|
||||
'type': 'object',
|
||||
}),
|
||||
'artifact': dict({
|
||||
'title': 'Artifact',
|
||||
}),
|
||||
'content': dict({
|
||||
'anyOf': list([
|
||||
dict({
|
||||
@@ -514,9 +520,6 @@
|
||||
'title': 'Name',
|
||||
'type': 'string',
|
||||
}),
|
||||
'raw_output': dict({
|
||||
'title': 'Raw Output',
|
||||
}),
|
||||
'response_metadata': dict({
|
||||
'title': 'Response Metadata',
|
||||
'type': 'object',
|
||||
@@ -1062,8 +1065,11 @@
|
||||
|
||||
ToolMessage(content='42', tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL')
|
||||
|
||||
|
||||
Example: A ToolMessage where only part of the tool output is sent to the model
|
||||
and the full output is passed in to raw_output.
|
||||
and the full output is passed in to artifact.
|
||||
|
||||
.. versionadded:: 0.2.17
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -1077,7 +1083,7 @@
|
||||
|
||||
ToolMessage(
|
||||
content=tool_output["stdout"],
|
||||
raw_output=tool_output,
|
||||
artifact=tool_output,
|
||||
tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL',
|
||||
)
|
||||
|
||||
@@ -1090,6 +1096,9 @@
|
||||
'title': 'Additional Kwargs',
|
||||
'type': 'object',
|
||||
}),
|
||||
'artifact': dict({
|
||||
'title': 'Artifact',
|
||||
}),
|
||||
'content': dict({
|
||||
'anyOf': list([
|
||||
dict({
|
||||
@@ -1119,9 +1128,6 @@
|
||||
'title': 'Name',
|
||||
'type': 'string',
|
||||
}),
|
||||
'raw_output': dict({
|
||||
'title': 'Raw Output',
|
||||
}),
|
||||
'response_metadata': dict({
|
||||
'title': 'Response Metadata',
|
||||
'type': 'object',
|
||||
|
@@ -813,8 +813,11 @@
|
||||
|
||||
ToolMessage(content='42', tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL')
|
||||
|
||||
|
||||
Example: A ToolMessage where only part of the tool output is sent to the model
|
||||
and the full output is passed in to raw_output.
|
||||
and the full output is passed in to artifact.
|
||||
|
||||
.. versionadded:: 0.2.17
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -828,7 +831,7 @@
|
||||
|
||||
ToolMessage(
|
||||
content=tool_output["stdout"],
|
||||
raw_output=tool_output,
|
||||
artifact=tool_output,
|
||||
tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL',
|
||||
)
|
||||
|
||||
@@ -841,6 +844,9 @@
|
||||
'title': 'Additional Kwargs',
|
||||
'type': 'object',
|
||||
}),
|
||||
'artifact': dict({
|
||||
'title': 'Artifact',
|
||||
}),
|
||||
'content': dict({
|
||||
'anyOf': list([
|
||||
dict({
|
||||
@@ -870,9 +876,6 @@
|
||||
'title': 'Name',
|
||||
'type': 'string',
|
||||
}),
|
||||
'raw_output': dict({
|
||||
'title': 'Raw Output',
|
||||
}),
|
||||
'response_metadata': dict({
|
||||
'title': 'Response Metadata',
|
||||
'type': 'object',
|
||||
|
@@ -5739,8 +5739,11 @@
|
||||
|
||||
ToolMessage(content='42', tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL')
|
||||
|
||||
|
||||
Example: A ToolMessage where only part of the tool output is sent to the model
|
||||
and the full output is passed in to raw_output.
|
||||
and the full output is passed in to artifact.
|
||||
|
||||
.. versionadded:: 0.2.17
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -5754,7 +5757,7 @@
|
||||
|
||||
ToolMessage(
|
||||
content=tool_output["stdout"],
|
||||
raw_output=tool_output,
|
||||
artifact=tool_output,
|
||||
tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL',
|
||||
)
|
||||
|
||||
@@ -5767,6 +5770,9 @@
|
||||
'title': 'Additional Kwargs',
|
||||
'type': 'object',
|
||||
}),
|
||||
'artifact': dict({
|
||||
'title': 'Artifact',
|
||||
}),
|
||||
'content': dict({
|
||||
'anyOf': list([
|
||||
dict({
|
||||
@@ -5796,9 +5802,6 @@
|
||||
'title': 'Name',
|
||||
'type': 'string',
|
||||
}),
|
||||
'raw_output': dict({
|
||||
'title': 'Raw Output',
|
||||
}),
|
||||
'response_metadata': dict({
|
||||
'title': 'Response Metadata',
|
||||
'type': 'object',
|
||||
@@ -6413,8 +6416,11 @@
|
||||
|
||||
ToolMessage(content='42', tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL')
|
||||
|
||||
|
||||
Example: A ToolMessage where only part of the tool output is sent to the model
|
||||
and the full output is passed in to raw_output.
|
||||
and the full output is passed in to artifact.
|
||||
|
||||
.. versionadded:: 0.2.17
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -6428,7 +6434,7 @@
|
||||
|
||||
ToolMessage(
|
||||
content=tool_output["stdout"],
|
||||
raw_output=tool_output,
|
||||
artifact=tool_output,
|
||||
tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL',
|
||||
)
|
||||
|
||||
@@ -6441,6 +6447,9 @@
|
||||
'title': 'Additional Kwargs',
|
||||
'type': 'object',
|
||||
}),
|
||||
'artifact': dict({
|
||||
'title': 'Artifact',
|
||||
}),
|
||||
'content': dict({
|
||||
'anyOf': list([
|
||||
dict({
|
||||
@@ -6470,9 +6479,6 @@
|
||||
'title': 'Name',
|
||||
'type': 'string',
|
||||
}),
|
||||
'raw_output': dict({
|
||||
'title': 'Raw Output',
|
||||
}),
|
||||
'response_metadata': dict({
|
||||
'title': 'Response Metadata',
|
||||
'type': 'object',
|
||||
@@ -7002,8 +7008,11 @@
|
||||
|
||||
ToolMessage(content='42', tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL')
|
||||
|
||||
|
||||
Example: A ToolMessage where only part of the tool output is sent to the model
|
||||
and the full output is passed in to raw_output.
|
||||
and the full output is passed in to artifact.
|
||||
|
||||
.. versionadded:: 0.2.17
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -7017,7 +7026,7 @@
|
||||
|
||||
ToolMessage(
|
||||
content=tool_output["stdout"],
|
||||
raw_output=tool_output,
|
||||
artifact=tool_output,
|
||||
tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL',
|
||||
)
|
||||
|
||||
@@ -7030,6 +7039,9 @@
|
||||
'title': 'Additional Kwargs',
|
||||
'type': 'object',
|
||||
}),
|
||||
'artifact': dict({
|
||||
'title': 'Artifact',
|
||||
}),
|
||||
'content': dict({
|
||||
'anyOf': list([
|
||||
dict({
|
||||
@@ -7059,9 +7071,6 @@
|
||||
'title': 'Name',
|
||||
'type': 'string',
|
||||
}),
|
||||
'raw_output': dict({
|
||||
'title': 'Raw Output',
|
||||
}),
|
||||
'response_metadata': dict({
|
||||
'title': 'Response Metadata',
|
||||
'type': 'object',
|
||||
@@ -7648,8 +7657,11 @@
|
||||
|
||||
ToolMessage(content='42', tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL')
|
||||
|
||||
|
||||
Example: A ToolMessage where only part of the tool output is sent to the model
|
||||
and the full output is passed in to raw_output.
|
||||
and the full output is passed in to artifact.
|
||||
|
||||
.. versionadded:: 0.2.17
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -7663,7 +7675,7 @@
|
||||
|
||||
ToolMessage(
|
||||
content=tool_output["stdout"],
|
||||
raw_output=tool_output,
|
||||
artifact=tool_output,
|
||||
tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL',
|
||||
)
|
||||
|
||||
@@ -7676,6 +7688,9 @@
|
||||
'title': 'Additional Kwargs',
|
||||
'type': 'object',
|
||||
}),
|
||||
'artifact': dict({
|
||||
'title': 'Artifact',
|
||||
}),
|
||||
'content': dict({
|
||||
'anyOf': list([
|
||||
dict({
|
||||
@@ -7705,9 +7720,6 @@
|
||||
'title': 'Name',
|
||||
'type': 'string',
|
||||
}),
|
||||
'raw_output': dict({
|
||||
'title': 'Raw Output',
|
||||
}),
|
||||
'response_metadata': dict({
|
||||
'title': 'Response Metadata',
|
||||
'type': 'object',
|
||||
@@ -8297,8 +8309,11 @@
|
||||
|
||||
ToolMessage(content='42', tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL')
|
||||
|
||||
|
||||
Example: A ToolMessage where only part of the tool output is sent to the model
|
||||
and the full output is passed in to raw_output.
|
||||
and the full output is passed in to artifact.
|
||||
|
||||
.. versionadded:: 0.2.17
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -8312,7 +8327,7 @@
|
||||
|
||||
ToolMessage(
|
||||
content=tool_output["stdout"],
|
||||
raw_output=tool_output,
|
||||
artifact=tool_output,
|
||||
tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL',
|
||||
)
|
||||
|
||||
@@ -8325,6 +8340,9 @@
|
||||
'title': 'Additional Kwargs',
|
||||
'type': 'object',
|
||||
}),
|
||||
'artifact': dict({
|
||||
'title': 'Artifact',
|
||||
}),
|
||||
'content': dict({
|
||||
'anyOf': list([
|
||||
dict({
|
||||
@@ -8354,9 +8372,6 @@
|
||||
'title': 'Name',
|
||||
'type': 'string',
|
||||
}),
|
||||
'raw_output': dict({
|
||||
'title': 'Raw Output',
|
||||
}),
|
||||
'response_metadata': dict({
|
||||
'title': 'Response Metadata',
|
||||
'type': 'object',
|
||||
@@ -8893,8 +8908,11 @@
|
||||
|
||||
ToolMessage(content='42', tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL')
|
||||
|
||||
|
||||
Example: A ToolMessage where only part of the tool output is sent to the model
|
||||
and the full output is passed in to raw_output.
|
||||
and the full output is passed in to artifact.
|
||||
|
||||
.. versionadded:: 0.2.17
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -8908,7 +8926,7 @@
|
||||
|
||||
ToolMessage(
|
||||
content=tool_output["stdout"],
|
||||
raw_output=tool_output,
|
||||
artifact=tool_output,
|
||||
tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL',
|
||||
)
|
||||
|
||||
@@ -8921,6 +8939,9 @@
|
||||
'title': 'Additional Kwargs',
|
||||
'type': 'object',
|
||||
}),
|
||||
'artifact': dict({
|
||||
'title': 'Artifact',
|
||||
}),
|
||||
'content': dict({
|
||||
'anyOf': list([
|
||||
dict({
|
||||
@@ -8950,9 +8971,6 @@
|
||||
'title': 'Name',
|
||||
'type': 'string',
|
||||
}),
|
||||
'raw_output': dict({
|
||||
'title': 'Raw Output',
|
||||
}),
|
||||
'response_metadata': dict({
|
||||
'title': 'Response Metadata',
|
||||
'type': 'object',
|
||||
@@ -9462,8 +9480,11 @@
|
||||
|
||||
ToolMessage(content='42', tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL')
|
||||
|
||||
|
||||
Example: A ToolMessage where only part of the tool output is sent to the model
|
||||
and the full output is passed in to raw_output.
|
||||
and the full output is passed in to artifact.
|
||||
|
||||
.. versionadded:: 0.2.17
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -9477,7 +9498,7 @@
|
||||
|
||||
ToolMessage(
|
||||
content=tool_output["stdout"],
|
||||
raw_output=tool_output,
|
||||
artifact=tool_output,
|
||||
tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL',
|
||||
)
|
||||
|
||||
@@ -9490,6 +9511,9 @@
|
||||
'title': 'Additional Kwargs',
|
||||
'type': 'object',
|
||||
}),
|
||||
'artifact': dict({
|
||||
'title': 'Artifact',
|
||||
}),
|
||||
'content': dict({
|
||||
'anyOf': list([
|
||||
dict({
|
||||
@@ -9519,9 +9543,6 @@
|
||||
'title': 'Name',
|
||||
'type': 'string',
|
||||
}),
|
||||
'raw_output': dict({
|
||||
'title': 'Raw Output',
|
||||
}),
|
||||
'response_metadata': dict({
|
||||
'title': 'Response Metadata',
|
||||
'type': 'object',
|
||||
@@ -10140,8 +10161,11 @@
|
||||
|
||||
ToolMessage(content='42', tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL')
|
||||
|
||||
|
||||
Example: A ToolMessage where only part of the tool output is sent to the model
|
||||
and the full output is passed in to raw_output.
|
||||
and the full output is passed in to artifact.
|
||||
|
||||
.. versionadded:: 0.2.17
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -10155,7 +10179,7 @@
|
||||
|
||||
ToolMessage(
|
||||
content=tool_output["stdout"],
|
||||
raw_output=tool_output,
|
||||
artifact=tool_output,
|
||||
tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL',
|
||||
)
|
||||
|
||||
@@ -10168,6 +10192,9 @@
|
||||
'title': 'Additional Kwargs',
|
||||
'type': 'object',
|
||||
}),
|
||||
'artifact': dict({
|
||||
'title': 'Artifact',
|
||||
}),
|
||||
'content': dict({
|
||||
'anyOf': list([
|
||||
dict({
|
||||
@@ -10197,9 +10224,6 @@
|
||||
'title': 'Name',
|
||||
'type': 'string',
|
||||
}),
|
||||
'raw_output': dict({
|
||||
'title': 'Raw Output',
|
||||
}),
|
||||
'response_metadata': dict({
|
||||
'title': 'Response Metadata',
|
||||
'type': 'object',
|
||||
|
@@ -662,7 +662,7 @@ def test_convert_to_messages() -> None:
|
||||
"role": "tool",
|
||||
"tool_call_id": "tool_id2",
|
||||
"content": "Bye!",
|
||||
"raw_output": {"foo": 123},
|
||||
"artifact": {"foo": 123},
|
||||
},
|
||||
{"role": "remove", "id": "message_to_remove", "content": ""},
|
||||
]
|
||||
@@ -685,7 +685,7 @@ def test_convert_to_messages() -> None:
|
||||
tool_calls=[ToolCall(name="greet", args={"name": "Jane"}, id="tool_id")],
|
||||
),
|
||||
ToolMessage(tool_call_id="tool_id", content="Hi!"),
|
||||
ToolMessage(tool_call_id="tool_id2", content="Bye!", raw_output={"foo": 123}),
|
||||
ToolMessage(tool_call_id="tool_id2", content="Bye!", artifact={"foo": 123}),
|
||||
RemoveMessage(id="message_to_remove"),
|
||||
]
|
||||
assert expected == actual
|
||||
@@ -787,7 +787,7 @@ def test_merge_tool_calls() -> None:
|
||||
|
||||
|
||||
def test_tool_message_serdes() -> None:
|
||||
message = ToolMessage("foo", raw_output={"bar": {"baz": 123}}, tool_call_id="1")
|
||||
message = ToolMessage("foo", artifact={"bar": {"baz": 123}}, tool_call_id="1")
|
||||
ser_message = {
|
||||
"lc": 1,
|
||||
"type": "constructor",
|
||||
@@ -796,7 +796,7 @@ def test_tool_message_serdes() -> None:
|
||||
"content": "foo",
|
||||
"type": "tool",
|
||||
"tool_call_id": "1",
|
||||
"raw_output": {"bar": {"baz": 123}},
|
||||
"artifact": {"bar": {"baz": 123}},
|
||||
},
|
||||
}
|
||||
assert dumpd(message) == ser_message
|
||||
@@ -809,7 +809,7 @@ class BadObject:
|
||||
|
||||
def test_tool_message_ser_non_serializable() -> None:
|
||||
bad_obj = BadObject()
|
||||
message = ToolMessage("foo", raw_output=bad_obj, tool_call_id="1")
|
||||
message = ToolMessage("foo", artifact=bad_obj, tool_call_id="1")
|
||||
ser_message = {
|
||||
"lc": 1,
|
||||
"type": "constructor",
|
||||
@@ -818,7 +818,7 @@ def test_tool_message_ser_non_serializable() -> None:
|
||||
"content": "foo",
|
||||
"type": "tool",
|
||||
"tool_call_id": "1",
|
||||
"raw_output": {
|
||||
"artifact": {
|
||||
"lc": 1,
|
||||
"type": "not_implemented",
|
||||
"id": ["tests", "unit_tests", "test_messages", "BadObject"],
|
||||
@@ -832,14 +832,14 @@ def test_tool_message_ser_non_serializable() -> None:
|
||||
|
||||
|
||||
def test_tool_message_to_dict() -> None:
|
||||
message = ToolMessage("foo", raw_output={"bar": {"baz": 123}}, tool_call_id="1")
|
||||
message = ToolMessage("foo", artifact={"bar": {"baz": 123}}, tool_call_id="1")
|
||||
expected = {
|
||||
"type": "tool",
|
||||
"data": {
|
||||
"content": "foo",
|
||||
"additional_kwargs": {},
|
||||
"response_metadata": {},
|
||||
"raw_output": {"bar": {"baz": 123}},
|
||||
"artifact": {"bar": {"baz": 123}},
|
||||
"type": "tool",
|
||||
"name": None,
|
||||
"id": None,
|
||||
@@ -851,16 +851,16 @@ def test_tool_message_to_dict() -> None:
|
||||
|
||||
|
||||
def test_tool_message_repr() -> None:
|
||||
message = ToolMessage("foo", raw_output={"bar": {"baz": 123}}, tool_call_id="1")
|
||||
message = ToolMessage("foo", artifact={"bar": {"baz": 123}}, tool_call_id="1")
|
||||
expected = (
|
||||
"ToolMessage(content='foo', tool_call_id='1', raw_output={'bar': {'baz': 123}})"
|
||||
"ToolMessage(content='foo', tool_call_id='1', artifact={'bar': {'baz': 123}})"
|
||||
)
|
||||
actual = repr(message)
|
||||
assert expected == actual
|
||||
|
||||
|
||||
def test_tool_message_str() -> None:
|
||||
message = ToolMessage("foo", raw_output={"bar": {"baz": 123}}, tool_call_id="1")
|
||||
expected = "content='foo' tool_call_id='1' raw_output={'bar': {'baz': 123}}"
|
||||
message = ToolMessage("foo", artifact={"bar": {"baz": 123}}, tool_call_id="1")
|
||||
expected = "content='foo' tool_call_id='1' artifact={'bar': {'baz': 123}}"
|
||||
actual = str(message)
|
||||
assert expected == actual
|
||||
|
@@ -1150,7 +1150,7 @@ class _MockStructuredToolWithRawOutput(BaseTool):
|
||||
name: str = "structured_api"
|
||||
args_schema: Type[BaseModel] = _MockSchema
|
||||
description: str = "A Structured Tool"
|
||||
response_format: Literal["content_and_raw_output"] = "content_and_raw_output"
|
||||
response_format: Literal["content_and_artifact"] = "content_and_artifact"
|
||||
|
||||
def _run(
|
||||
self, arg1: int, arg2: bool, arg3: Optional[dict] = None
|
||||
@@ -1158,8 +1158,8 @@ class _MockStructuredToolWithRawOutput(BaseTool):
|
||||
return f"{arg1} {arg2}", {"arg1": arg1, "arg2": arg2, "arg3": arg3}
|
||||
|
||||
|
||||
@tool("structured_api", response_format="content_and_raw_output")
|
||||
def _mock_structured_tool_with_raw_output(
|
||||
@tool("structured_api", response_format="content_and_artifact")
|
||||
def _mock_structured_tool_with_artifact(
|
||||
arg1: int, arg2: bool, arg3: Optional[dict] = None
|
||||
) -> Tuple[str, dict]:
|
||||
"""A Structured Tool"""
|
||||
@@ -1167,16 +1167,16 @@ def _mock_structured_tool_with_raw_output(
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tool", [_MockStructuredToolWithRawOutput(), _mock_structured_tool_with_raw_output]
|
||||
"tool", [_MockStructuredToolWithRawOutput(), _mock_structured_tool_with_artifact]
|
||||
)
|
||||
def test_tool_call_input_tool_message_with_raw_output(tool: BaseTool) -> None:
|
||||
def test_tool_call_input_tool_message_with_artifact(tool: BaseTool) -> None:
|
||||
tool_call: Dict = {
|
||||
"name": "structured_api",
|
||||
"args": {"arg1": 1, "arg2": True, "arg3": {"img": "base64string..."}},
|
||||
"id": "123",
|
||||
"type": "tool_call",
|
||||
}
|
||||
expected = ToolMessage("1 True", raw_output=tool_call["args"], tool_call_id="123")
|
||||
expected = ToolMessage("1 True", artifact=tool_call["args"], tool_call_id="123")
|
||||
actual = tool.invoke(tool_call)
|
||||
assert actual == expected
|
||||
|
||||
|
Reference in New Issue
Block a user