Skip to content

Commit beaa616

Browse files
committed
fix(llm): forward tool error status in AWS Bedrock format
1 parent 5f12c87 commit beaa616

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎livekit-agents/livekit/agents/llm/_provider_format/aws.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def to_chat_ctx(
8383
if isinstance(msg.output, dict)
8484
else {"text": msg.output}
8585
],
86-
"status": "success",
86+
"status": "error" if msg.is_error else "success",
8787
}
8888
}
8989
)

‎tests/test_chat_ctx.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,28 @@ def test_aws_image_content_rejects_external_urls():
128128
chat_ctx.to_provider_format(format="aws")
129129

130130

131+
@pytest.mark.parametrize(
132+
("is_error", "expected_status"),
133+
[(True, "error"), (False, "success")],
134+
)
135+
def test_aws_format_tool_result_status_reflects_is_error(is_error: bool, expected_status: str):
136+
chat_ctx = ChatContext.empty()
137+
chat_ctx.items.append(FunctionCall(name="search", call_id="call_1", arguments="{}"))
138+
chat_ctx.items.append(
139+
FunctionCallOutput(
140+
name="search",
141+
call_id="call_1",
142+
output="the database is on fire",
143+
is_error=is_error,
144+
)
145+
)
146+
147+
messages, _ = chat_ctx.to_provider_format(format="aws")
148+
149+
tool_result = messages[-1]["content"][-1]["toolResult"]
150+
assert tool_result["status"] == expected_status
151+
152+
131153
def _ctx_with_per_turn_instructions() -> tuple[ChatContext, str]:
132154
# the shape generate_reply(instructions=...) produces: a trailing system message
133155
instructions = "Ask the caller for the year they were born."

0 commit comments

Comments
 (0)