core[patch]: introduce ToolMessage.status (#24628)

Anthropic models (including via Bedrock and other cloud platforms)
accept a status/is_error attribute on tool messages/results
(specifically in `tool_result` content blocks for Anthropic API). Adding
a ToolMessage.status attribute so that users can set this attribute when
using those models
This commit is contained in:
Bagatur
2024-07-29 14:01:53 -07:00
committed by GitHub
parent 78d97b49d9
commit a6d1fb4275
9 changed files with 174 additions and 15 deletions

View File

@@ -524,6 +524,15 @@
'title': 'Response Metadata',
'type': 'object',
}),
'status': dict({
'default': 'success',
'enum': list([
'success',
'error',
]),
'title': 'Status',
'type': 'string',
}),
'tool_call_id': dict({
'title': 'Tool Call Id',
'type': 'string',
@@ -1132,6 +1141,15 @@
'title': 'Response Metadata',
'type': 'object',
}),
'status': dict({
'default': 'success',
'enum': list([
'success',
'error',
]),
'title': 'Status',
'type': 'string',
}),
'tool_call_id': dict({
'title': 'Tool Call Id',
'type': 'string',

View File

@@ -880,6 +880,15 @@
'title': 'Response Metadata',
'type': 'object',
}),
'status': dict({
'default': 'success',
'enum': list([
'success',
'error',
]),
'title': 'Status',
'type': 'string',
}),
'tool_call_id': dict({
'title': 'Tool Call Id',
'type': 'string',

View File

@@ -5806,6 +5806,15 @@
'title': 'Response Metadata',
'type': 'object',
}),
'status': dict({
'default': 'success',
'enum': list([
'success',
'error',
]),
'title': 'Status',
'type': 'string',
}),
'tool_call_id': dict({
'title': 'Tool Call Id',
'type': 'string',
@@ -6483,6 +6492,15 @@
'title': 'Response Metadata',
'type': 'object',
}),
'status': dict({
'default': 'success',
'enum': list([
'success',
'error',
]),
'title': 'Status',
'type': 'string',
}),
'tool_call_id': dict({
'title': 'Tool Call Id',
'type': 'string',
@@ -7075,6 +7093,15 @@
'title': 'Response Metadata',
'type': 'object',
}),
'status': dict({
'default': 'success',
'enum': list([
'success',
'error',
]),
'title': 'Status',
'type': 'string',
}),
'tool_call_id': dict({
'title': 'Tool Call Id',
'type': 'string',
@@ -7724,6 +7751,15 @@
'title': 'Response Metadata',
'type': 'object',
}),
'status': dict({
'default': 'success',
'enum': list([
'success',
'error',
]),
'title': 'Status',
'type': 'string',
}),
'tool_call_id': dict({
'title': 'Tool Call Id',
'type': 'string',
@@ -8376,6 +8412,15 @@
'title': 'Response Metadata',
'type': 'object',
}),
'status': dict({
'default': 'success',
'enum': list([
'success',
'error',
]),
'title': 'Status',
'type': 'string',
}),
'tool_call_id': dict({
'title': 'Tool Call Id',
'type': 'string',
@@ -8975,6 +9020,15 @@
'title': 'Response Metadata',
'type': 'object',
}),
'status': dict({
'default': 'success',
'enum': list([
'success',
'error',
]),
'title': 'Status',
'type': 'string',
}),
'tool_call_id': dict({
'title': 'Tool Call Id',
'type': 'string',
@@ -9547,6 +9601,15 @@
'title': 'Response Metadata',
'type': 'object',
}),
'status': dict({
'default': 'success',
'enum': list([
'success',
'error',
]),
'title': 'Status',
'type': 'string',
}),
'tool_call_id': dict({
'title': 'Tool Call Id',
'type': 'string',
@@ -10228,6 +10291,15 @@
'title': 'Response Metadata',
'type': 'object',
}),
'status': dict({
'default': 'success',
'enum': list([
'success',
'error',
]),
'title': 'Status',
'type': 'string',
}),
'tool_call_id': dict({
'title': 'Tool Call Id',
'type': 'string',

View File

@@ -874,7 +874,9 @@ def test_merge_tool_calls() -> None:
def test_tool_message_serdes() -> None:
message = ToolMessage("foo", artifact={"bar": {"baz": 123}}, tool_call_id="1")
message = ToolMessage(
"foo", artifact={"bar": {"baz": 123}}, tool_call_id="1", status="error"
)
ser_message = {
"lc": 1,
"type": "constructor",
@@ -884,6 +886,7 @@ def test_tool_message_serdes() -> None:
"type": "tool",
"tool_call_id": "1",
"artifact": {"bar": {"baz": 123}},
"status": "error",
},
}
assert dumpd(message) == ser_message
@@ -911,6 +914,7 @@ def test_tool_message_ser_non_serializable() -> None:
"id": ["tests", "unit_tests", "test_messages", "BadObject"],
"repr": repr(bad_obj),
},
"status": "success",
},
}
assert dumpd(message) == ser_message
@@ -931,6 +935,7 @@ def test_tool_message_to_dict() -> None:
"name": None,
"id": None,
"tool_call_id": "1",
"status": "success",
},
}
actual = message_to_dict(message)