copilot-sdk
copilot-sdk copied to clipboard
fix(python): forward binary tool results in HandlePendingToolCall RPC
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()inpython/copilot/tools.pyto mapToolResult→ExternalToolTextResultForLlm, including binary result type enum conversion. - Use the helper in
CopilotSession._execute_tool_and_respondinstead of an inline constructor that omittedbinary_results_for_llmandsession_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