LangChain Azure Dynamic Sessions

raw JSON →
1.0.2 verified Fri May 01 auth: no python

An integration package connecting Azure Container Apps dynamic sessions with LangChain. It provides tools to execute code snippets (Python, bash) in isolated, ephemeral sessions within Azure Container Apps. Current version 1.0.2, released on 2025-01-14, with periodic patch updates. Requires Python >=3.10, <4.0.

pip install langchain-azure-dynamic-sessions
error ImportError: cannot import name 'AzureDynamicSessionsTool' from 'langchain_azure_dynamic_sessions'
cause Wrong import path – the tool is in the 'tool' submodule.
fix
Use: from langchain_azure_dynamic_sessions.tool import AzureDynamicSessionsTool
error azure.core.exceptions.ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token
cause No Azure credentials available; missing environment variables or Azure CLI login.
fix
Set AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET or run 'az login'.
error ValueError: Invalid pool endpoint. Expected a full URL.
cause Pool endpoint provided without https:// prefix or missing region.
fix
Use format: https://<pool-name>.<region>.azurecontainerapps.io
gotcha The library requires Python >=3.10. Attempting to install on older versions will fail due to requires_python constraints.
fix Upgrade to Python 3.10+ or use a compatible environment.
breaking The pool_endpoint must be a full URL (including https://). Earlier beta versions allowed just the pool name.
fix Always use the full endpoint URL: https://<pool-name>.<region>.azurecontainerapps.io
gotcha Authentication is handled via Azure Identity (DefaultAzureCredential). If you have multiple credentials, ensure the correct one is used (e.g., via environment variables).
fix Set AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET, or use Azure CLI login.
deprecated The SessionsPythonTool is deprecated in favor of AzureDynamicSessionsTool. New projects should use AzureDynamicSessionsTool.
fix Replace SessionsPythonTool with AzureDynamicSessionsTool.

Initialize the tool with your pool endpoint (set the environment variable or replace the placeholder) and execute a Python snippet.

import os
from langchain_azure_dynamic_sessions.tool import AzureDynamicSessionsTool

pool_endpoint = os.environ.get("AZURE_CONTAINER_SESSION_POOL_ENDPOINT", "https://<your-pool>.region.azurecontainerapps.io")
tool = AzureDynamicSessionsTool(pool_endpoint=pool_endpoint)
result = tool.run("print('Hello from dynamic sessions!')")
print(result)