{"record":{"id":"93a0300da2adee1f","repo":"microsoft/semantic-kernel","slug":"failed-to-create-copilot-studio-agent-settings-e","errorCode":null,"errorMessage":"Failed to create Copilot Studio Agent settings: {exc}","messagePattern":"Failed to create Copilot Studio Agent settings: (.+?)","errorType":"exception","errorClass":"AgentInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/copilot_studio/copilot_studio_agent.py","lineNumber":387,"sourceCode":"\n        try:\n            connection_settings = CopilotStudioAgentSettings(\n                app_client_id=app_client_id,\n                tenant_id=tenant_id,\n                environment_id=environment_id,\n                agent_identifier=agent_identifier,\n                cloud=cloud,\n                type=copilot_agent_type,\n                custom_power_platform_cloud=custom_power_platform_cloud,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n                client_secret=client_secret,\n                client_certificate=client_certificate,\n                user_assertion=user_assertion,\n                auth_mode=auth_mode,\n            )\n        except ValidationError as exc:\n            raise AgentInitializationException(f\"Failed to create Copilot Studio Agent settings: {exc}\") from exc\n\n        missing_params = [name for name in (\"app_client_id\", \"tenant_id\") if not getattr(connection_settings, name)]\n        if missing_params:\n            raise AgentInitializationException(f\"Missing required configuration field(s): {', '.join(missing_params)}\")\n\n        cache_file = environ.get(\"TOKEN_CACHE_PATH_INTERACTIVE\") or path.join(\n            path.dirname(__file__), \"bin\", \"token_cache_interactive.bin\"\n        )\n\n        token = _CopilotStudioAgentTokenFactory(\n            settings=connection_settings,\n            cache_path=cache_file,\n            mode=connection_settings.auth_mode,\n            client_secret=connection_settings.client_secret.get_secret_value()\n            if connection_settings.client_secret\n            else None,\n            client_certificate=Path(client_certificate) if client_certificate else None,\n            user_assertion=user_assertion,","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/copilot_studio/copilot_studio_agent.py#L369-L405","documentation":"Raised by CopilotStudioAgent.create_client() when constructing CopilotStudioAgentSettings raises a Pydantic ValidationError. The ValidationError is caught, wrapped in an AgentInitializationException, and chained (from exc). This means one or more settings fields failed Pydantic validation — type mismatches, invalid enum values, or constraint violations.","triggerScenarios":"Calling create_client() with an invalid value for a typed field, e.g. cloud not a valid PowerPlatformCloud, copilot_agent_type not a valid AgentType, auth_mode not a valid CopilotStudioAgentAuthMode, or env_file_encoding with an unsupported value. Values loaded from a .env file or environment variables that do not parse into the expected types also trigger this.","commonSituations":"Typos in .env file values (e.g. cloud=sovereign instead of a valid enum); passing a string where an enum is expected; missing required env vars that have no default; version mismatch where an enum gained/lost members.","solutions":["Read the full ValidationError message embedded in the exception (it lists each invalid field and the expected type).","Correct the offending field value — ensure cloud, copilot_agent_type, and auth_mode match their enum members exactly.","Validate env file values against CopilotStudioAgentSettings field definitions before calling create_client().","If loading from a .env file, check env_file_path and env_file_encoding are correct so values are parsed properly."],"exampleFix":"# before — invalid cloud value\nclient = CopilotStudioAgent.create_client(cloud=\"prod\", ...)\n\n# after — valid PowerPlatformCloud enum member\nfrom microsoft_agents.copilotstudio.client import PowerPlatformCloud\nclient = CopilotStudioAgent.create_client(cloud=PowerPlatformCloud.PUBLIC, ...)","handlingStrategy":"try-catch","validationCode":"from semantic_kernel.agents.copilot_studio.copilot_studio_agent_settings import CopilotStudioAgentSettings\n\n# Pre-validate settings to get the raw ValidationError detail\ntry:\n    settings = CopilotStudioAgentSettings(\n        app_client_id=app_client_id, tenant_id=tenant_id, cloud=cloud, ...\n    )\nexcept ValidationError as e:\n    print(e.errors())  # inspect before it gets wrapped","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.agent_exceptions import AgentInitializationException\n\ntry:\n    client = CopilotStudioAgent.create_client(cloud=cloud, ...)\nexcept AgentInitializationException as exc:\n    # exc.__cause__ holds the original Pydantic ValidationError\n    detail = exc.__cause__.errors() if exc.__cause__ else str(exc)\n    logger.error(\"Settings validation failed: %s\", detail)","preventionTips":["Pre-validate settings by constructing CopilotStudioAgentSettings directly to see raw ValidationError detail.","Ensure enum-valued fields (cloud, copilot_agent_type, auth_mode) use valid members.","Double-check env_file_path / env_file_encoding if loading from a .env file."],"tags":["configuration","validation","pydantic","copilot-studio","initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}