diff --git a/python/agent-framework/sample-agent/.env.template b/python/agent-framework/sample-agent/.env.template index 0fa2ede..6188d90 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,19 +17,16 @@ 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= +AGENTIC_AUTH_SCOPE=05879165-0320-489e-b644-f72b33f3edf0/.default # Agent365 Agentic Authentication Configuration CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID= @@ -38,10 +36,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 +51,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..e52846e --- /dev/null +++ b/python/agent-framework/sample-agent/SETUP-GUIDE.md @@ -0,0 +1,153 @@ +# 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: +- 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` + - `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 install in two steps: + +```powershell +### 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 X packages" (PyPI dependencies from requirements.txt) + +### 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. Most missing dependencies should already be included in `requirements.txt`, but if you still get errors, you can install them individually: +```powershell +# For any additional missing modules: +uv pip install +``` + +**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/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/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, 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: diff --git a/python/agent-framework/sample-agent/pyproject.toml b/python/agent-framework/sample-agent/pyproject.toml index 159e43f..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", @@ -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", + "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" @@ -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",