From c447b4ab854200c158c375f1d44d865f335fbefc Mon Sep 17 00:00:00 2001 From: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com> Date: Tue, 13 Oct 2026 20:07:32 +0530 Subject: [PATCH 1/2] Python: fix(anthropic): nest bash tool result files inside the shell tool result The bash branch appended hosted output files to the message-level contents list instead of the shell result outputs, so the files leaked out as bare top-level hosted_file contents. The code interpreter twin branch already nested them correctly. Fixes #9342 Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com> --- .../agent_framework_anthropic/_chat_client.py | 2 +- .../anthropic/tests/test_anthropic_client.py | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/python/packages/anthropic/agent_framework_anthropic/_chat_client.py b/python/packages/anthropic/agent_framework_anthropic/_chat_client.py index 146b9f6a998..01cd6b021dc 100644 --- a/python/packages/anthropic/agent_framework_anthropic/_chat_client.py +++ b/python/packages/anthropic/agent_framework_anthropic/_chat_client.py @@ -1527,7 +1527,7 @@ def _parse_contents_from_anthropic( ) ) for bash_file_content in content_block.content.content: - contents.append( + shell_outputs.append( Content.from_hosted_file( file_id=bash_file_content.file_id, raw_representation=bash_file_content, diff --git a/python/packages/anthropic/tests/test_anthropic_client.py b/python/packages/anthropic/tests/test_anthropic_client.py index c91a37765ed..ee1b07f2053 100644 --- a/python/packages/anthropic/tests/test_anthropic_client.py +++ b/python/packages/anthropic/tests/test_anthropic_client.py @@ -4251,3 +4251,32 @@ def test_option_translations_single_stop_string_becomes_list() -> None: options = {"stop": ["END", "STOP"]} _apply_option_translations(options) assert options == {"stop_sequences": ["END", "STOP"]} + + +def test_parse_bash_execution_result_with_files( + mock_anthropic_client: MagicMock, +) -> None: + """Bash result files stay nested in the shell tool result outputs (#9342).""" + client = create_test_anthropic_client(mock_anthropic_client) + + mock_file = MagicMock() + mock_file.file_id = "file_456" + + mock_content = MagicMock() + mock_content.stdout = "Output text" + mock_content.stderr = None + mock_content.return_code = 0 + mock_content.content = [mock_file] + + mock_block = MagicMock() + mock_block.type = "bash_code_execution_tool_result" + mock_block.tool_use_id = "call_bash4" + mock_block.content = mock_content + + result = client._parse_contents_from_anthropic([mock_block]) + + assert len(result) == 1 + assert result[0].type == "shell_tool_result" + hosted_files = [output for output in result[0].outputs if output.type == "hosted_file"] + assert len(hosted_files) == 1 + assert hosted_files[0].file_id == "file_456" From 4e999542b02bc0bcc509adf3f23f4f9f07ba8062 Mon Sep 17 00:00:00 2001 From: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com> Date: Wed, 14 Oct 2026 13:37:19 +0530 Subject: [PATCH 2/2] Python: guard the bash files test against the optional outputs list Signed-off-by: Manohar Paturi <186662190+ManoharPaturi@users.noreply.github.com> --- python/packages/anthropic/tests/test_anthropic_client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/packages/anthropic/tests/test_anthropic_client.py b/python/packages/anthropic/tests/test_anthropic_client.py index ee1b07f2053..48e2a8917b3 100644 --- a/python/packages/anthropic/tests/test_anthropic_client.py +++ b/python/packages/anthropic/tests/test_anthropic_client.py @@ -4277,6 +4277,7 @@ def test_parse_bash_execution_result_with_files( assert len(result) == 1 assert result[0].type == "shell_tool_result" + assert result[0].outputs is not None hosted_files = [output for output in result[0].outputs if output.type == "hosted_file"] assert len(hosted_files) == 1 assert hosted_files[0].file_id == "file_456"