Skip to main content

An integration package connecting Azure Container Apps dynamic sessions and LangChain

Project description

langchain-azure-dynamic-sessions

This package contains the LangChain integration for Azure Container Apps dynamic sessions. You can use it to add a secure and scalable code interpreter to your agents.

Installation

pip install -U langchain-azure-dynamic-sessions

Configuration

You first need to create an Azure Container Apps session pool and obtain its management endpoint. Learn how to configure a pool in Azure Container Apps.

By default, both tools use DefaultAzureCredential to authenticate with Azure. If you're using a user-assigned managed identity, you must set the AZURE_CLIENT_ID environment variable to the ID of the managed identity. Only Microsoft Entra ID tokens from an identity belonging to the Azure ContainerApps Session Executor role on the session pool are authorized to call the pool management API.

az role assignment create \
    --role "Azure ContainerApps Session Executor" \
    --assignee <PRINCIPAL_ID> \
    --scope <SESSION_POOL_RESOURCE_ID>

Usage

SessionsPythonREPLTool

Use the SessionsPythonREPLTool tool to give your agent the ability to execute Python code.

from langchain.agents import create_agent
from langchain_azure_dynamic_sessions.tools import SessionsPythonREPLTool


# get the management endpoint from the session pool in the Azure portal
tool = SessionsPythonREPLTool(pool_management_endpoint=POOL_MANAGEMENT_ENDPOINT)

agent = create_agent(model=llm, tools=[tool])
result = agent.invoke({"messages": [{"role": "user", "content": "What is the current time in Vancouver, Canada?"}]})

SessionsBashTool

Use the SessionsBashTool tool to give your agent the ability to execute bash commands.

from langchain.agents import create_agent
from langchain_azure_dynamic_sessions.tools import SessionsBashTool


# get the management endpoint from the session pool in the Azure portal
tool = SessionsBashTool(pool_management_endpoint=POOL_MANAGEMENT_ENDPOINT)

agent = create_agent(model=llm, tools=[tool])
result = agent.invoke({"messages": [{"role": "user", "content": "List the files in the current directory."}]})

You can also execute bash commands directly:

from langchain_azure_dynamic_sessions import SessionsBashTool


tool = SessionsBashTool(pool_management_endpoint=POOL_MANAGEMENT_ENDPOINT)

# execute a bash command
result = tool.run("echo hello world")
# Returns: '{"stdout": "hello world\n", "stderr": "", "exitCode": 0}'

The tool supports file operations as well:

tool = SessionsBashTool(pool_management_endpoint=POOL_MANAGEMENT_ENDPOINT)

# upload a file to the session
tool.upload_file(local_file_path="./local_script.sh", remote_file_path="/mnt/user/script.sh")

# list files in the session
files = tool.list_files()

# download a file from the session
tool.download_file(remote_file_path="/mnt/user/output.txt", local_file_path="./output.txt")

Changelog

  • 1.0.2:

    • We aligned SessionsBashTool request and response handling with the Azure Container Apps shell session pool API contract. #450
    • We fixed a NameError that could occur when importing SessionsBashBackend. #473
    • We patched dependency vulnerabilities and refreshed core dependencies to improve package stability and security. #442

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_azure_dynamic_sessions-1.0.2.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file langchain_azure_dynamic_sessions-1.0.2.tar.gz.

File metadata

File hashes

Hashes for langchain_azure_dynamic_sessions-1.0.2.tar.gz
Algorithm Hash digest
SHA256 8a37112bd920b9497d47b5039ecc2aebc51ae29dc60a481267ccf171e52ad319
MD5 b5357dbfec4ed49104f8307f22142924
BLAKE2b-256 66ca14f79967ca924dc069636dd216e0a2b56fc854e1217bc5f5c82affedfdaa

See more details on using hashes here.

File details

Details for the file langchain_azure_dynamic_sessions-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_azure_dynamic_sessions-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9c8a9805a165478ff0909c0dcecf852661434234ce5b9382e2d4a7f5e79ebe33
MD5 33c3bef18abb533f702636a196273ef7
BLAKE2b-256 e5cc664206e10c82471d0b50a6362687eb25cdef6796920fc3d989874650faad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page