feat: tool_code_execution() — provider-executed code execution

Open
#364 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Quiet
Tech stack
python

Research direction

Start with the docs/plans draft and the existing web search/fetch implementation described in the issue. Trace the provider annotation and content-type precedents, then define the work needed for Anthropic, OpenAI Responses, and Google, including container persistence and unsupported platforms; done means the design is settled and all three providers have a consistent first-class tool path.

Written by the indexing model from the issue text.

Description

ai-triage:needs-review

Code execution is the last provider-executed tool that is GA across all three first-class providers (Anthropic, OpenAI Responses API, Google Gemini) — the same footprint as tool_web_search(). A first-class tool_code_execution() would let the model run Python server-side for data analysis, math, and file processing with zero local sandbox setup, which is squarely in the wheelhouse of chatlas's data-science audience.

chat.register_tool(tool_code_execution())
chat.chat("Compute the eigenvalues of this matrix and plot them: ...")

Provider mapping

Provider Tool spec Notes
Anthropic {"type": "code_execution_20250825", ...} (newer dated variants exist) Server sandbox (Python 3.11, no internet). Container reusable across requests via container param. Free when combined with recent web search/fetch variants; otherwise ~1,550 free container-hours/org/month, then $0.05/hr. Docs
OpenAI (Responses) {"type": "code_interpreter", "container": {"type": "auto"}} Or an explicit container ID from /v1/containers. Billed per memory tier per 20-min session ($0.03–$1.92). Docs
Google types.Tool(code_execution=types.ToolCodeExecution()) No extra fee (standard token billing). Python only, ~30s per execution, no custom packages. Returns executable_code / code_execution_result parts. Docs

Design considerations

  • New content types (ContentToolRequestCodeExecution / ContentToolResponseCodeExecution) following the web search/fetch precedent, registered in PROVIDER_ANNOTATION_TYPES so each provider replays only its own blocks.
  • Container/session persistence across turns (Anthropic container, OpenAI container IDs) — likely: scan turn history for the most recent container ID and resend it.
  • Gemini models before Gemini 3 cannot mix built-in tools with custom function declarations in the same request.
  • Availability gaps: not supported on Amazon Bedrock; not supported on Vertex AI for Anthropic models (see the guard issue for how unsupported platforms should fail).

Design work for this is already underway locally (docs/plans draft + worktree).

Dominant language
Python
Stars
179
Forks
32
Avg merge
1d 3h
Merged PRs (30d)
10

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from posit-dev/chatlas

All issues in posit-dev/chatlas

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.