Skip to main content

Code interpreter AI agent tools

Add code interpreter tools to AI agents using the Mosaic AI Agent Framework to enable agents to execute arbitrary code provided by an interacting user, retrieved from a code base, or written by the agent.

To learn more about agent tools, see AI agent tools and to create tools that execute custom task-specific operations, see Create AI agent tools using Unity Catalog functions

Built-in Python executor tool

Databricks also provides a built-in Unity Catalog function allowing AI agents to dynamically execute Python code within queries dynamically.

system.ai.python_exec is available by default and can be used like any other Unity Catalog function-based tool.

The following example shows you how to use the python_exec function in a SQL query:

SQL
SELECT python_exec("""
import random
numbers = [random.random() for _ in range(10)]
print(numbers)
""")

Next steps

After you create a Unity Catalog tool, add it to your agent. See Create an agent tool.