From 27cebd42627e346cdf0cc8b9bf962af99e9b25cb Mon Sep 17 00:00:00 2001 From: Josh Oratz Date: Thu, 6 Nov 2025 10:21:42 -0800 Subject: [PATCH 1/3] Update samples to remove environment id from calls and settings --- .../sample-agent/Agents/Agent365Agent.cs | 4 +--- .../sample-agent/Properties/launchSettings.json | 1 - nodejs/langchain/sample-agent/.env.example | 1 - .../sample-agent/Agent-Code-Walkthrough.md | 11 +++-------- nodejs/langchain/sample-agent/src/client.ts | 1 - python/openai/sample-agent/.env.template | 1 - .../sample-agent/AGENT-CODE-WALKTHROUGH.md | 2 -- python/openai/sample-agent/agent.py | 2 -- .../sample-agent/local_authentication_options.py | 16 ++++------------ 9 files changed, 8 insertions(+), 31 deletions(-) diff --git a/dotnet/semantic-kernel/sample-agent/Agents/Agent365Agent.cs b/dotnet/semantic-kernel/sample-agent/Agents/Agent365Agent.cs index c96b0e5b..28ca2f4a 100644 --- a/dotnet/semantic-kernel/sample-agent/Agents/Agent365Agent.cs +++ b/dotnet/semantic-kernel/sample-agent/Agents/Agent365Agent.cs @@ -48,11 +48,9 @@ public Agent365Agent(Kernel kernel, IServiceProvider service, IMcpToolRegistrati if (MyAgent.TermsAndConditionsAccepted) { // Provide the tool service with necessary parameters to connect to A365 - // The environmentId will be extracted programmatically - string environmentId = Environment.GetEnvironmentVariable("ENVIRONMENT_ID") ?? string.Empty; this._kernel.ImportPluginFromType(); - toolService.AddToolServersToAgent(kernel, environmentId, userAuthorization, turnContext); + toolService.AddToolServersToAgent(kernel, userAuthorization, turnContext); } else { diff --git a/dotnet/semantic-kernel/sample-agent/Properties/launchSettings.json b/dotnet/semantic-kernel/sample-agent/Properties/launchSettings.json index 16b14741..73ebfe32 100644 --- a/dotnet/semantic-kernel/sample-agent/Properties/launchSettings.json +++ b/dotnet/semantic-kernel/sample-agent/Properties/launchSettings.json @@ -6,7 +6,6 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "USE_AGENTIC_AUTH": "false", - "ENVIRONMENT_ID": "", // This is the Environment id, only needed when using MCPPlatform mode }, "applicationUrl": "https://localhost:64896;http://localhost:64897" } diff --git a/nodejs/langchain/sample-agent/.env.example b/nodejs/langchain/sample-agent/.env.example index 2cd60203..91753574 100644 --- a/nodejs/langchain/sample-agent/.env.example +++ b/nodejs/langchain/sample-agent/.env.example @@ -4,7 +4,6 @@ OPENAI_API_KEY= # MCP Tooling Configuration TOOLS_MODE=MCPPlatform # Options: MockMCPServer | MCPPlatform BEARER_TOKEN= -ENVIRONMENT_ID= # MCPPlatform Configuration. Default to production values. MCP_PLATFORM_ENDPOINT= diff --git a/nodejs/langchain/sample-agent/Agent-Code-Walkthrough.md b/nodejs/langchain/sample-agent/Agent-Code-Walkthrough.md index 5cdf2bb4..10ad4d09 100644 --- a/nodejs/langchain/sample-agent/Agent-Code-Walkthrough.md +++ b/nodejs/langchain/sample-agent/Agent-Code-Walkthrough.md @@ -151,7 +151,6 @@ export async function getClient(authorization: any, turnContext: TurnContext): P tools = await toolService.addMcpToolServers( mcpClientConfig, '', - process.env.ENVIRONMENT_ID || "", authorization, turnContext, process.env.BEARER_TOKEN || "", @@ -179,22 +178,18 @@ export async function getClient(authorization: any, turnContext: TurnContext): P **LangChain Integration**: - **MCP Tools**: Loads tools from MCP tool servers dynamically -- **Environment-Based**: Uses `ENVIRONMENT_ID` and `BEARER_TOKEN` for authentication +- **Auth**: Uses `BEARER_TOKEN` for authentication - **OpenAI Model**: Configured for GPT-4o-mini - **Error Handling**: Gracefully handles tool loading failures **Authentication Options**: -1. **The environment for which your servers are provisioned**: -``` -ENVIRONMENT_ID= -``` -2. **OBO (On-Behalf-Of) Authentication**: +1. **OBO (On-Behalf-Of) Authentication**: ``` BEARER_TOKEN= ``` -3. **Agentic Authentication**: +2. **Agentic Authentication**: ``` USE_AGENTIC_AUTH=true diff --git a/nodejs/langchain/sample-agent/src/client.ts b/nodejs/langchain/sample-agent/src/client.ts index 9880531d..d28800b1 100644 --- a/nodejs/langchain/sample-agent/src/client.ts +++ b/nodejs/langchain/sample-agent/src/client.ts @@ -58,7 +58,6 @@ export async function getClient(authorization: any, turnContext: TurnContext): P tools = await toolService.addMcpToolServers( mcpClientConfig, '', - process.env.ENVIRONMENT_ID || "", authorization, turnContext, process.env.BEARER_TOKEN || "", diff --git a/python/openai/sample-agent/.env.template b/python/openai/sample-agent/.env.template index 56c9972c..86fc07ca 100644 --- a/python/openai/sample-agent/.env.template +++ b/python/openai/sample-agent/.env.template @@ -14,7 +14,6 @@ LOG_LEVEL=INFO OBSERVABILITY_SERVICE_NAME=openai-agent-sample OBSERVABILITY_SERVICE_NAMESPACE=agents.samples -ENV_ID= BEARER_TOKEN= OPENAI_MODEL=gpt-4o-mini diff --git a/python/openai/sample-agent/AGENT-CODE-WALKTHROUGH.md b/python/openai/sample-agent/AGENT-CODE-WALKTHROUGH.md index d5798f7b..f76833fa 100644 --- a/python/openai/sample-agent/AGENT-CODE-WALKTHROUGH.md +++ b/python/openai/sample-agent/AGENT-CODE-WALKTHROUGH.md @@ -246,7 +246,6 @@ def _initialize_services(self): self.agent = await self.tool_service.add_tool_servers_to_agent( agent=self.agent, agent_user_id=agent_user_id, - environment_id=self.auth_options.env_id, auth=auth, context=context, ) @@ -254,7 +253,6 @@ def _initialize_services(self): self.agent = await self.tool_service.add_tool_servers_to_agent( agent=self.agent, agent_user_id=agent_user_id, - environment_id=self.auth_options.env_id, auth=auth, context=context, auth_token=self.auth_options.bearer_token, diff --git a/python/openai/sample-agent/agent.py b/python/openai/sample-agent/agent.py index d0f27b43..a034a2e0 100644 --- a/python/openai/sample-agent/agent.py +++ b/python/openai/sample-agent/agent.py @@ -217,7 +217,6 @@ async def setup_mcp_servers(self, auth: Authorization, context: TurnContext): self.agent = await self.tool_service.add_tool_servers_to_agent( agent=self.agent, agentic_app_id=agentic_app_id, - environment_id=self.auth_options.env_id, auth=auth, context=context, ) @@ -225,7 +224,6 @@ async def setup_mcp_servers(self, auth: Authorization, context: TurnContext): self.agent = await self.tool_service.add_tool_servers_to_agent( agent=self.agent, agentic_app_id=agentic_app_id, - environment_id=self.auth_options.env_id, auth=auth, context=context, auth_token=self.auth_options.bearer_token, diff --git a/python/openai/sample-agent/local_authentication_options.py b/python/openai/sample-agent/local_authentication_options.py index f913d2dd..a732a7d6 100644 --- a/python/openai/sample-agent/local_authentication_options.py +++ b/python/openai/sample-agent/local_authentication_options.py @@ -22,20 +22,17 @@ class LocalAuthenticationOptions: the necessary authentication details for MCP tool server access. """ - env_id: str = "" bearer_token: str = "" def __post_init__(self): """Validate the authentication options after initialization.""" - if not isinstance(self.env_id, str): - self.env_id = str(self.env_id) if self.env_id else "" if not isinstance(self.bearer_token, str): self.bearer_token = str(self.bearer_token) if self.bearer_token else "" @property def is_valid(self) -> bool: """Check if the authentication options are valid.""" - return bool(self.env_id and self.bearer_token) + return bool(self.bearer_token) def validate(self) -> None: """ @@ -44,20 +41,17 @@ def validate(self) -> None: Raises: ValueError: If required authentication parameters are missing. """ - if not self.env_id: - raise ValueError("env_id is required for authentication") if not self.bearer_token: raise ValueError("bearer_token is required for authentication") @classmethod def from_environment( - cls, env_id_var: str = "ENV_ID", token_var: str = "BEARER_TOKEN" + cls, token_var: str = "BEARER_TOKEN" ) -> "LocalAuthenticationOptions": """ Create authentication options from environment variables. Args: - env_id_var: Environment variable name for the environment ID. token_var: Environment variable name for the bearer token. Returns: @@ -66,14 +60,12 @@ def from_environment( # Load .env file (automatically searches current and parent directories) load_dotenv() - env_id = os.getenv(env_id_var, "") bearer_token = os.getenv(token_var, "") - print(f"🔧 Environment ID: {env_id[:20]}{'...' if len(env_id) > 20 else ''}") print(f"🔧 Bearer Token: {'***' if bearer_token else 'NOT SET'}") - return cls(env_id=env_id, bearer_token=bearer_token) + return cls(bearer_token=bearer_token) def to_dict(self) -> dict: """Convert to dictionary for serialization.""" - return {"env_id": self.env_id, "bearer_token": self.bearer_token} + return {"bearer_token": self.bearer_token} From f73bcd7e5c16a2ce1ff14a256bdb5d6a38372503 Mon Sep 17 00:00:00 2001 From: Jesus Terrazas Date: Wed, 12 Nov 2025 13:01:01 -0800 Subject: [PATCH 2/3] remove env id from newer samples --- nodejs/claude/sample-agent/README.md | 3 +- nodejs/claude/sample-agent/env.TEMPLATE | 4 -- nodejs/claude/sample-agent/src/claudeAgent.js | 4 +- nodejs/n8n/sample-agent/.env.template | 1 - .../sample-agent/Agent-Code-Walkthrough.MD | 1 - .../src/mcpToolRegistrationService.ts | 7 +-- nodejs/n8n/sample-agent/src/n8nAgent.ts | 1 - nodejs/openai/sample-agent/.env.template | 1 - .../sample-agent/AGENT-CODE-WALKTHROUGH.md | 4 -- nodejs/openai/sample-agent/src/client.ts | 1 - .../sample-agent/.env.template | 17 ++++--- .../sample-agent/AGENT-CODE-WALKTHROUGH.md | 44 +++++++++---------- python/agent-framework/sample-agent/agent.py | 18 ++++---- 13 files changed, 40 insertions(+), 66 deletions(-) diff --git a/nodejs/claude/sample-agent/README.md b/nodejs/claude/sample-agent/README.md index 6d80f726..821bf02e 100644 --- a/nodejs/claude/sample-agent/README.md +++ b/nodejs/claude/sample-agent/README.md @@ -174,8 +174,7 @@ const agentOptions = { await toolServerService.addMcpToolServers( agentOptions, process.env.AGENTIC_USER_ID || "", // Only required outside development mode - process.env.MCP_ENVIRONMENT_ID || "", // Only required outside development mode - app.authorizaiton, + app.authorization, turnContext, process.env.MCP_AUTH_TOKEN || "" // Only required if your mcp server requires this ); diff --git a/nodejs/claude/sample-agent/env.TEMPLATE b/nodejs/claude/sample-agent/env.TEMPLATE index 023aa599..5e472f3d 100644 --- a/nodejs/claude/sample-agent/env.TEMPLATE +++ b/nodejs/claude/sample-agent/env.TEMPLATE @@ -25,12 +25,8 @@ PORT=3978 # and set ANTHROPIC_API_KEY above # MockMCPServer Settings -# Note: MCP_ENVIRONMENT_ID is only needed for Tooling Gateway or if your MCP -# server uses an environment id in its path. TOOLS_MODE=MockMCPServer MCP_AUTH_TOKEN= -MCP_ENVIRONMENT_ID= - # Service Connection Settings connections__service_connection__settings__clientId= diff --git a/nodejs/claude/sample-agent/src/claudeAgent.js b/nodejs/claude/sample-agent/src/claudeAgent.js index 368ec019..82d25bae 100644 --- a/nodejs/claude/sample-agent/src/claudeAgent.js +++ b/nodejs/claude/sample-agent/src/claudeAgent.js @@ -257,17 +257,15 @@ export class ClaudeAgent { }, } - const mcpEnvironmentId = process.env.MCP_ENVIRONMENT_ID || ''; const agenticUserId = process.env.AGENTIC_USER_ID || ''; const mcpAuthToken = process.env.MCP_AUTH_TOKEN || ''; - if (mcpEnvironmentId && agenticUserId) { + if (agenticUserId) { try { await this.toolServerService.addToolServersToAgent( agentOptions, agenticUserId, - mcpEnvironmentId, this.authorization, turnContext, mcpAuthToken diff --git a/nodejs/n8n/sample-agent/.env.template b/nodejs/n8n/sample-agent/.env.template index c868d47d..788edb8f 100644 --- a/nodejs/n8n/sample-agent/.env.template +++ b/nodejs/n8n/sample-agent/.env.template @@ -13,7 +13,6 @@ PORT=3978 # MCP Tool Server Configuration (optional) # Set these if you want to provide Microsoft 365 tools to your n8n workflow -MCP_ENVIRONMENT_ID= MCP_AUTH_TOKEN= TOOLS_MODE=MCPPlatform diff --git a/nodejs/n8n/sample-agent/Agent-Code-Walkthrough.MD b/nodejs/n8n/sample-agent/Agent-Code-Walkthrough.MD index ff211dfe..e3620a33 100644 --- a/nodejs/n8n/sample-agent/Agent-Code-Walkthrough.MD +++ b/nodejs/n8n/sample-agent/Agent-Code-Walkthrough.MD @@ -216,7 +216,6 @@ agentic_altBlueprintConnectionName=service_connection agentic_scopes=ea9ffc3e-8a23-4a7d-836d-234d7c7565c1/.default # MCP Tools (Optional) -MCP_ENVIRONMENT_ID=your-environment-id MCP_AUTH_TOKEN=optional-bearer-token TOOLS_MODE=MCPPlatform ``` diff --git a/nodejs/n8n/sample-agent/src/mcpToolRegistrationService.ts b/nodejs/n8n/sample-agent/src/mcpToolRegistrationService.ts index 5ad5553e..162bf7f4 100644 --- a/nodejs/n8n/sample-agent/src/mcpToolRegistrationService.ts +++ b/nodejs/n8n/sample-agent/src/mcpToolRegistrationService.ts @@ -21,7 +21,6 @@ export class McpToolRegistrationService { async getMcpServers( agentUserId: string, - environmentId: string, authorization: Authorization, turnContext: TurnContext, authToken: string @@ -31,7 +30,7 @@ export class McpToolRegistrationService { } const mcpServers: McpServer[] = []; - const servers = await this.configService.listToolServers(agentUserId, environmentId, authToken); + const servers = await this.configService.listToolServers(agentUserId, authToken); for (const server of servers) { // Compose headers if values are available @@ -40,10 +39,6 @@ export class McpToolRegistrationService { headers['Authorization'] = `Bearer ${authToken}`; } - if (environmentId) { - headers['x-ms-environment-id'] = environmentId; - } - // Add each server to the config object const mcpServer = { mcpServerName: server.mcpServerName, diff --git a/nodejs/n8n/sample-agent/src/n8nAgent.ts b/nodejs/n8n/sample-agent/src/n8nAgent.ts index 1b6e74a4..bf473976 100644 --- a/nodejs/n8n/sample-agent/src/n8nAgent.ts +++ b/nodejs/n8n/sample-agent/src/n8nAgent.ts @@ -182,7 +182,6 @@ export class N8nAgent { try { mcpServers.push(...await this.toolService.getMcpServers( process.env.AGENTIC_USER_ID || '', - process.env.MCP_ENVIRONMENT_ID || "", this.authorization, turnContext, process.env.MCP_AUTH_TOKEN || "" diff --git a/nodejs/openai/sample-agent/.env.template b/nodejs/openai/sample-agent/.env.template index 9f4a8ebe..b0bbc17d 100644 --- a/nodejs/openai/sample-agent/.env.template +++ b/nodejs/openai/sample-agent/.env.template @@ -4,7 +4,6 @@ OPENAI_API_KEY= # MCP Tooling Configuration TOOLS_MODE=MCPPlatform # Options: MockMCPServer | MCPPlatform BEARER_TOKEN= -USE_ENVIRONMENT_ID=false # Environment Settings NODE_ENV=development # Retrieve mcp servers from ToolingManifest diff --git a/nodejs/openai/sample-agent/AGENT-CODE-WALKTHROUGH.md b/nodejs/openai/sample-agent/AGENT-CODE-WALKTHROUGH.md index c134ab67..8a36cff1 100644 --- a/nodejs/openai/sample-agent/AGENT-CODE-WALKTHROUGH.md +++ b/nodejs/openai/sample-agent/AGENT-CODE-WALKTHROUGH.md @@ -126,7 +126,6 @@ export async function getClient(authorization: any, turnContext: TurnContext): P await toolService.addToolServersToAgent( agent, process.env.AGENTIC_USER_ID || '', - process.env.MCP_ENVIRONMENT_ID || "", authorization, turnContext, process.env.MCP_AUTH_TOKEN || "", @@ -149,7 +148,6 @@ export async function getClient(authorization: any, turnContext: TurnContext): P **Environment Variables**: - `AGENTIC_USER_ID`: User identifier for the agent -- `MCP_ENVIRONMENT_ID`: Environment where MCP servers are provisioned - `MCP_AUTH_TOKEN`: Bearer token for MCP server authentication --- @@ -223,7 +221,6 @@ MCP servers are registered in the `getClient` function: await toolService.addToolServersToAgent( agent, process.env.AGENTIC_USER_ID || '', - process.env.MCP_ENVIRONMENT_ID || "", authorization, turnContext, process.env.MCP_AUTH_TOKEN || "", @@ -234,7 +231,6 @@ await toolService.addToolServersToAgent( **Environment Variables**: - `AGENTIC_USER_ID`: Identifier for the agent instance -- `MCP_ENVIRONMENT_ID`: Environment ID for MCP server provisioning - `MCP_AUTH_TOKEN`: Bearer token for MCP authentication **Authentication Modes**: diff --git a/nodejs/openai/sample-agent/src/client.ts b/nodejs/openai/sample-agent/src/client.ts index cb8a0350..923875e4 100644 --- a/nodejs/openai/sample-agent/src/client.ts +++ b/nodejs/openai/sample-agent/src/client.ts @@ -42,7 +42,6 @@ export async function getClient(authorization: any, turnContext: TurnContext): P await toolService.addToolServersToAgent( agent, process.env.AGENTIC_USER_ID || '', - process.env.MCP_ENVIRONMENT_ID || "", authorization, turnContext, process.env.MCP_AUTH_TOKEN || "", diff --git a/python/agent-framework/sample-agent/.env.template b/python/agent-framework/sample-agent/.env.template index 4ea70131..9c8de782 100644 --- a/python/agent-framework/sample-agent/.env.template +++ b/python/agent-framework/sample-agent/.env.template @@ -4,23 +4,22 @@ OPENAI_API_KEY= MCP_SERVER_HOST= MCP_PLATFORM_ENDPOINT= # Logging - + LOG_LEVEL=INFO - + # Observability Configuration OBSERVABILITY_SERVICE_NAME=agent-framework-sample OBSERVABILITY_SERVICE_NAMESPACE=agent-framework.samples - + ENV_ID= BEARER_TOKEN= OPENAI_MODEL= -#USE_ENVIRONMENT_ID=false USE_AGENTIC_AUTH=true # Agentic Authentication Scope AGENTIC_AUTH_SCOPE= - + AGENT_ID= # Agent365 Agentic Authentication Configuration @@ -32,13 +31,13 @@ CONNECTIONS__SERVICE_CONNECTION__SETTINGS__SCOPES= 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 - + # Optional: Server Configuration PORT=3978 - + # Azure OpenAI Configuration AZURE_OPENAI_API_KEY= AZURE_OPENAI_ENDPOINT= @@ -51,5 +50,5 @@ ENABLE_A365_OBSERVABILITY_EXPORTER=false PYTHON_ENVIRONMENT=development # Enable otel logs on AgentFramework SDK. Required for auto instrumentation -ENABLE_OTEL=true +ENABLE_OTEL=true ENABLE_SENSITIVE_DATA=true \ No newline at end of file diff --git a/python/agent-framework/sample-agent/AGENT-CODE-WALKTHROUGH.md b/python/agent-framework/sample-agent/AGENT-CODE-WALKTHROUGH.md index 57ea7d1b..5c69292b 100644 --- a/python/agent-framework/sample-agent/AGENT-CODE-WALKTHROUGH.md +++ b/python/agent-framework/sample-agent/AGENT-CODE-WALKTHROUGH.md @@ -20,7 +20,7 @@ Each section follows this pattern: ```python # ============================================================================= -# SECTION NAME +# SECTION NAME # ============================================================================= # [actual code here] @@ -73,19 +73,19 @@ from microsoft_agents_a365.tooling.extensions.agentframework.services.mcp_tool_r def __init__(self): """Initialize the AgentFramework agent.""" self.logger = logging.getLogger(self.__class__.__name__) - + # Initialize observability self._setup_observability() - + # Initialize authentication options self.auth_options = LocalAuthenticationOptions.from_environment() - + # Create Azure OpenAI chat client self._create_chat_client() - + # Create the agent with initial configuration self._create_agent() - + # Initialize MCP services self._initialize_services() ``` @@ -109,14 +109,14 @@ def _create_chat_client(self): endpoint = os.getenv("AZURE_OPENAI_ENDPOINT") deployment = os.getenv("AZURE_OPENAI_DEPLOYMENT") api_version = os.getenv("AZURE_OPENAI_API_VERSION") - + if not endpoint: raise ValueError("AZURE_OPENAI_ENDPOINT environment variable is required") if not deployment: raise ValueError("AZURE_OPENAI_DEPLOYMENT environment variable is required") if not api_version: raise ValueError("AZURE_OPENAI_API_VERSION environment variable is required") - + self.chat_client = AzureOpenAIChatClient( endpoint=endpoint, credential=AzureCliCredential(), @@ -146,15 +146,15 @@ def _create_agent(self): """Create the AgentFramework agent with initial configuration""" try: logger.info("Creating AgentFramework agent...") - + self.agent = ChatAgent( chat_client=self.chat_client, instructions="You are a helpful assistant with access to tools.", tools=[] # Tools will be added dynamically by MCP setup ) - + logger.info("✅ AgentFramework agent created successfully") - + except Exception as e: logger.error(f"Failed to create agent: {e}") raise @@ -244,17 +244,16 @@ async def setup_mcp_servers(self, auth: Authorization, context: TurnContext): if not self.tool_service: logger.warning("⚠️ MCP tool service not available - skipping MCP server setup") return - + agent_user_id = os.getenv("AGENT_ID", "user123") use_agentic_auth = os.getenv("USE_AGENTIC_AUTH", "false").lower() == "true" - + if use_agentic_auth: self.agent = await self.tool_service.add_tool_servers_to_agent( chat_client=self.chat_client, agent_instructions="You are a helpful assistant with access to tools.", initial_tools=[], agent_user_id=agent_user_id, - environment_id=self.auth_options.env_id, auth=auth, turn_context=context, ) @@ -264,12 +263,11 @@ async def setup_mcp_servers(self, auth: Authorization, context: TurnContext): agent_instructions="You are a helpful assistant with access to tools.", initial_tools=[], agent_user_id=agent_user_id, - environment_id=self.auth_options.env_id, auth=auth, auth_token=self.auth_options.bearer_token, turn_context=context, ) - + if self.agent: logger.info("✅ Agent MCP setup completed successfully") else: @@ -344,11 +342,11 @@ async def handle_agent_notification_activity( if notification_type == NotificationTypes.EMAIL_NOTIFICATION: if not hasattr(notification_activity, "email") or not notification_activity.email: return "I could not find the email notification details." - + email = notification_activity.email email_body = getattr(email, "html_body", "") or getattr(email, "body", "") message = f"You have received the following email. Please follow any instructions in it. {email_body}" - + result = await self.agent.run(message) return self._extract_result(result) or "Email notification processed." @@ -356,17 +354,17 @@ async def handle_agent_notification_activity( elif notification_type == NotificationTypes.WPX_COMMENT: if not hasattr(notification_activity, "wpx_comment") or not notification_activity.wpx_comment: return "I could not find the Word notification details." - + wpx = notification_activity.wpx_comment doc_id = getattr(wpx, "document_id", "") comment_id = getattr(wpx, "initiating_comment_id", "") drive_id = "default" - + # Get Word document content doc_message = f"You have a new comment on the Word document with id '{doc_id}', comment id '{comment_id}', drive id '{drive_id}'. Please retrieve the Word document as well as the comments and return it in text format." doc_result = await self.agent.run(doc_message) word_content = self._extract_result(doc_result) - + # Process the comment with document context comment_text = notification_activity.text or "" response_message = f"You have received the following Word document content and comments. Please refer to these when responding to comment '{comment_text}'. {word_content}" @@ -479,7 +477,7 @@ async def cleanup(self) -> None: **What it does**: Properly shuts down the agent and cleans up connections when it's done working. -**What happens**: +**What happens**: - Safely closes connections to MCP tool servers - Makes sure no resources are left hanging around - Logs any cleanup issues but doesn't crash if something goes wrong @@ -528,7 +526,7 @@ Clean separation of concerns through interfaces: ```python class AgentInterface(ABC): # Define contract without implementation details - + class AgentFrameworkInterface(AgentInterface): # Specific implementation for AgentFramework ``` diff --git a/python/agent-framework/sample-agent/agent.py b/python/agent-framework/sample-agent/agent.py index 71f9ae28..6b7c2635 100644 --- a/python/agent-framework/sample-agent/agent.py +++ b/python/agent-framework/sample-agent/agent.py @@ -67,7 +67,7 @@ class AgentFrameworkAgent(AgentInterface): """AgentFramework Agent integrated with MCP servers and Observability""" - + AGENT_PROMPT = "You are a helpful assistant with access to tools." # ========================================================================= @@ -93,7 +93,7 @@ def __init__(self): # Initialize MCP services self._initialize_services() - + # Track if MCP servers have been set up self.mcp_servers_initialized = False @@ -186,7 +186,7 @@ async def setup_mcp_servers(self, auth: Authorization, context: TurnContext): """Set up MCP server connections""" if self.mcp_servers_initialized: return - + try: if not self.tool_service: logger.warning("⚠️ MCP tool service unavailable") @@ -208,7 +208,6 @@ async def setup_mcp_servers(self, auth: Authorization, context: TurnContext): agent_instructions=self.AGENT_PROMPT, initial_tools=[], agentic_app_id=agent_user_id, - environment_id=self.auth_options.env_id, auth=auth, turn_context=context, auth_token=auth_token, @@ -219,7 +218,6 @@ async def setup_mcp_servers(self, auth: Authorization, context: TurnContext): agent_instructions=self.AGENT_PROMPT, initial_tools=[], agentic_app_id=agent_user_id, - environment_id=self.auth_options.env_id, auth=auth, auth_token=self.auth_options.bearer_token, turn_context=context, @@ -279,11 +277,11 @@ async def handle_agent_notification_activity( if notification_type == NotificationTypes.EMAIL_NOTIFICATION: if not hasattr(notification_activity, "email") or not notification_activity.email: return "I could not find the email notification details." - + email = notification_activity.email email_body = getattr(email, "html_body", "") or getattr(email, "body", "") message = f"You have received the following email. Please follow any instructions in it. {email_body}" - + result = await self.agent.run(message) return self._extract_result(result) or "Email notification processed." @@ -291,17 +289,17 @@ async def handle_agent_notification_activity( elif notification_type == NotificationTypes.WPX_COMMENT: if not hasattr(notification_activity, "wpx_comment") or not notification_activity.wpx_comment: return "I could not find the Word notification details." - + wpx = notification_activity.wpx_comment doc_id = getattr(wpx, "document_id", "") comment_id = getattr(wpx, "initiating_comment_id", "") drive_id = "default" - + # Get Word document content doc_message = f"You have a new comment on the Word document with id '{doc_id}', comment id '{comment_id}', drive id '{drive_id}'. Please retrieve the Word document as well as the comments and return it in text format." doc_result = await self.agent.run(doc_message) word_content = self._extract_result(doc_result) - + # Process the comment with document context comment_text = notification_activity.text or "" response_message = f"You have received the following Word document content and comments. Please refer to these when responding to comment '{comment_text}'. {word_content}" From cf378742fc245cc068cf946336e463b6b5ca68fc Mon Sep 17 00:00:00 2001 From: Josh Oratz <43622754+joratz@users.noreply.github.com> Date: Wed, 12 Nov 2025 14:49:50 -0800 Subject: [PATCH 3/3] Update python/agent-framework/sample-agent/.env.template Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- python/agent-framework/sample-agent/.env.template | 1 - 1 file changed, 1 deletion(-) diff --git a/python/agent-framework/sample-agent/.env.template b/python/agent-framework/sample-agent/.env.template index 9c8de782..23b5bd3c 100644 --- a/python/agent-framework/sample-agent/.env.template +++ b/python/agent-framework/sample-agent/.env.template @@ -11,7 +11,6 @@ LOG_LEVEL=INFO OBSERVABILITY_SERVICE_NAME=agent-framework-sample OBSERVABILITY_SERVICE_NAMESPACE=agent-framework.samples -ENV_ID= BEARER_TOKEN= OPENAI_MODEL=