Skip to content

docs: migrate examples off deprecated code_interpreter/local_code_interpreter to python_tool #1277

@psschwei

Description

@psschwei

Problem

The docs and examples still use the deprecated code_interpreter() and local_code_interpreter() helpers instead of python_tool(). PR #1271 updated docs/examples/tools/README.md and python_tool_example.py, but three files still reference the deprecated functions:

  • docs/examples/tools/interpreter_example.py — uses code_interpreter / local_code_interpreter throughout (the runnable companion to the README that fix: address default execution tier security posture #1271 changed, so the two now diverge)
  • docs/docs/how-to/tools-and-agents.md — lines ~114–162 and ~264–274
  • docs/examples/tools/README.md — "Tool with LLM" / "Forcing Tool Use" / "Validating" examples and the "Available Tools" list still name both deprecated functions

Both code_interpreter() and local_code_interpreter() emit DeprecationWarning and point at python_tool() (mellea/stdlib/tools/interpreter.py:1199-1244). The docs should demonstrate the supported API.

Why this is more than a rename

python_tool() is not a drop-in substitution for the deprecated callables — the migration touches four things:

Aspect Deprecated python_tool
Import code_interpreter, local_code_interpreter python_tool
Wrapping MelleaTool.from_callable(local_code_interpreter) python_tool(tier="local_unsafe") — already a MelleaTool
Direct call code_interpreter("print(1+1)") tool.run(code="print(1+1)")ExecutionResult
Tool-call key & uses_tool arg "local_code_interpreter" / the callable "python" (default name=) or your name=; the name string, not the object

Two caveats that block a naive find-replace:

  1. uses_tool(tool) / tool_arg_validator(tool_name=tool) cannot take the MelleaTool object. _name2str (mellea/stdlib/requirements/tool_reqs.py:16) accepts only a str or a callable with __name__; a MelleaTool instance hits the case _TypeError. Pass the tool's name string instead.
  2. python_tool() emits the new UserWarning from fix: address default execution tier security posture #1271 unless tier= is passed explicitly. Passing tier="local_unsafe" is exactly the conscious trust decision fix: address default execution tier security posture #1271 introduced, so the migrated examples should pass it explicitly — turning the examples into a demonstration of the new contract.

Suggested shape

from mellea.stdlib.tools import python_tool

# create once, reuse the name in requirements and lookups
tool = python_tool(tier="local_unsafe", name="python")

# direct, no LLM:
result = tool.run(code="print(1 + 1)")

# force + validate:
m.instruct(
    description="Use the code interpreter tool to make a plot of y=x^2.",
    requirements=[uses_tool("python")],          # name string, not the object
    model_options={ModelOption.TOOLS: [tool]},
    tool_calls=True,
)
code = response.tool_calls["python"].args["code"]

Note: the README examples just changed in #1271 will need a second pass so their tool_calls[...] keys and uses_tool(...) args use "python" rather than "local_code_interpreter".

Acceptance criteria

  • docs/examples/tools/interpreter_example.py migrated to python_tool (passes its # pytest: ollama, e2e run)
  • docs/docs/how-to/tools-and-agents.md migrated; markdownlint-cli2 clean
  • docs/examples/tools/README.md migrated (tool-call keys + uses_tool args use the name string; "Available Tools" list updated)
  • No remaining references to code_interpreter / local_code_interpreter in docs/ except where intentionally documenting the deprecation
  • Tier passed explicitly so examples don't emit the fix: address default execution tier security posture #1271 UserWarning

Context

Follow-up to #1271, which deliberately kept its scope to the security-posture warnings. Surfaced during review of that PR.

Metadata

Metadata

Labels

p2Medium/low: minor bugs, niche features, polish, docs, tests, cleanup. Scoped, lower urgency.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions