From 923991bf4a4bea7d32e258fd33a1855ef08dcd8b Mon Sep 17 00:00:00 2001 From: Sellakumaran Kanagarathnam Date: Sat, 8 Nov 2025 14:54:47 -0800 Subject: [PATCH 1/7] The project starts locally. --- .../sample-agent/.env.template | 26 +-- .../sample-agent/MockAcitivity.json | 28 +++ .../sample-agent/SETUP-GUIDE.md | 160 ++++++++++++++++++ .../sample-agent/pyproject.toml | 24 +-- 4 files changed, 211 insertions(+), 27 deletions(-) create mode 100644 python/agent-framework/sample-agent/MockAcitivity.json create mode 100644 python/agent-framework/sample-agent/SETUP-GUIDE.md diff --git a/python/agent-framework/sample-agent/.env.template b/python/agent-framework/sample-agent/.env.template index 0fa2ede..fc6eefd 100644 --- a/python/agent-framework/sample-agent/.env.template +++ b/python/agent-framework/sample-agent/.env.template @@ -1,13 +1,14 @@ # This is a demo .env file +# Replace with your actual values -# OpenAI Configuration +# OpenAI Configuration OPENAI_API_KEY= OPENAI_MODEL=gpt-4o # MCP Server Configuration MCP_SERVER_PORT=8000 MCP_SERVER_HOST=localhost -MCP_PLATFORM_ENDPOINT=https://test.agent365.svc.cloud.dev.microsoft +MCP_PLATFORM_ENDPOINT=https://preprod.agent365.svc.cloud.dev.microsoft # Logging LOG_LEVEL=INFO @@ -16,18 +17,14 @@ LOG_LEVEL=INFO OBSERVABILITY_SERVICE_NAME=agent-framework-sample OBSERVABILITY_SERVICE_NAMESPACE=agent-framework.samples -# Environment Configuration +# Environment and Authentication # OBO Default-6e8b84fa-ae41-4a00-9ad1-934b73e5d73c -# Agentic auth - Default-5369a35c-46a5-4677-8ff9-2e65587654e7 +# agentic auth - Default-5369a35c-46a5-4677-8ff9-2e65587654e7 ENV_ID= BEARER_TOKEN= -# Authentication Mode USE_AGENTIC_AUTH=true -# Agentic Authentication Scope -AGENTIC_AUTH_SCOPE=05879165-0320-489e-b644-f72b33f3edf0/.default - AGENT_ID= # Agent365 Agentic Authentication Configuration @@ -38,10 +35,9 @@ CONNECTIONS__SERVICE_CONNECTION__SETTINGS__SCOPES=https://api.botframework.com/. AGENTAPPLICATION__USERAUTHORIZATION__HANDLERS__AGENTIC__SETTINGS__TYPE=AgenticUserAuthorization AGENTAPPLICATION__USERAUTHORIZATION__HANDLERS__AGENTIC__SETTINGS__SCOPES=https://graph.microsoft.com/.default -AGENTAPPLICATION__USERAUTHORIZATION__HANDLERS__AGENTIC__SETTINGS__ALTERNATEBLUEPRINTCONNECTIONNAME=https://graph.microsoft.com/.default -CONNECTIONSMAP_0_SERVICEURL=* -CONNECTIONSMAP_0_CONNECTION=SERVICE_CONNECTION +CONNECTIONSMAP__0__SERVICEURL=* +CONNECTIONSMAP__0_CONNECTION=SERVICE_CONNECTION # Optional: Server Configuration PORT=3978 @@ -54,9 +50,5 @@ AZURE_OPENAI_API_VERSION="2024-02-01" # Required for observability SDK ENABLE_OBSERVABILITY=true -ENABLE_A365_OBSERVABILITY_EXPORTER=false -PYTHON_ENVIRONMENT=development - -# Enable otel logs on AgentFramework SDK. Required for auto instrumentation -ENABLE_OTEL=true -ENABLE_SENSITIVE_DATA=true \ No newline at end of file +ENABLE_KAIRO_EXPORTER=false +PYTHON_ENVIRONMENT=development \ No newline at end of file diff --git a/python/agent-framework/sample-agent/MockAcitivity.json b/python/agent-framework/sample-agent/MockAcitivity.json new file mode 100644 index 0000000..3e0e055 --- /dev/null +++ b/python/agent-framework/sample-agent/MockAcitivity.json @@ -0,0 +1,28 @@ +{ + "id": "94a8b018-7365-43b9-b9a9-bc7fc67be329", + "timestamp": "2025-09-18T22:21:54.612Z", + "channelId": "msteams", + "serviceUrl": "http://localhost:56150/_connector", + "recipient": { + "id": "agent365demo.sellak.userNov7_1@ztaitest12.onmicrosoft.com", + "name": "Agent365 Sellak Demo User Instance Nov7_1", + "agenticUserId": "7a4b6845-8a2c-4dfd-aeb9-fb9c5aa0027b", + "agenticAppId": "5d5288ae-72b5-4f2c-a92d-32ebcda338f3", + "tenantId": "e8a85347-fb53-4a91-9267-c616cbe1fd16", + "role": "agenticUser" + }, + "from": { + "id": "29:1sH5NArUwkWAX-VmfHH3cfem2S89f2nB0N6aJ5zEjBoxT17fhSMdlYu_55ZyR8_OKFxS3BMnaGldHH3wdf_9K4Q", + "name": "Josjoy", + "aadObjectId": "03f4dd93-7e1e-41d6-bf7c-f211f9e96a13", + "role": "user" + }, + "conversation": { + "id": "personal-chat-id", + "conversationType": "personal", + "tenantId": "00000000-0000-0000-0000-0000000000001" + }, + "type": "message", + "text": "Send Email to sellak@microsoft.com with detailed Comparison between NordicTrack Commercial 2450 vs. Peloton Tread treadmills. It should be atleast 200 words. Do not ask follow up questions and directly send the email. Use formal writing style. Sign off as A365TestingAgent Py Ztai A365-samples" +} + \ No newline at end of file diff --git a/python/agent-framework/sample-agent/SETUP-GUIDE.md b/python/agent-framework/sample-agent/SETUP-GUIDE.md new file mode 100644 index 0000000..f51e92d --- /dev/null +++ b/python/agent-framework/sample-agent/SETUP-GUIDE.md @@ -0,0 +1,160 @@ +# Quick Setup Guide + +Get the A365 Python SDK sample running in 7 simple steps. + +## Setup Steps + +### 1. Verify prerequisites +First, ensure you have the required Microsoft Agent365 packages: + +```powershell +# Navigate to the agent-framework directory (parent of sample-agent) +cd .. + +# Check if dist folder exists with required wheel files +ls dist +``` + +**If the dist folder doesn't exist or is empty:** +- Create the `dist` folder: `mkdir dist` +- Download or copy the required `.whl` files to the `dist` folder: + - `microsoft_agents_a365_tooling-*.whl` + - `microsoft_agents_a365_tooling_extensions_agentframework-*.whl` + - `microsoft_agents_a365_observability_core-*.whl` + - `microsoft_agents_a365_observability_extensions_agent_framework-*.whl` + - `microsoft_agents_a365_runtime-*.whl` + - `microsoft_agents_a365_notifications-*.whl` + +**✅ Success Check**: The `dist` folder should contain the Microsoft Agent365 wheel files. + +```powershell +# Return to sample-agent directory for next steps +cd sample-agent +``` + +### 2. Set up environment configuration +Open PowerShell **in VS Code** (Terminal → New Terminal) and navigate to the sample-agent directory: + +```powershell +# Navigate to the sample-agent directory (where this README is located) +# Make sure you're in the sample-agent folder +cd sample-agent + +# Copy the environment template +copy .env.template .env +``` + +### 3. Update environment variables +Open the newly created `.env` file and update the following values: + +``` +AZURE_OPENAI_API_KEY= +AZURE_OPENAI_ENDPOINT= +AZURE_OPENAI_DEPLOYMENT= +AZURE_OPENAI_API_VERSION="2024-02-01" +``` + +### 4. Install uv +uv is a fast Python package manager. Open PowerShell **in VS Code** (Terminal → New Terminal) and run: + +```powershell +# Install uv +powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" + +# Add uv to PATH for this session (only if not already there) +if ($env:PATH -notlike "*$env:USERPROFILE\.local\bin*") { + $env:PATH += ";$env:USERPROFILE\.local\bin" +} + +# Test that uv works +uv --version +``` + +### 5. Set up the project +Continue in the same terminal (make sure you're still in the sample-agent directory): + +```powershell +# Verify you're in the right directory - you should see pyproject.toml +ls pyproject.toml + +# First, check if Python is installed +python --version +``` + +**If Python is not found:** +- Download and install Python 3.11+ from https://python.org +- Make sure to check "Add Python to PATH" during installation +- Restart VS Code and try again + +**If Python is found, continue:** +```powershell +# Create virtual environment with pip included +uv venv .venv --seed + +# Activate the virtual environment +.\.venv\Scripts\Activate.ps1 + +# Verify setup - you should see (.venv) in your prompt +python --version +``` + +**✅ Success Check**: Your terminal shows `(.venv)` at the beginning and you can see pyproject.toml in the directory + +### 6. Install dependencies + +Due to version constraints in the wheel files, we need to install in steps: + +```powershell +# Install the main package without dependencies +uv pip install -e . --find-links ../dist --pre --no-deps + +# Install the remaining dependencies +uv pip install agent-framework-azure-ai microsoft-agents-hosting-aiohttp microsoft-agents-hosting-core microsoft-agents-authentication-msal microsoft-agents-activity azure-identity python-dotenv aiohttp "uvicorn[standard]>=0.20.0" "fastapi>=0.100.0" "httpx>=0.24.0" "pydantic>=2.0.0" "typing-extensions>=4.0.0" wrapt --find-links ../dist --pre + +# Install the local Microsoft Agent365 packages +uv pip install microsoft-agents-a365-tooling microsoft-agents-a365-tooling-extensions-agentframework microsoft-agents-a365-observability-core microsoft-agents-a365-observability-extensions-agent-framework microsoft-agents-a365-runtime microsoft-agents-a365-notifications --find-links ../dist --pre --no-deps +``` + +**Important**: You may see some warning messages about dependencies. **This is normal and expected** - the agent will work correctly. + +**✅ Success Check**: +- First command: "Installed 1 package" +- Second command: "Installed X packages" (multiple packages from PyPI) +- Third command: "Installed X packages" (Microsoft Agent365 packages) + +### 7. Start the agent +```powershell +python start_with_generic_host.py +``` + +**✅ Success Check**: You should see: +``` +🚀 Starting server on localhost:3978 +🎯 Ready for testing! +======== Running on http://localhost:3978 ======== +``` + +## Troubleshooting + +**"python is not recognized"** → Install Python 3.11+ from python.org and check "Add Python to PATH" + +**"uv not found"** → Restart your terminal and try step 1 again + +**"No module named 'dotenv'"** → Try: `uv pip install python-dotenv` + +**"No module named..."** → Make sure you see `(.venv)` in your prompt and that all three installation commands in step 6 completed successfully. If you get specific missing module errors, install them individually: +```powershell +# For common missing modules, try: +uv pip install wrapt opentelemetry-instrumentation opentelemetry-instrumentation-aiohttp-client opentelemetry-instrumentation-fastapi +# or if that fails, try: +uv pip install wrapt opentelemetry-api opentelemetry-sdk opentelemetry-instrumentation-aiohttp +``` + +**Dependency conflict warnings** → These are expected! Continue with the next step - the agent will work fine + +**"No solution found when resolving dependencies"** → Make sure you're using the three-step installation process in step 6 and that the dist folder exists with wheel files + +**Agent won't start** → Check you're in the sample-agent directory and that all installation steps completed successfully + +## Done! +Your agent is now running and ready for testing. Configuration values will be provided during the bug bash session. \ No newline at end of file diff --git a/python/agent-framework/sample-agent/pyproject.toml b/python/agent-framework/sample-agent/pyproject.toml index 159e43f..b74389d 100644 --- a/python/agent-framework/sample-agent/pyproject.toml +++ b/python/agent-framework/sample-agent/pyproject.toml @@ -36,13 +36,13 @@ dependencies = [ "typing-extensions>=4.0.0", # Local packages from local index - # - Update package versions to match your built wheels - "microsoft_agents_a365_tooling >= 0.1.0", - "microsoft_agents_a365_tooling_extensions_agentframework >= 0.1.0", - "microsoft_agents_a365_observability_core >= 0.1.0", - "microsoft_agents_a365_observability_extensions_agent_framework >= 0.1.0", - "microsoft_agents_a365_runtime >= 0.1.0", - "microsoft_agents_a365_notifications >= 0.1.0", + # - Use version ranges that work with both dev versions and future production releases + "microsoft_agents_a365_tooling >= 0.1.0.dev11, < 999.0.0", + "microsoft_agents_a365_tooling_extensions_agentframework >= 0.1.0.dev11, < 999.0.0", + "microsoft_agents_a365_observability_core >= 0.1.0.dev11, < 999.0.0", + "microsoft_agents_a365_observability_extensions_agent_framework >= 0.1.0.dev11, < 999.0.0", + "microsoft_agents_a365_runtime >= 0.1.0.dev11, < 999.0.0", + "microsoft_agents_a365_notifications >= 0.1.0.dev11, < 999.0.0", ] requires-python = ">=3.11" @@ -54,8 +54,8 @@ url = "https://pypi.org/simple" default = true [[tool.uv.index]] -name = "microsoft_kairo" -url = "../../../../python/dist" +name = "microsoft_agents" +url = "../dist" format = "flat" [build-system] @@ -66,7 +66,11 @@ build-backend = "hatchling.build" packages = ["."] [tool.uv] -dev-dependencies = [ +# Allow pre-release versions for dependencies that require them +prerelease = "allow" + +[dependency-groups] +dev = [ "pytest>=8.0", "pytest-asyncio>=0.24.0", "ruff>=0.1.0", From 6fca3e4ebf1ade2e70105309e4b6f63bd4e980de Mon Sep 17 00:00:00 2001 From: Sellakumaran Kanagarathnam Date: Sat, 8 Nov 2025 15:12:33 -0800 Subject: [PATCH 2/7] add missing _ --- python/agent-framework/sample-agent/.env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/agent-framework/sample-agent/.env.template b/python/agent-framework/sample-agent/.env.template index fc6eefd..b3164f7 100644 --- a/python/agent-framework/sample-agent/.env.template +++ b/python/agent-framework/sample-agent/.env.template @@ -37,7 +37,7 @@ AGENTAPPLICATION__USERAUTHORIZATION__HANDLERS__AGENTIC__SETTINGS__TYPE=AgenticUs AGENTAPPLICATION__USERAUTHORIZATION__HANDLERS__AGENTIC__SETTINGS__SCOPES=https://graph.microsoft.com/.default CONNECTIONSMAP__0__SERVICEURL=* -CONNECTIONSMAP__0_CONNECTION=SERVICE_CONNECTION +CONNECTIONSMAP__0__CONNECTION=SERVICE_CONNECTION # Optional: Server Configuration PORT=3978 From c568f2a65c2d48a748cb2e3b410de0e7faa829b0 Mon Sep 17 00:00:00 2001 From: Sellakumaran Kanagarathnam Date: Sat, 8 Nov 2025 21:51:06 -0800 Subject: [PATCH 3/7] Simplify installation and update dependency handling Simplified the installation process in `SETUP-GUIDE.md`: - Consolidated multiple installation commands into a single step. - Replaced explicit dependency installation with `requirements.txt`. - Updated success checks and troubleshooting instructions. Updated `pyproject.toml`: - Removed upper version constraints for Microsoft Agent365 packages. - Retained minimum version requirements to ensure compatibility. Improved documentation clarity and reduced redundancy. --- .../sample-agent/SETUP-GUIDE.md | 29 +++++++------------ .../sample-agent/pyproject.toml | 12 ++++---- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/python/agent-framework/sample-agent/SETUP-GUIDE.md b/python/agent-framework/sample-agent/SETUP-GUIDE.md index f51e92d..e52846e 100644 --- a/python/agent-framework/sample-agent/SETUP-GUIDE.md +++ b/python/agent-framework/sample-agent/SETUP-GUIDE.md @@ -18,6 +18,9 @@ ls dist **If the dist folder doesn't exist or is empty:** - Create the `dist` folder: `mkdir dist` - Download or copy the required `.whl` files to the `dist` folder: +- https://github.com/microsoft/Agent365-python/actions/runs/19200334217 + - Click on Artifacts - python-3.11 + - Download the zip file and extract the wheel files into the `dist` folder - `microsoft_agents_a365_tooling-*.whl` - `microsoft_agents_a365_tooling_extensions_agentframework-*.whl` - `microsoft_agents_a365_observability_core-*.whl` @@ -102,25 +105,17 @@ python --version ### 6. Install dependencies -Due to version constraints in the wheel files, we need to install in steps: +Due to version constraints in the wheel files, we install in two steps: ```powershell -# Install the main package without dependencies -uv pip install -e . --find-links ../dist --pre --no-deps - -# Install the remaining dependencies -uv pip install agent-framework-azure-ai microsoft-agents-hosting-aiohttp microsoft-agents-hosting-core microsoft-agents-authentication-msal microsoft-agents-activity azure-identity python-dotenv aiohttp "uvicorn[standard]>=0.20.0" "fastapi>=0.100.0" "httpx>=0.24.0" "pydantic>=2.0.0" "typing-extensions>=4.0.0" wrapt --find-links ../dist --pre - -# Install the local Microsoft Agent365 packages -uv pip install microsoft-agents-a365-tooling microsoft-agents-a365-tooling-extensions-agentframework microsoft-agents-a365-observability-core microsoft-agents-a365-observability-extensions-agent-framework microsoft-agents-a365-runtime microsoft-agents-a365-notifications --find-links ../dist --pre --no-deps -``` +### 3. Install dependencies +```powershell +uv pip install -e . --find-links ../dist --pre **Important**: You may see some warning messages about dependencies. **This is normal and expected** - the agent will work correctly. **✅ Success Check**: -- First command: "Installed 1 package" -- Second command: "Installed X packages" (multiple packages from PyPI) -- Third command: "Installed X packages" (Microsoft Agent365 packages) +- First command: "Installed X packages" (PyPI dependencies from requirements.txt) ### 7. Start the agent ```powershell @@ -142,12 +137,10 @@ python start_with_generic_host.py **"No module named 'dotenv'"** → Try: `uv pip install python-dotenv` -**"No module named..."** → Make sure you see `(.venv)` in your prompt and that all three installation commands in step 6 completed successfully. If you get specific missing module errors, install them individually: +**"No module named..."** → Make sure you see `(.venv)` in your prompt and that all three installation commands in step 6 completed successfully. Most missing dependencies should already be included in `requirements.txt`, but if you still get errors, you can install them individually: ```powershell -# For common missing modules, try: -uv pip install wrapt opentelemetry-instrumentation opentelemetry-instrumentation-aiohttp-client opentelemetry-instrumentation-fastapi -# or if that fails, try: -uv pip install wrapt opentelemetry-api opentelemetry-sdk opentelemetry-instrumentation-aiohttp +# For any additional missing modules: +uv pip install ``` **Dependency conflict warnings** → These are expected! Continue with the next step - the agent will work fine diff --git a/python/agent-framework/sample-agent/pyproject.toml b/python/agent-framework/sample-agent/pyproject.toml index b74389d..0f21f62 100644 --- a/python/agent-framework/sample-agent/pyproject.toml +++ b/python/agent-framework/sample-agent/pyproject.toml @@ -37,12 +37,12 @@ dependencies = [ # Local packages from local index # - Use version ranges that work with both dev versions and future production releases - "microsoft_agents_a365_tooling >= 0.1.0.dev11, < 999.0.0", - "microsoft_agents_a365_tooling_extensions_agentframework >= 0.1.0.dev11, < 999.0.0", - "microsoft_agents_a365_observability_core >= 0.1.0.dev11, < 999.0.0", - "microsoft_agents_a365_observability_extensions_agent_framework >= 0.1.0.dev11, < 999.0.0", - "microsoft_agents_a365_runtime >= 0.1.0.dev11, < 999.0.0", - "microsoft_agents_a365_notifications >= 0.1.0.dev11, < 999.0.0", + "microsoft_agents_a365_tooling >= 0.1.0.dev11", + "microsoft_agents_a365_tooling_extensions_agentframework >= 0.1.0.dev11", + "microsoft_agents_a365_observability_core >= 0.1.0.dev11", + "microsoft_agents_a365_observability_extensions_agent_framework >= 0.1.0.dev11", + "microsoft_agents_a365_runtime >= 0.1.0.dev11", + "microsoft_agents_a365_notifications >= 0.1.0.dev11", ] requires-python = ">=3.11" From ebaefd8ed9278f6d973e54f52aee02ff09dcb241 Mon Sep 17 00:00:00 2001 From: Sellakumaran Kanagarathnam Date: Sat, 8 Nov 2025 22:42:32 -0800 Subject: [PATCH 4/7] Update ToolingManifest and pyproject dependencies Enhanced `ToolingManifest.json` with new properties: - Added `url`, `scope`, and `audience` for `mcp_MailTools`. Updated `pyproject.toml`: - Set `version` to `0.1.0`. - Clarified AgentFramework SDK description. - Specified minimum versions for dependencies: - `microsoft-agents-hosting-aiohttp`, `microsoft-agents-hosting-core`, `microsoft-agents-authentication-msal`, `microsoft-agents-activity` (>=0.5.0). - `azure-identity` (>=1.25.0). - `python-dotenv` (>=1.0.0). - `aiohttp` (>=3.9.0). - Retained `uvicorn[standard]` and `fastapi` with existing minimum versions. These changes improve configuration, compatibility, and maintainability. --- .../sample-agent/ToolingManifest.json | 5 ++++- .../agent-framework/sample-agent/pyproject.toml | 16 ++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/python/agent-framework/sample-agent/ToolingManifest.json b/python/agent-framework/sample-agent/ToolingManifest.json index 9d5cacf..c7bc00b 100644 --- a/python/agent-framework/sample-agent/ToolingManifest.json +++ b/python/agent-framework/sample-agent/ToolingManifest.json @@ -2,7 +2,10 @@ "mcpServers": [ { "mcpServerName": "mcp_MailTools", - "mcpServerUniqueName": "mcp_MailTools" + "mcpServerUniqueName": "mcp_MailTools", + "url": "https://preprod.agent365.svc.cloud.dev.microsoft/agents/servers/mcp_MailTools", + "scope": "McpServers.Mail.All", + "audience": "05879165-0320-489e-b644-f72b33f3edf0" } ] } \ No newline at end of file diff --git a/python/agent-framework/sample-agent/pyproject.toml b/python/agent-framework/sample-agent/pyproject.toml index 0f21f62..824a6fd 100644 --- a/python/agent-framework/sample-agent/pyproject.toml +++ b/python/agent-framework/sample-agent/pyproject.toml @@ -6,21 +6,21 @@ authors = [ { name = "Microsoft", email = "example@microsoft.com" } ] dependencies = [ - # AgentFramework SDK - The official package + # AgentFramework SDK - The official package (accepting beta versions) "agent-framework-azure-ai", # Microsoft Agents SDK - Official packages for hosting and integration - "microsoft-agents-hosting-aiohttp", - "microsoft-agents-hosting-core", - "microsoft-agents-authentication-msal", - "microsoft-agents-activity", + "microsoft-agents-hosting-aiohttp>=0.5.0", + "microsoft-agents-hosting-core>=0.5.0", + "microsoft-agents-authentication-msal>=0.5.0", + "microsoft-agents-activity>=0.5.0", # Azure SDK components - "azure-identity", + "azure-identity>=1.25.0", # Core dependencies - "python-dotenv", - "aiohttp", + "python-dotenv>=1.0.0", + "aiohttp>=3.9.0", # HTTP server support for MCP servers "uvicorn[standard]>=0.20.0", From fe94be06bcb8eb8f82cef34326042e3d5d6bbe34 Mon Sep 17 00:00:00 2001 From: Sellakumaran Kanagarathnam Date: Sat, 8 Nov 2025 23:47:13 -0800 Subject: [PATCH 5/7] Add AGENTIC_AUTH_SCOPE to .env.template --- python/agent-framework/sample-agent/.env.template | 1 + 1 file changed, 1 insertion(+) diff --git a/python/agent-framework/sample-agent/.env.template b/python/agent-framework/sample-agent/.env.template index b3164f7..2890c4e 100644 --- a/python/agent-framework/sample-agent/.env.template +++ b/python/agent-framework/sample-agent/.env.template @@ -26,6 +26,7 @@ BEARER_TOKEN= USE_AGENTIC_AUTH=true AGENT_ID= +AGENTIC_AUTH_SCOPE=05879165-0320-489e-b644-f72b33f3edf0 # Agent365 Agentic Authentication Configuration CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID= From 413d6ed8f279988e4f1d160c08018e8c245b108d Mon Sep 17 00:00:00 2001 From: Sellakumaran Kanagarathnam Date: Sun, 9 Nov 2025 00:09:41 -0800 Subject: [PATCH 6/7] Refactor agentic authentication handling Updated `.env.template` to include `.default` in `AGENTIC_AUTH_SCOPE` for proper Azure AD scope handling. Replaced `agent_user_id` with dynamically retrieved `agentic_app_id` from activity context. Introduced `USE_AGENTIC_AUTH` flag for configurable authentication. Updated logging to reflect new variable usage. Adjusted `add_tool_servers_to_agent` method to use `agentic_app_id` and ensured correct scope handling for authentication. These changes improve flexibility, modernize authentication, and enhance traceability. --- python/agent-framework/sample-agent/.env.template | 2 +- python/agent-framework/sample-agent/agent.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/python/agent-framework/sample-agent/.env.template b/python/agent-framework/sample-agent/.env.template index 2890c4e..6188d90 100644 --- a/python/agent-framework/sample-agent/.env.template +++ b/python/agent-framework/sample-agent/.env.template @@ -26,7 +26,7 @@ BEARER_TOKEN= USE_AGENTIC_AUTH=true AGENT_ID= -AGENTIC_AUTH_SCOPE=05879165-0320-489e-b644-f72b33f3edf0 +AGENTIC_AUTH_SCOPE=05879165-0320-489e-b644-f72b33f3edf0/.default # Agent365 Agentic Authentication Configuration CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID= diff --git a/python/agent-framework/sample-agent/agent.py b/python/agent-framework/sample-agent/agent.py index 1bdb91f..3e4bcc8 100644 --- a/python/agent-framework/sample-agent/agent.py +++ b/python/agent-framework/sample-agent/agent.py @@ -225,10 +225,11 @@ async def setup_mcp_servers(self, auth: Authorization, context: TurnContext): logger.info("🔍 Starting MCP server setup...") - agent_user_id = os.getenv("AGENT_ID", "user123") + agentic_app_id = context._activity.recipient.agentic_app_id + use_agentic_auth = os.getenv("USE_AGENTIC_AUTH", "false").lower() == "true" - logger.info(f"🆔 Agent User ID: {agent_user_id}") + logger.info(f"🆔 Agentic App Id: {agentic_app_id}") logger.info(f"🔐 Using agentic auth: {use_agentic_auth}") if use_agentic_auth: @@ -246,7 +247,7 @@ async def setup_mcp_servers(self, auth: Authorization, context: TurnContext): chat_client=self.chat_client, agent_instructions="You are a helpful assistant with access to tools.", initial_tools=[], - agentic_app_id=agent_user_id, + agentic_app_id=agentic_app_id, environment_id=self.auth_options.env_id, auth=auth, turn_context=context, @@ -260,7 +261,7 @@ async def setup_mcp_servers(self, auth: Authorization, context: TurnContext): chat_client=self.chat_client, agent_instructions="You are a helpful assistant with access to tools.", initial_tools=[], - agentic_app_id=agent_user_id, + agentic_app_id=agentic_app_id, environment_id=self.auth_options.env_id, auth=auth, auth_token=self.auth_options.bearer_token, From 0743ddd7937f07494a40385c9d3477d2aec4fe1a Mon Sep 17 00:00:00 2001 From: Sellakumaran Kanagarathnam Date: Sun, 9 Nov 2025 00:48:32 -0800 Subject: [PATCH 7/7] Enhance Azure App Service compatibility Update `GenericAgentHost` to dynamically set the `host` value based on the environment. Use `0.0.0.0` for Azure App Service and `localhost` for local development. This ensures seamless operation across both environments without manual configuration. --- python/agent-framework/sample-agent/host_agent_server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/agent-framework/sample-agent/host_agent_server.py b/python/agent-framework/sample-agent/host_agent_server.py index 383f36b..f69d515 100644 --- a/python/agent-framework/sample-agent/host_agent_server.py +++ b/python/agent-framework/sample-agent/host_agent_server.py @@ -320,7 +320,9 @@ async def cleanup_on_shutdown(app): app.on_shutdown.append(cleanup_on_shutdown) try: - run_app(app, host="localhost", port=port, handle_signals=True) + # Use 0.0.0.0 for Azure App Service compatibility, localhost for local dev + host = "0.0.0.0" if os.getenv("WEBSITE_SITE_NAME") else "localhost" + run_app(app, host=host, port=port, handle_signals=True) except KeyboardInterrupt: print("\n👋 Server stopped") except Exception as error: