{"record":{"id":"e33ee74895468cd2","repo":"microsoft/semantic-kernel","slug":"azure-openai-endpoint-is-not-set-e33ee7","errorCode":null,"errorMessage":"AZURE_OPENAI_ENDPOINT is not set.","messagePattern":"AZURE_OPENAI_ENDPOINT is not set\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/AgentFrameworkMigration/AgentOrchestrations/Step03_Handoff/Program.cs","lineNumber":19,"sourceCode":"﻿// Copyright (c) Microsoft. All rights reserved.\n\n#pragma warning disable MAAIW001 // Experimental: HandoffWorkflowBuilder\n\nusing System.ComponentModel;\nusing System.Text.Json;\nusing Azure.AI.OpenAI;\nusing Azure.Identity;\nusing Microsoft.Agents.AI;\nusing Microsoft.Agents.AI.Workflows;\nusing Microsoft.Extensions.AI;\nusing Microsoft.SemanticKernel;\nusing Microsoft.SemanticKernel.Agents;\nusing Microsoft.SemanticKernel.Agents.Orchestration;\nusing Microsoft.SemanticKernel.Agents.Orchestration.Handoff;\nusing Microsoft.SemanticKernel.Agents.Runtime.InProcess;\nusing Microsoft.SemanticKernel.ChatCompletion;\n\nvar endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\") ?? throw new InvalidOperationException(\"AZURE_OPENAI_ENDPOINT is not set.\");\nvar deploymentName = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_DEPLOYMENT_NAME\") ?? \"gpt-4o-mini\";\n\n// Queries to simulate user input during the interactive orchestration\nList<string> Queries = [\n    \"I'd like to track the status of my first order 123.\",\n    \"I want to return another order of mine whose ID is 456 because it arrived damaged.\",\n];\n\n// This sample compares running handoff orchestrations using\n// Semantic Kernel and the Agent Framework.\nConsole.WriteLine(\"=== Semantic Kernel Handoff Orchestration ===\");\n// State to help format the streaming output\nbool newAgentTurn = true;\nstring previousFunctionCallId = string.Empty;\nawait SKHandoffOrchestration();\n\nConsole.WriteLine(\"\\n=== Agent Framework Handoff Agent Workflow ===\");\nawait AFHandoffAgentWorkflow();","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/AgentFrameworkMigration/AgentOrchestrations/Step03_Handoff/Program.cs#L1-L37","documentation":"The Handoff Orchestration migration sample throws InvalidOperationException when AZURE_OPENAI_ENDPOINT is missing. This sample simulates a customer-service scenario with multiple specialized agents (order tracking, returns) that hand off conversations. The endpoint feeds AzureOpenAIChatClient construction with AzureCliCredential for both SK and AF comparison paths.","triggerScenarios":"Running AgentOrchestrations/Step03_Handoff without AZURE_OPENAI_ENDPOINT. The throw at line 19 fires before the simulated Queries list and streaming output logic execute.","commonSituations":"New clone without environment setup; the handoff sample requires multiple agents so developers may assume it has a different setup process (it does not — same single endpoint variable); running from Visual Studio without project-level environment variables configured in launchSettings.json.","solutions":["Set AZURE_OPENAI_ENDPOINT in your environment before running","Optionally set AZURE_OPENAI_DEPLOYMENT_NAME (defaults to gpt-4o-mini)","If running from VS, add the variable to Properties/launchSettings.json under environmentVariables","Ensure az login is current for AzureCliCredential"],"exampleFix":"// before\nvar endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\") ?? throw new InvalidOperationException(\"AZURE_OPENAI_ENDPOINT is not set.\");\n\n// after — load from launchSettings or user secrets as fallback\nvar endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\")\n    ?? throw new InvalidOperationException(\n        \"AZURE_OPENAI_ENDPOINT is not set. See README.md Environment Variables section.\");","handlingStrategy":"validation","validationCode":"var endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\");\nif (string.IsNullOrWhiteSpace(endpoint))\n{\n    Console.Error.WriteLine(\"AZURE_OPENAI_ENDPOINT is not set. Required for handoff orchestration.\");\n    return;\n}","typeGuard":"static bool IsAzureOpenAIEndpointConfigured() =>\n    !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\"));","tryCatchPattern":"try\n{\n    var endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\")\n        ?? throw new InvalidOperationException(\"AZURE_OPENAI_ENDPOINT is not set.\");\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"AZURE_OPENAI_ENDPOINT\"))\n{\n    Console.Error.WriteLine(ex.Message);\n    return;\n}","preventionTips":["Configure env vars in launchSettings.json when running handoff samples from Visual Studio","Run az login before executing samples that rely on AzureCliCredential","Create a shared setup script for all AgentOrchestration samples since they share the same env var","Validate env vars in a guard method called at the top of Main"],"tags":["configuration","csharp","azure-openai","semantic-kernel","environment-variables","agent-orchestration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}