Setup
By default, theSessionsPythonREPLTool tool uses DefaultAzureCredential to authenticate with Azure. Locally, it’ll use your credentials from the Azure CLI or VS Code. Install the Azure CLI and log in with az login to authenticate.
To use the code interpreter you’ll also need to create a session pool, which you can do by following the instructions here. Once that’s done you should have a pool management session endpoint, which you’ll need to set below:
langchain-azure-dynamic-sessions package:
Use tool
Instantiate and use tool:execute() method:
Upload data
If we want to perform computation over specific data, we can use theupload_file() functionality to upload data to our session. You can upload data either via the data: BinaryIO arg or via the local_file_path: str arg (which points to a local file on your system). The data is automatically uploaded to the “/mnt/data/” directory in the sessions container. You can get the full file path via the upload metadata returned by upload_file().
Handling image results
Dynamic sessions results can include image outputs as base64 encoded strings. In these cases the value of ‘result’ will be a dictionary with keys “type” (which will be “image”), “format (the format of the image), and “base64_data”.Simple agent example
LangGraph data analyst agent
For a more complex agent example check out the LangGraph data analyst exampleConnect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.