From 1a00cb08b0f2ebb73ee73831776d4ebd550ad7d5 Mon Sep 17 00:00:00 2001 From: Shivakishore14 Date: Fri, 23 Oct 2026 10:46:28 +0000 Subject: [PATCH 1/2] fix(hosting): configure python startup for foundry samples Configure user-site loading before Python starts in deployment files, container images, and local sample instructions. Authored-by: GitHub Copilot CLI v1.0.102 Model: GPT-6.1 Sol (gpt-6.1-sol) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../container/hyperlight_codeact/Dockerfile | 2 + .../container/hyperlight_codeact/README.md | 6 +++ .../hyperlight_codeact/agent.manifest.yaml | 2 + .../container/hyperlight_codeact/agent.yaml | 2 + .../foundry-hosted-agents/README.md | 44 +++++++++++++++++++ .../invocations/basic/Dockerfile | 2 + .../invocations/basic/README.md | 4 ++ .../invocations/basic/agent.manifest.yaml | 2 + .../invocations/basic/agent.yaml | 3 ++ .../invocations/break_glass/Dockerfile | 2 + .../break_glass/agent.manifest.yaml | 2 + .../invocations/break_glass/agent.yaml | 3 ++ .../invocations/telegram/azure.yaml | 2 + .../telegram/tests/test_infrastructure.py | 1 + .../responses/azure_search_rag/Dockerfile | 2 + .../azure_search_rag/agent.manifest.yaml | 2 + .../responses/azure_search_rag/agent.yaml | 2 + .../responses/basic/Dockerfile | 2 + .../responses/basic/README.md | 3 +- .../responses/basic/agent.manifest.yaml | 2 + .../responses/basic/agent.yaml | 2 + .../responses/custom_storage/Dockerfile | 2 + .../custom_storage/agent.manifest.yaml | 2 + .../responses/custom_storage/agent.yaml | 2 + .../declarative_customer_support/Dockerfile | 2 + .../agent.manifest.yaml | 2 + .../declarative_customer_support/agent.yaml | 2 + .../responses/files/Dockerfile | 2 + .../responses/files/agent.manifest.yaml | 2 + .../responses/files/agent.yaml | 2 + .../responses/foundry_memory/Dockerfile | 2 + .../foundry_memory/agent.manifest.yaml | 2 + .../responses/foundry_memory/agent.yaml | 2 + .../responses/foundry_toolbox/Dockerfile | 2 + .../responses/foundry_toolbox/README.md | 4 ++ .../foundry_toolbox/agent.manifest.yaml | 2 + .../responses/foundry_toolbox/agent.yaml | 2 + .../foundry_toolbox_mcp_skills/Dockerfile | 2 + .../agent.manifest.yaml | 2 + .../foundry_toolbox_mcp_skills/agent.yaml | 2 + .../responses/mcp/Dockerfile | 2 + .../responses/mcp/agent.manifest.yaml | 2 + .../responses/mcp/agent.yaml | 2 + .../responses/monty_codeact/Dockerfile | 2 + .../responses/monty_codeact/README.md | 4 ++ .../monty_codeact/agent.manifest.yaml | 2 + .../responses/monty_codeact/agent.yaml | 2 + .../responses/observability/Dockerfile | 2 + .../observability/agent.manifest.yaml | 2 + .../responses/observability/agent.yaml | 2 + .../Dockerfile | 2 + .../agent.manifest.yaml | 3 ++ .../agent.yaml | 3 ++ .../steerable_long_running_agent/Dockerfile | 2 + .../agent.manifest.yaml | 2 + .../steerable_long_running_agent/agent.yaml | 2 + .../responses/tools/Dockerfile | 2 + .../responses/tools/agent.manifest.yaml | 2 + .../responses/tools/agent.yaml | 2 + .../responses/workflows/Dockerfile | 2 + .../responses/workflows/README.md | 4 ++ .../responses/workflows/agent.manifest.yaml | 2 + .../responses/workflows/agent.yaml | 2 + .../references/hosting-and-deployment.md | 11 +++++ 64 files changed, 194 insertions(+), 1 deletion(-) diff --git a/python/samples/04-hosting/container/hyperlight_codeact/Dockerfile b/python/samples/04-hosting/container/hyperlight_codeact/Dockerfile index 218ba87b8ba..00faccb8ff7 100644 --- a/python/samples/04-hosting/container/hyperlight_codeact/Dockerfile +++ b/python/samples/04-hosting/container/hyperlight_codeact/Dockerfile @@ -7,6 +7,8 @@ # python/ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app # Copy the in-tree agent-framework packages we need. Order matters for editable diff --git a/python/samples/04-hosting/container/hyperlight_codeact/README.md b/python/samples/04-hosting/container/hyperlight_codeact/README.md index 44c9a53e918..1c434d24c58 100644 --- a/python/samples/04-hosting/container/hyperlight_codeact/README.md +++ b/python/samples/04-hosting/container/hyperlight_codeact/README.md @@ -68,6 +68,12 @@ Follow the instructions in the [Running the Agent Host Locally](../../foundry-hosted-agents//README.md#running-the-agent-host-locally) section of the README in the Foundry Hosted Agent directory. +Apply the [Python startup configuration](../../foundry-hosted-agents/README.md#python-startup-configuration) +before launching the host. The image and hosted deployment definitions set +`PYTHONNOUSERSITE=1`; this controls Python user-site loading only and does not +change the hypervisor requirement or make this sample supported on the default +Foundry runtime. + ## Interacting with the agent Send a POST request to the server with a JSON body containing an `"input"` diff --git a/python/samples/04-hosting/container/hyperlight_codeact/agent.manifest.yaml b/python/samples/04-hosting/container/hyperlight_codeact/agent.manifest.yaml index 623c663291f..f04d901ed3f 100644 --- a/python/samples/04-hosting/container/hyperlight_codeact/agent.manifest.yaml +++ b/python/samples/04-hosting/container/hyperlight_codeact/agent.manifest.yaml @@ -16,6 +16,8 @@ template: - protocol: responses version: 1.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" resources: diff --git a/python/samples/04-hosting/container/hyperlight_codeact/agent.yaml b/python/samples/04-hosting/container/hyperlight_codeact/agent.yaml index 3355fb51abf..abf3faef905 100644 --- a/python/samples/04-hosting/container/hyperlight_codeact/agent.yaml +++ b/python/samples/04-hosting/container/hyperlight_codeact/agent.yaml @@ -19,5 +19,7 @@ resources: cpu: "1" memory: 2Gi environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: gpt-4.1-mini diff --git a/python/samples/04-hosting/foundry-hosted-agents/README.md b/python/samples/04-hosting/foundry-hosted-agents/README.md index 1c91b59bfea..13dd0f0ef85 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/README.md @@ -5,6 +5,45 @@ This directory contains samples that demonstrate how to use hosted [Agent Framew > [IMPORTANT] Migrating from Protocol version 1.0.0 to 2.0.0: Foundry Hosting Agents service has been updated to use Protocol version 2.0.0. If your application is using Protocol version 1.0.0, please upgrade to Protocol version 2.0.0 in your `agent.manifest.yaml` or `agent.yaml` and upgrade to the latest `agent-framework-foundry-hosting` package. `agent-framework-foundry-hosting==1.0.0a260625` is the last version that supports Protocol version 1.0.0. > > The `agent-framework-foundry-hosting` Python API surface is intended to remain stable, but protocol 1.0.0 and 2.0.0 are incompatible. +## Python startup configuration + +The deployment YAML files in these samples explicitly configure +`PYTHONNOUSERSITE` with the string value `"1"` before the remote Python +interpreter starts. Each Python Dockerfile also sets `ENV PYTHONNOUSERSITE=1` +so directly running an image without its YAML keeps the same startup setting. +The Telegram direct-code sample sets it in `azure.yaml` instead. + +This setting is configured by the customer in the sample deployment, not +automatically injected by Foundry or Agent Framework. It disables Python +user-site loading, not all code execution, and does not configure other +language runtimes. Existing deployments need a newly deployed agent version +to pick up the setting; editing a local YAML file does not update a running +version. + +Install dependencies in a virtual environment or the container image's +system site-packages, not with `pip install --user`. The samples' `pip` and +`uv` installation paths do not require user-site packages. + +For **all local entry points and their restarts**, set the variable in the +launching shell before running Python, `uv run`, or `azd ai agent run`: + +```bash +# bash/zsh +export PYTHONNOUSERSITE=1 +``` + +```powershell +$env:PYTHONNOUSERSITE = "1" +``` + +```cmd +set PYTHONNOUSERSITE=1 +``` + +Repeat this setup in each new terminal. Setting `os.environ` or loading a +`.env` file from application code is too late for Python startup. Local shell +configuration does not replace the remote deployment's environment variables. + ## Samples ### Responses API @@ -139,6 +178,7 @@ This will create the following Azure resources: ```bash export FOUNDRY_PROJECT_ENDPOINT="https://.services.ai.azure.com/api/projects/" export FOUNDRY_MODEL="" +export PYTHONNOUSERSITE=1 # And any other environment variables required by the sample ``` @@ -147,6 +187,7 @@ Or in PowerShell: ```powershell $env:FOUNDRY_PROJECT_ENDPOINT="https://.services.ai.azure.com/api/projects/" $env:FOUNDRY_MODEL="" +$env:PYTHONNOUSERSITE="1" # And any other environment variables required by the sample ``` @@ -235,6 +276,9 @@ cd agent-framework/python/samples/04-hosting/foundry-hosted-agents/responses/bas #### Running the Agent Host +First apply the [shell startup configuration](#python-startup-configuration) +in the current terminal, including when using `uv run` instead of `python`: + ```bash python main.py ``` diff --git a/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/Dockerfile index eaffb94f198..e0c93a0ab5e 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/README.md b/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/README.md index 37283c6edce..450db99619f 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/README.md @@ -104,9 +104,13 @@ Use the current workspace until the coordinated hosting beta containing the native workflow API is published. From `python/`, run: ```bash +export PYTHONNOUSERSITE=1 uv run --no-sync python samples/04-hosting/foundry-hosted-agents/invocations/basic/workflow.py ``` +For other shells and deployment settings, see the +[Python startup configuration](../../README.md#python-startup-configuration). + After that release, the script's PEP 723 metadata also supports `uv run --script --prerelease=allow workflow.py`. Do not change a `pyproject.toml` to install sample-only imports. This entrypoint does not read diff --git a/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/agent.manifest.yaml index ac71182ab62..643cac9bcbe 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/agent.manifest.yaml @@ -15,6 +15,8 @@ template: - protocol: invocations version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" resources: diff --git a/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/agent.yaml index b42a6df045a..db1f3d8fcf7 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/agent.yaml @@ -7,3 +7,6 @@ protocols: resources: cpu: "0.25" memory: "0.5Gi" +environment_variables: + - name: PYTHONNOUSERSITE + value: "1" diff --git a/python/samples/04-hosting/foundry-hosted-agents/invocations/break_glass/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/invocations/break_glass/Dockerfile index eaffb94f198..e0c93a0ab5e 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/invocations/break_glass/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/invocations/break_glass/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/invocations/break_glass/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/invocations/break_glass/agent.manifest.yaml index ac71182ab62..643cac9bcbe 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/invocations/break_glass/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/invocations/break_glass/agent.manifest.yaml @@ -15,6 +15,8 @@ template: - protocol: invocations version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" resources: diff --git a/python/samples/04-hosting/foundry-hosted-agents/invocations/break_glass/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/invocations/break_glass/agent.yaml index b42a6df045a..db1f3d8fcf7 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/invocations/break_glass/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/invocations/break_glass/agent.yaml @@ -7,3 +7,6 @@ protocols: resources: cpu: "0.25" memory: "0.5Gi" +environment_variables: + - name: PYTHONNOUSERSITE + value: "1" diff --git a/python/samples/04-hosting/foundry-hosted-agents/invocations/telegram/azure.yaml b/python/samples/04-hosting/foundry-hosted-agents/invocations/telegram/azure.yaml index d5989239be9..e572952c896 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/invocations/telegram/azure.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/invocations/telegram/azure.yaml @@ -20,6 +20,8 @@ services: Telegram bot routed through API Management to an Agent Framework agent using the Foundry Invocations 2.0 protocol. environmentVariables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} - name: AZURE_COSMOS_ENDPOINT diff --git a/python/samples/04-hosting/foundry-hosted-agents/invocations/telegram/tests/test_infrastructure.py b/python/samples/04-hosting/foundry-hosted-agents/invocations/telegram/tests/test_infrastructure.py index ba3153605f8..bc18af66514 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/invocations/telegram/tests/test_infrastructure.py +++ b/python/samples/04-hosting/foundry-hosted-agents/invocations/telegram/tests/test_infrastructure.py @@ -22,6 +22,7 @@ def test_direct_code_invocations_2_configuration() -> None: "runtime": "python_3_13", } assert service["protocols"] == [{"protocol": "invocations", "version": "2.0.0"}] + assert {"name": "PYTHONNOUSERSITE", "value": "1"} in service["environmentVariables"] def test_dependencies_use_sample_local_pyproject() -> None: diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/azure_search_rag/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/azure_search_rag/Dockerfile index 0cc939d9b3a..75e65e952d4 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/azure_search_rag/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/azure_search_rag/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/azure_search_rag/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/azure_search_rag/agent.manifest.yaml index 5167dfcaef9..d8c0cd58afc 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/azure_search_rag/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/azure_search_rag/agent.manifest.yaml @@ -18,6 +18,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" - name: AZURE_SEARCH_ENDPOINT diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/azure_search_rag/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/azure_search_rag/agent.yaml index 7ffb60057c5..3b27a586335 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/azure_search_rag/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/azure_search_rag/agent.yaml @@ -8,6 +8,8 @@ resources: cpu: "0.25" memory: "0.5Gi" environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} - name: AZURE_SEARCH_ENDPOINT diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/basic/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/basic/Dockerfile index eaffb94f198..e0c93a0ab5e 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/basic/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/basic/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/basic/README.md b/python/samples/04-hosting/foundry-hosted-agents/responses/basic/README.md index d9b46fcd7f0..2ee19c316a4 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/basic/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/basic/README.md @@ -23,7 +23,8 @@ downstream service ID. Run one entry point at a time. The deployment manifest targets `main.py`; select another script to deploy a different mode. Set `FOUNDRY_PROJECT_ENDPOINT` and `FOUNDRY_MODEL` in `.env`, then run `python main.py`. -Follow the [parent hosting guide](../../README.md) for local and deployed setup. +First apply the [Python startup configuration](../../README.md#python-startup-configuration) +in the launching shell. Follow the [parent hosting guide](../../README.md) for local and deployed setup. ## Outer response storage and background diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/basic/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/basic/agent.manifest.yaml index 9547802be6a..ea63bcc064f 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/basic/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/basic/agent.manifest.yaml @@ -15,6 +15,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" resources: diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/basic/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/basic/agent.yaml index 9408da5eb40..cfdcee9aed6 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/basic/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/basic/agent.yaml @@ -8,5 +8,7 @@ resources: cpu: "0.25" memory: "0.5Gi" environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/custom_storage/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/custom_storage/Dockerfile index 0cc939d9b3a..75e65e952d4 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/custom_storage/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/custom_storage/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/custom_storage/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/custom_storage/agent.manifest.yaml index a045ba5333e..77239958fae 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/custom_storage/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/custom_storage/agent.manifest.yaml @@ -15,6 +15,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" - name: AZURE_COSMOS_ENDPOINT diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/custom_storage/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/custom_storage/agent.yaml index 4f8a99e5d34..84246f6ed1a 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/custom_storage/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/custom_storage/agent.yaml @@ -8,6 +8,8 @@ resources: cpu: "0.25" memory: "0.5Gi" environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} - name: AZURE_COSMOS_ENDPOINT diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/declarative_customer_support/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/declarative_customer_support/Dockerfile index 82316e2210b..74662ab3a92 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/declarative_customer_support/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/declarative_customer_support/Dockerfile @@ -6,6 +6,8 @@ FROM mcr.microsoft.com/dotnet/runtime:10.0 AS dotnet FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app # libicu is required by the .NET runtime for globalization support. diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/declarative_customer_support/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/declarative_customer_support/agent.manifest.yaml index 584120c871b..ff57ec0972d 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/declarative_customer_support/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/declarative_customer_support/agent.manifest.yaml @@ -17,6 +17,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" resources: diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/declarative_customer_support/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/declarative_customer_support/agent.yaml index 44ad3ede5b6..340cc05b933 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/declarative_customer_support/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/declarative_customer_support/agent.yaml @@ -8,5 +8,7 @@ resources: cpu: '0.25' memory: '0.5Gi' environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/files/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/files/Dockerfile index eaffb94f198..e0c93a0ab5e 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/files/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/files/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/files/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/files/agent.manifest.yaml index 01576e0e7f2..ab4f471e967 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/files/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/files/agent.manifest.yaml @@ -15,6 +15,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" - name: TOOLBOX_NAME diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/files/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/files/agent.yaml index 816e6cc15f1..b7189c871a4 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/files/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/files/agent.yaml @@ -8,6 +8,8 @@ resources: cpu: "0.25" memory: "0.5Gi" environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} - name: TOOLBOX_NAME diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_memory/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_memory/Dockerfile index 0cc939d9b3a..75e65e952d4 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_memory/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_memory/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_memory/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_memory/agent.manifest.yaml index 060e96adec7..0debe4ea604 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_memory/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_memory/agent.manifest.yaml @@ -18,6 +18,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" - name: MEMORY_STORE_NAME diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_memory/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_memory/agent.yaml index 53691375eee..80822778b66 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_memory/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_memory/agent.yaml @@ -8,6 +8,8 @@ resources: cpu: "0.25" memory: "0.5Gi" environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} - name: MEMORY_STORE_NAME diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/Dockerfile index 6a5bde6d263..eca43e28f91 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* WORKDIR /app diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/README.md b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/README.md index 78393322a1f..b5659f6a1af 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/README.md @@ -195,9 +195,13 @@ azd deploy --all ``` ```bash +export PYTHONNOUSERSITE=1 azd ai agent run ``` +For other shells and deployment settings, see the +[Python startup configuration](../../README.md#python-startup-configuration). + The agent host will start on `http://localhost:8088`. #### Invoke the local agent diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/agent.manifest.yaml index 770bb0100ff..6fa0881dd4c 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/agent.manifest.yaml @@ -15,6 +15,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" - name: TOOLBOX_ENDPOINT diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/agent.yaml index 3711356799e..0b24c0a77dd 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/agent.yaml @@ -7,6 +7,8 @@ resources: cpu: "0.25" memory: 0.5Gi environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} - name: TOOLBOX_ENDPOINT diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox_mcp_skills/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox_mcp_skills/Dockerfile index 12c4791bc9f..cfa20f498d0 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox_mcp_skills/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox_mcp_skills/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* WORKDIR /app diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox_mcp_skills/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox_mcp_skills/agent.manifest.yaml index 148e7ad11fa..83ce4709c9b 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox_mcp_skills/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox_mcp_skills/agent.manifest.yaml @@ -27,6 +27,8 @@ template: cpu: "0.25" memory: 0.5Gi environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" - name: TOOLBOX_ENDPOINT diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox_mcp_skills/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox_mcp_skills/agent.yaml index 75d676ed187..76736ecf0ea 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox_mcp_skills/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox_mcp_skills/agent.yaml @@ -8,6 +8,8 @@ resources: cpu: "0.25" memory: 0.5Gi environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} - name: TOOLBOX_ENDPOINT diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/mcp/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/mcp/Dockerfile index eaffb94f198..e0c93a0ab5e 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/mcp/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/mcp/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/mcp/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/mcp/agent.manifest.yaml index 70eae4a779f..c797d505173 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/mcp/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/mcp/agent.manifest.yaml @@ -15,6 +15,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" - name: GITHUB_PAT diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/mcp/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/mcp/agent.yaml index 5f9fb3d6add..3fc91eb2f7d 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/mcp/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/mcp/agent.yaml @@ -7,6 +7,8 @@ resources: cpu: "0.25" memory: 0.5Gi environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} - name: GITHUB_PAT diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/Dockerfile index 514bc9a0d02..bd1e3b62837 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + # Bring in the `uv` binary from a pinned Astral image. Update this tag intentionally; # `latest` would make rebuilds non-deterministic. COPY --from=ghcr.io/astral-sh/uv:0.11.6 /uv /uvx /usr/local/bin/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/README.md b/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/README.md index 1d5751c7d6a..7180f667ba1 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/README.md @@ -74,9 +74,13 @@ Set the environment variables described in the the dependencies declared in the script: ```bash +export PYTHONNOUSERSITE=1 uv run --script --prerelease=allow main.py ``` +For other shells and deployment settings, see the +[Python startup configuration](../../README.md#python-startup-configuration). + Additional sample imports belong in inline script metadata, not a workspace, package or sample `pyproject.toml`. Before the coordinated hosting beta is published, use the current workspace's installed packages diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/agent.manifest.yaml index cf678721b52..4918a2801f0 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/agent.manifest.yaml @@ -16,6 +16,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" - name: ENABLE_INSTRUMENTATION diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/agent.yaml index 041f5a5745a..bf07346085c 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/agent.yaml @@ -7,6 +7,8 @@ resources: cpu: "0.25" memory: 0.5Gi environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} - name: ENABLE_INSTRUMENTATION diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/observability/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/observability/Dockerfile index eaffb94f198..e0c93a0ab5e 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/observability/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/observability/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/observability/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/observability/agent.manifest.yaml index 2d5f20c3d86..e5f14b948b4 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/observability/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/observability/agent.manifest.yaml @@ -15,6 +15,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" - name: ENABLE_SENSITIVE_DATA diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/observability/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/observability/agent.yaml index 6ce2a78704a..edda4f822c9 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/observability/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/observability/agent.yaml @@ -8,6 +8,8 @@ resources: cpu: "0.25" memory: "0.5Gi" environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} - name: ENABLE_SENSITIVE_DATA diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/Dockerfile index eaffb94f198..e0c93a0ab5e 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/agent.manifest.yaml index 7502e04fc2f..a29d2795fe3 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/agent.manifest.yaml @@ -16,3 +16,6 @@ template: protocols: - protocol: responses version: 2.0.0 + environment_variables: + - name: PYTHONNOUSERSITE + value: "1" diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/agent.yaml index 09728900fe2..685a4cce3c0 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/resilient_long_running_workflow/agent.yaml @@ -7,3 +7,6 @@ protocols: resources: cpu: "0.25" memory: "0.5Gi" +environment_variables: + - name: PYTHONNOUSERSITE + value: "1" diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/steerable_long_running_agent/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/steerable_long_running_agent/Dockerfile index 0cc939d9b3a..75e65e952d4 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/steerable_long_running_agent/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/steerable_long_running_agent/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/steerable_long_running_agent/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/steerable_long_running_agent/agent.manifest.yaml index d9a59b8b978..17e2dff3bb1 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/steerable_long_running_agent/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/steerable_long_running_agent/agent.manifest.yaml @@ -17,6 +17,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" resources: diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/steerable_long_running_agent/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/steerable_long_running_agent/agent.yaml index eb5b5340403..da863470a53 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/steerable_long_running_agent/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/steerable_long_running_agent/agent.yaml @@ -8,5 +8,7 @@ resources: cpu: "0.25" memory: "0.5Gi" environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/tools/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/tools/Dockerfile index eaffb94f198..e0c93a0ab5e 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/tools/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/tools/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/tools/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/tools/agent.manifest.yaml index 42840f80d34..f3f05109abf 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/tools/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/tools/agent.manifest.yaml @@ -15,6 +15,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" resources: diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/tools/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/tools/agent.yaml index 2a27cd4f002..4039a89d058 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/tools/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/tools/agent.yaml @@ -7,5 +7,7 @@ resources: cpu: "0.25" memory: 0.5Gi environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/Dockerfile b/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/Dockerfile index eaffb94f198..e0c93a0ab5e 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/Dockerfile +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONNOUSERSITE=1 + WORKDIR /app COPY . user_agent/ diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/README.md b/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/README.md index 096980b8f58..5a97093d17d 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/README.md @@ -26,11 +26,15 @@ remain stable. `store=False` is one-shot and cannot expose a resumable pause. Run locally from this directory with the current workspace: ```bash +export PYTHONNOUSERSITE=1 uv run --no-sync python main.py # or: uv run --no-sync python approval.py ``` +For other shells and deployment settings, see the +[Python startup configuration](../../README.md#python-startup-configuration). + Example typed request: ```bash diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/agent.manifest.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/agent.manifest.yaml index 6305ab4d792..028c8a97e39 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/agent.manifest.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/agent.manifest.yaml @@ -15,6 +15,8 @@ template: - protocol: responses version: 2.0.0 environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: "{{AZURE_AI_MODEL_DEPLOYMENT_NAME}}" resources: diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/agent.yaml b/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/agent.yaml index db73258994b..941b65870bc 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/agent.yaml +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/agent.yaml @@ -7,5 +7,7 @@ resources: cpu: "0.25" memory: 0.5Gi environment_variables: + - name: PYTHONNOUSERSITE + value: "1" - name: AZURE_AI_MODEL_DEPLOYMENT_NAME value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME} diff --git a/skills/agent-framework-builder-python/references/hosting-and-deployment.md b/skills/agent-framework-builder-python/references/hosting-and-deployment.md index 480c09fc374..25eaa4dfe0b 100644 --- a/skills/agent-framework-builder-python/references/hosting-and-deployment.md +++ b/skills/agent-framework-builder-python/references/hosting-and-deployment.md @@ -35,6 +35,17 @@ Verify the entry point imports, required packages and external files are include and storage ownership are documented, request-owned resources are cleaned up, and no local credentials or caches enter the deployment package. +For Python Foundry hosted agents, configure `PYTHONNOUSERSITE=1` in the +deployment environment before Python starts, and in the Dockerfile for images +also launched without that deployment definition. Set it in the launching +shell for local runs; setting it inside application code or a `.env` file +loaded by Python is too late for startup. Install dependencies in a virtual +environment or image system site-packages, not with `pip install --user`. +This customer-configured setting disables Python user-site loading, not all +code execution or other language runtimes. Redeploy a new agent version to +apply it to existing deployments. See the +[maintained sample startup guidance](https://github.com/microsoft/agent-framework/tree/main/python/samples/04-hosting/foundry-hosted-agents#python-startup-configuration). + ## Deploy to Microsoft Foundry Foundry deployment commands, manifests, prerequisites, and injected configuration change independently from Agent From 656843346170e2984393660dbc79334b12e00b98 Mon Sep 17 00:00:00 2001 From: Shivakishore14 Date: Fri, 23 Oct 2026 11:13:56 +0000 Subject: [PATCH 2/2] docs(hosting): keep python startup in deployment configuration Remove startup-variable shell exports and local command prerequisites. Preserve Dockerfile and deployment environment configuration. Authored-by: GitHub Copilot CLI v1.0.102 Model: GPT-6.1 Sol (gpt-6.1-sol) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../container/hyperlight_codeact/README.md | 6 ++-- .../foundry-hosted-agents/README.md | 28 +++---------------- .../invocations/basic/README.md | 3 +- .../responses/basic/README.md | 5 ++-- .../responses/foundry_toolbox/README.md | 3 +- .../responses/monty_codeact/README.md | 3 +- .../responses/workflows/README.md | 3 +- .../references/hosting-and-deployment.md | 7 ++--- 8 files changed, 17 insertions(+), 41 deletions(-) diff --git a/python/samples/04-hosting/container/hyperlight_codeact/README.md b/python/samples/04-hosting/container/hyperlight_codeact/README.md index 1c434d24c58..7d6e8a04614 100644 --- a/python/samples/04-hosting/container/hyperlight_codeact/README.md +++ b/python/samples/04-hosting/container/hyperlight_codeact/README.md @@ -68,9 +68,9 @@ Follow the instructions in the [Running the Agent Host Locally](../../foundry-hosted-agents//README.md#running-the-agent-host-locally) section of the README in the Foundry Hosted Agent directory. -Apply the [Python startup configuration](../../foundry-hosted-agents/README.md#python-startup-configuration) -before launching the host. The image and hosted deployment definitions set -`PYTHONNOUSERSITE=1`; this controls Python user-site loading only and does not +The image and hosted deployment definitions set `PYTHONNOUSERSITE=1`; see the +[Python startup configuration](../../foundry-hosted-agents/README.md#python-startup-configuration). +This controls Python user-site loading only and does not change the hypervisor requirement or make this sample supported on the default Foundry runtime. diff --git a/python/samples/04-hosting/foundry-hosted-agents/README.md b/python/samples/04-hosting/foundry-hosted-agents/README.md index 13dd0f0ef85..f2721e7c83e 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/README.md @@ -5,6 +5,7 @@ This directory contains samples that demonstrate how to use hosted [Agent Framew > [IMPORTANT] Migrating from Protocol version 1.0.0 to 2.0.0: Foundry Hosting Agents service has been updated to use Protocol version 2.0.0. If your application is using Protocol version 1.0.0, please upgrade to Protocol version 2.0.0 in your `agent.manifest.yaml` or `agent.yaml` and upgrade to the latest `agent-framework-foundry-hosting` package. `agent-framework-foundry-hosting==1.0.0a260625` is the last version that supports Protocol version 1.0.0. > > The `agent-framework-foundry-hosting` Python API surface is intended to remain stable, but protocol 1.0.0 and 2.0.0 are incompatible. + ## Python startup configuration The deployment YAML files in these samples explicitly configure @@ -24,25 +25,9 @@ Install dependencies in a virtual environment or the container image's system site-packages, not with `pip install --user`. The samples' `pip` and `uv` installation paths do not require user-site packages. -For **all local entry points and their restarts**, set the variable in the -launching shell before running Python, `uv run`, or `azd ai agent run`: - -```bash -# bash/zsh -export PYTHONNOUSERSITE=1 -``` - -```powershell -$env:PYTHONNOUSERSITE = "1" -``` - -```cmd -set PYTHONNOUSERSITE=1 -``` - -Repeat this setup in each new terminal. Setting `os.environ` or loading a -`.env` file from application code is too late for Python startup. Local shell -configuration does not replace the remote deployment's environment variables. +Keep this setting in the deployment environment or Python Dockerfile, rather +than adding it to individual run commands. Setting `os.environ` or loading a +`.env` file from application code is too late for Python startup. ## Samples @@ -178,7 +163,6 @@ This will create the following Azure resources: ```bash export FOUNDRY_PROJECT_ENDPOINT="https://.services.ai.azure.com/api/projects/" export FOUNDRY_MODEL="" -export PYTHONNOUSERSITE=1 # And any other environment variables required by the sample ``` @@ -187,7 +171,6 @@ Or in PowerShell: ```powershell $env:FOUNDRY_PROJECT_ENDPOINT="https://.services.ai.azure.com/api/projects/" $env:FOUNDRY_MODEL="" -$env:PYTHONNOUSERSITE="1" # And any other environment variables required by the sample ``` @@ -276,9 +259,6 @@ cd agent-framework/python/samples/04-hosting/foundry-hosted-agents/responses/bas #### Running the Agent Host -First apply the [shell startup configuration](#python-startup-configuration) -in the current terminal, including when using `uv run` instead of `python`: - ```bash python main.py ``` diff --git a/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/README.md b/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/README.md index 450db99619f..578b6c12a31 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/invocations/basic/README.md @@ -104,11 +104,10 @@ Use the current workspace until the coordinated hosting beta containing the native workflow API is published. From `python/`, run: ```bash -export PYTHONNOUSERSITE=1 uv run --no-sync python samples/04-hosting/foundry-hosted-agents/invocations/basic/workflow.py ``` -For other shells and deployment settings, see the +For deployment environment settings, see the [Python startup configuration](../../README.md#python-startup-configuration). After that release, the script's PEP 723 metadata also supports diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/basic/README.md b/python/samples/04-hosting/foundry-hosted-agents/responses/basic/README.md index 2ee19c316a4..6ba33391f7d 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/basic/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/basic/README.md @@ -23,8 +23,9 @@ downstream service ID. Run one entry point at a time. The deployment manifest targets `main.py`; select another script to deploy a different mode. Set `FOUNDRY_PROJECT_ENDPOINT` and `FOUNDRY_MODEL` in `.env`, then run `python main.py`. -First apply the [Python startup configuration](../../README.md#python-startup-configuration) -in the launching shell. Follow the [parent hosting guide](../../README.md) for local and deployed setup. +For deployment environment configuration, see the +[Python startup configuration](../../README.md#python-startup-configuration). +Follow the [parent hosting guide](../../README.md) for local and deployed setup. ## Outer response storage and background diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/README.md b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/README.md index b5659f6a1af..036887e84d7 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/foundry_toolbox/README.md @@ -195,11 +195,10 @@ azd deploy --all ``` ```bash -export PYTHONNOUSERSITE=1 azd ai agent run ``` -For other shells and deployment settings, see the +For deployment environment settings, see the [Python startup configuration](../../README.md#python-startup-configuration). The agent host will start on `http://localhost:8088`. diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/README.md b/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/README.md index 7180f667ba1..d1e6a2f0ebf 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/monty_codeact/README.md @@ -74,11 +74,10 @@ Set the environment variables described in the the dependencies declared in the script: ```bash -export PYTHONNOUSERSITE=1 uv run --script --prerelease=allow main.py ``` -For other shells and deployment settings, see the +For deployment environment settings, see the [Python startup configuration](../../README.md#python-startup-configuration). Additional sample imports belong in inline script metadata, not a workspace, diff --git a/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/README.md b/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/README.md index 5a97093d17d..cf895801b44 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/responses/workflows/README.md @@ -26,13 +26,12 @@ remain stable. `store=False` is one-shot and cannot expose a resumable pause. Run locally from this directory with the current workspace: ```bash -export PYTHONNOUSERSITE=1 uv run --no-sync python main.py # or: uv run --no-sync python approval.py ``` -For other shells and deployment settings, see the +For deployment environment settings, see the [Python startup configuration](../../README.md#python-startup-configuration). Example typed request: diff --git a/skills/agent-framework-builder-python/references/hosting-and-deployment.md b/skills/agent-framework-builder-python/references/hosting-and-deployment.md index 25eaa4dfe0b..8b0dc4afb1e 100644 --- a/skills/agent-framework-builder-python/references/hosting-and-deployment.md +++ b/skills/agent-framework-builder-python/references/hosting-and-deployment.md @@ -37,10 +37,9 @@ the deployment package. For Python Foundry hosted agents, configure `PYTHONNOUSERSITE=1` in the deployment environment before Python starts, and in the Dockerfile for images -also launched without that deployment definition. Set it in the launching -shell for local runs; setting it inside application code or a `.env` file -loaded by Python is too late for startup. Install dependencies in a virtual -environment or image system site-packages, not with `pip install --user`. +also launched without that deployment definition. Setting it inside application +code or a `.env` file loaded by Python is too late for startup. Install dependencies +in a virtual environment or image system site-packages, not with `pip install --user`. This customer-configured setting disables Python user-site loading, not all code execution or other language runtimes. Redeploy a new agent version to apply it to existing deployments. See the