From f9103266c6696a81a01549471a3c404c9a5cf3ac Mon Sep 17 00:00:00 2001 From: Aditya Kumar Date: Wed, 11 Nov 2026 16:52:03 +0000 Subject: [PATCH] Python: Send empty text for GitHubCopilotAgent tool results without text The Copilot tool adapter fell back to str(result) when a tool produced no text. Since tool results became lists of Content items, that fallback sends the list repr ("[]") to the model for tools that return None, an empty string, or only rich content. Send the joined text as is, so these tools report an empty result like the Copilot SDK does for a handler that returns None. --- .../agent_framework_github_copilot/_agent.py | 2 +- .../tests/test_github_copilot_agent.py | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/python/packages/github_copilot/agent_framework_github_copilot/_agent.py b/python/packages/github_copilot/agent_framework_github_copilot/_agent.py index 92c47f970b1..7e3a8e428aa 100644 --- a/python/packages/github_copilot/agent_framework_github_copilot/_agent.py +++ b/python/packages/github_copilot/agent_framework_github_copilot/_agent.py @@ -1601,7 +1601,7 @@ async def handler(invocation: ToolInvocation) -> ToolResult: ) text = "\n".join(c.text for c in result if c.type == "text" and c.text) return ToolResult( - text_result_for_llm=text or str(result), + text_result_for_llm=text, result_type="success", ) except Exception as e: diff --git a/python/packages/github_copilot/tests/test_github_copilot_agent.py b/python/packages/github_copilot/tests/test_github_copilot_agent.py index 277d558f301..25cae12a2fd 100644 --- a/python/packages/github_copilot/tests/test_github_copilot_agent.py +++ b/python/packages/github_copilot/tests/test_github_copilot_agent.py @@ -2926,6 +2926,38 @@ def no_args_tool() -> str: assert result.result_type == "success" assert result.text_result_for_llm == "no args result" + @pytest.mark.parametrize( + "tool_return", + [None, "", Content.from_data(data=b"\x89PNG\r\n\x1a\n", media_type="image/png")], + ids=["none", "empty_string", "image_only"], + ) + async def test_tool_handler_returns_empty_text_when_tool_returns_no_text( + self, + mock_client: MagicMock, + mock_session: MagicMock, + tool_return: Any, + ) -> None: + """Test that a tool result without text reaches the model as an empty string, not as a Python repr.""" + + def no_text_tool() -> Any: + """A tool that returns no text.""" + return tool_return + + agent = GitHubCopilotAgent(client=mock_client, tools=[no_text_tool]) + await agent.start() + + await agent._get_or_create_session(AgentSession()) # type: ignore + + call_args = mock_client.create_session.call_args + config = call_args.kwargs + copilot_tool = config["tools"][0] + + result = await copilot_tool.handler(ToolInvocation(arguments={})) + + assert isinstance(result, ToolResult) + assert result.result_type == "success" + assert result.text_result_for_llm == "" + async def test_run_forwards_function_invocation_kwargs_to_tools( self, mock_client: MagicMock,