feat: Add `files` support to `CodeExecutionTool` for Anthropic and OpenAI

Merged
HE
5mo ago
+3698-8

Summary

  • Add file_ids parameter to CodeExecutionTool to allow uploading files to code execution containers
  • Upgrade Anthropic CodeExecutionTool from code_execution_20250522 to code_execution_20250825 beta
  • Add OpenAI Responses API support for file_ids in code_interpreter container
  • Support both providers as required by maintainer feedback for new generic class fields

Changes

Anthropic

  • Upgrade to code-execution-2025-08-25 beta which supports file uploads
  • Add container_upload blocks to user messages when file_ids are provided
  • Automatically enable files-api-2025-04-14 beta when file_ids are used
  • Handle new result block types: BetaBashCodeExecutionToolResultBlock, BetaTextEditorCodeExecutionToolResultBlock

OpenAI

  • Pass file_ids to code_interpreter container configuration
  • Extract _map_mcp_server_tool helper to reduce function complexity

Documentation

  • Add "File Uploads" section with examples for both Anthropic and OpenAI
  • Update provider support table to show ✅ for both providers

Test plan

  • Unit tests for Anthropic file_ids with and without files

  • Unit tests for OpenAI file_ids with and without files

  • End-to-end test with OpenAI (verified file upload and code execution works)

  • All existing tests pass

  • Type checking passes

  • Linting passes

  • Closes #4319

Pre-Review Checklist

  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • No breaking changes in accordance with the version policy.
  • Linting and type checking pass per make format and make typecheck.
  • PR title is fit for the release changelog.

Pre-Merge Checklist

  • New tests for any fix or new behavior, maintaining 100% coverage.
  • Updated documentation for new features and behaviors, including docstrings for API docs.