|
| 1 | +# Azure Container Apps Dynamic Sessions |
| 2 | + |
| 3 | +> [Azure Container Apps dynamic sessions](https://learn.microsoft.com/azure/container-apps/sessions) provide fast access to secure sandboxed environments that are ideal for running code or applications that require strong isolation from other workloads. |
| 4 | +
|
| 5 | +You can learn more about Azure Container Apps dynamic sessions and its code interpretation capabilities on [this page](https://learn.microsoft.com/azure/container-apps/sessions). If you don't have an Azure account, you can [create a free account](https://azure.microsoft.com/free/) to get started. |
| 6 | + |
| 7 | +## Setup |
| 8 | + |
| 9 | +You'll first need to install the [`@langchain/azure-dynamic-sessions`](https://www.npmjs.com/package/@langchain/azure-dynamic-sessions) package: |
| 10 | + |
| 11 | +import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx"; |
| 12 | + |
| 13 | +<IntegrationInstallTooltip></IntegrationInstallTooltip> |
| 14 | + |
| 15 | +```bash npm2yarn |
| 16 | +npm install @langchain/azure-dynamic-sessions |
| 17 | +``` |
| 18 | + |
| 19 | +You'll also need to have a code interpreter session pool instance running. You can deploy a version using [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli) following [this guide](https://learn.microsoft.com/azure/container-apps/sessions-code-interpreter). |
| 20 | + |
| 21 | +Once you have your instance running, you need to make sure you have properly set up the Azure Entra authentication for it. You can find the instructions on how to do that [here](https://learn.microsoft.com/azure/container-apps/sessions?tabs=azure-cli#authentication). |
| 22 | + |
| 23 | +After you've added the role for your identity, you need to retrieve the **session pool management endpoint**. You can find it in the Azure Portal, under the "Overview" section of your instance. Then you need to set the following environment variable: |
| 24 | + |
| 25 | +import CodeBlock from "@theme/CodeBlock"; |
| 26 | +import EnvVars from "@examples/tools/azure_dynamic_sessions/.env.example"; |
| 27 | + |
| 28 | +<CodeBlock language="text">{EnvVars}</CodeBlock> |
| 29 | + |
| 30 | +## Usage example |
| 31 | + |
| 32 | +Below is a simple example that creates a new Python code interpreter session, invoke the tool and prints the result. |
| 33 | + |
| 34 | +import Example from "@examples/tools/azure_dynamic_sessions/azure_dynamic_sessions.ts"; |
| 35 | + |
| 36 | +<CodeBlock language="typescript">{Example}</CodeBlock> |
| 37 | + |
| 38 | +Here is a complete example where we use an Azure OpenAI chat model to call the Python code interpreter session tool to execute the code and get the result: |
| 39 | + |
| 40 | +import AgentExample from "@examples/tools/azure_dynamic_sessions/azure_dynamic_sessions-agent.ts"; |
| 41 | + |
| 42 | +<CodeBlock language="typescript">{AgentExample}</CodeBlock> |
0 commit comments