copilot-sdk icon indicating copy to clipboard operation
copilot-sdk copied to clipboard

fix(python): forward binary tool results in HandlePendingToolCall RPC

Open syf2211 opened this issue 5 months ago • 0 comments

Summary

When a Python tool handler returns a ToolResult with binary_results_for_llm (e.g. base64 image data) or session_log, those fields were dropped while building the ExternalToolTextResultForLlm payload in _execute_tool_and_respond. The model only received text fields, so image tool outputs appeared unavailable.

Motivation

Fixes #1644. Users building agents with image-returning tools saw the model report it could not view images, even though direct blob attachments worked.

Changes

  • Add tool_result_to_external_tool_text_result_for_llm() in python/copilot/tools.py to map ToolResult → ExternalToolTextResultForLlm, including binary result type enum conversion.
  • Use the helper in CopilotSession._execute_tool_and_respond instead of an inline constructor that omitted binary_results_for_llm and session_log.
  • Add unit tests covering binary forwarding and the no-binary case.

Tests

cd python && uv run pytest test_tools.py::TestToolResultToExternalToolTextResultForLlm -q
cd python && uv run ruff check copilot/tools.py copilot/session.py test_tools.py
  • 2 passed
  • ruff: All checks passed

Notes

  • Scope is Python SDK only; Node passes the full result object through RPC already.
  • Composer-2.5 code review: APPROVE

syf2211 avatar Jun 28 '26 04:06 syf2211