Add optional code_interpreter built-in tool to chat (opt-in)
Author: pamelafoxCreated Jun 25, 2026Updated Jun 25, 2026
Summary
Add an opt-in setting that attaches the OpenAI Responses code_interpreter built-in tool to chat answer calls, so the model can run Python for computational questions (math, data analysis over retrieved content).
Motivation
Some questions need real computation (percentages, aggregations, unit conversions). Wiring code_interpreter as an optional, off-by-default tool adds capability without changing how answers are normally generated — so existing answer-quality evals remain valid.
Proposed implementation
Follow the existing tool/override pattern (e.g. use_web_source):
- Backend (
app/backend/approaches):- In
chatreadretrieveread.py, readoverrides.get("use_code_interpreter")and, when true, append{"type": "code_interpreter", "container": {"type": "auto"}}to thetoolslist passed tocreate_response()for the final answer call. create_response()inapproach.pyalready forwardstoolstoresponses.create— no change needed there.- Surface tool invocations as a
ThoughtStepso they appear in the thought process panel.
- In
- Frontend:
- Add
use_code_interpreter?: booleanto the overrides inapi/models.ts. - Add a toggle in
components/Settings/Settings.tsx, wired throughpages/chat/Chat.tsxlike other override checkboxes.
- Add
- Docs: note the setting in the relevant
docs/customization page.
Scope / out of scope
- In scope: opt-in toggle, backend tool wiring, thought-process visibility.
- Out of scope: changing default answer-generation prompts; enabling by default.
Acceptance criteria
- Toggle in Settings; off by default.
- When on,
code_interpreteris attached to the answer call and the model can execute Python. - Tool runs visible in the thought process.
- When off, request payload is unchanged (no eval impact); existing tests pass.
Source: Azure-Samples/azure-search-openai-demo