Share via

Credential Error in Microsoft Agent Framework SDK

Yi Chun Lam 10 Reputation points
2026-01-07T23:35:19.54+00:00

Hi All

I am doing the exercises in MS Learn to create agents using MS Agent Framework SDK. I followed every instruction in the exercises and ran the python scripts, but then there was an error "agent_framework.exceptions.ServiceInitializationError: Azure credential is required when agents_client is not provided.". Can anyone help to resolve this issue? Thanks!

Develop an Azure AI chat agent with the Microsoft Agent Framework SDK:
https://microsoftlearning.github.io/mslearn-ai-agents/Instructions/04-semantic-kernel.html

Develop a multi-agent solution

https://microsoftlearning.github.io/mslearn-ai-agents/Instructions/05-agent-orchestration.html

Full Error Details:

Traceback (most recent call last):

File "/home/john/ai-agents/Labfiles/05-agent-orchestration/Python/agents.py", line 76, in <module>

asyncio.run(main())

File "/usr/lib/python3.12/asyncio/runners.py", line 195, in run

return runner.run(main)

       ^^^^^^^^^^^^^^^^

File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run

return self._loop.run_until_complete(task)

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete

return future.result()

       ^^^^^^^^^^^^^^^

File "/home/john/ai-agents/Labfiles/05-agent-orchestration/Python/agents.py", line 33, in main

AzureAIAgentClient(async_credential=credential) as chat_client,

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/home/john/ai-agents/Labfiles/05-agent-orchestration/Python/labenv/lib/python3.12/site-packages/agent_framework_azure_ai/_chat_client.py", line 206, in init

raise ServiceInitializationError("Azure credential is required when agents_client is not provided.")

agent_framework.exceptions.ServiceInitializationError: Azure credential is required when agents_client is not provided.

Azure OpenAI in Foundry Models

3 answers

Sort by: Most helpful
  1. Anonymous
    2026-01-08T05:42:12.02+00:00

    Hi Yi Chun Lam

    agent_framework.exceptions.ServiceInitializationError: Azure credential is required when agents_client is not provided. happens when the client cannot find a usable Azure credential object (it’s None / not passed / not valid), and you didn’t pass a pre-built agents_client.

    So the SDK has no way to authenticate to Azure AI Agents / Azure AI Project. [agent_fram...soft Learn | Learn.Microsoft.com], [azure.ai.a...soft Learn | Learn.Microsoft.com], [agent_fram...soft Learn | Learn.Microsoft.com]

    In most lab environments, your code creates a credential like DefaultAzureCredential() or AzureCliCredential(), but you are not logged in (or the credential chain can’t find any valid auth method). Then the SDK effectively behaves like “no credential provided”, triggering this error. The official quickstart explicitly calls out using Azure CLI auth (az login) and having access to the Azure AI project. [Microsoft...soft Learn | Learn.Microsoft.com], [Create and...soft Learn | Learn.Microsoft.com]

    3) Fix #1 (recommended for labs): use Azure CLI credential and ensure you’re logged in

    Step A — Login

    Run this in your terminal:

    Shell

    az login
    az account show
    

    This ensures the CLI token exists for AzureCliCredential() to use. [Microsoft...soft Learn | Learn.Microsoft.com], [Create and...soft Learn | Learn.Microsoft.com]

    4)Step B — Use the credential correctly in code

    The AzureAIAgentClient expects a credential= parameter (per the SDK docs). If you pass async_credential= to AzureAIAgentClient, it may not bind to the right parameter and the SDK will treat it like no credential was provided. Use credential=... like below. [agent_fram...soft Learn | Learn.Microsoft.com], [Microsoft...soft Learn | Learn.Microsoft.com]

    import asyncio
    from azure.identity.aio import AzureCliCredential
    from agent_framework.azure import AzureAIAgentClient
    async def main():
    async with AzureCliCredential() as credential:
    async with AzureAIAgentClient(credential=credential) as client:
    # run your agent calls here
    pass
    if __name__ == "__main__":
    asyncio.run(main())
    

    This matches the documented constructor usage for AzureAIAgentClient(... credential= ...). [agent_fram...soft Learn | Learn.Microsoft.com], [Microsoft...soft Learn | Learn.Microsoft.com]

    1. Fix #2: Make sure required environment variables are set (very common missing step)

    Even with a valid credential, the SDK also needs to know where your Azure AI project is and which model deployment to use.

    Set these (either in your shell or in a .env file):

    • AZURE_AI_PROJECT_ENDPOINT
    • AZURE_AI_MODEL_DEPLOYMENT_NAME

    The SDK docs and quickstart show these exact variables. [agent_fram...soft Learn | Learn.Microsoft.com], [Microsoft...soft Learn | Learn.Microsoft.com]

    Example:

    Shell

    export AZURE_AI_PROJECT_ENDPOINT="https://<your-project>.cognitiveservices.azure.com"
    export AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-4o-mini"
    

    Or load from .env:

    Python

    client = AzureAIAgentClient(credential=credential, env_file_path=".env")
    

    [agent_fram...soft Learn | Learn.Microsoft.com], [Microsoft...soft Learn | Learn.Microsoft.com]

    Fix #3: If you really intended to pass a pre-built AgentsClient

    The error message says “credential is required when agents_client is not provided”. That means alternative path is: create an AgentsClient(endpoint, credential) yourself and pass it in as agents_client=.... The AgentsClient constructor requires both endpoint and credential. [azure.ai.a...soft Learn | Learn.Microsoft.com]

    Conceptually:

    Python

    from azure.ai.agents.aio import AgentsClient
    from azure.identity.aio import AzureCliCredential
    from agent_framework.azure import AzureAIAgentClient
    agents = AgentsClient(endpoint=PROJECT_ENDPOINT, credential=credential)
    client = AzureAIAgentClient(agents_client=agents, credential=credential)
    

    (Exact import path may differ by version, but the key is: AgentsClient requires endpoint + credential.) [agent_fram...soft Learn | Learn.Microsoft.com]

    6) Quick checklist (this resolves 95% of cases)

    1. pip show agent-framework agent-framework-azure-ai azure-identity (packages installed)
    2. az login completed successfully
    3. You used AzureCliCredential() or a working DefaultAzureCredential()
    4. You passed it as credential=credential into AzureAIAgentClient
    5. AZURE_AI_PROJECT_ENDPOINT + AZURE_AI_MODEL_DEPLOYMENT_NAME are set

    These align directly with the SDK constructor + quickstart requirements. [agent_fram...soft Learn | Learn.Microsoft.com], [Microsoft...soft Learn | Learn.Microsoft.com], [Create and...soft Learn | Learn.Microsoft.com]

    Please let me know and if there are any remaining questions or additional details, I can help with, I’ll be glad to provide further clarification or guidance.

    Thankyou!

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments

  2. Baraldi, Andrea 10 Reputation points
    2026-01-13T14:50:51.84+00:00

    I had a look at AzureAIAgentClient docs here and I found that they wrote the wrong credential parameter and they missed to specify env_file_path.

    I was able to run successfully the lab with the following code:

    
    
    ```ruby
    # Create a chat agent
    async with (
        AzureCliCredential() as credential,
        ChatAgent(
            chat_client=AzureAIAgentClient(credential=credential, env_file_path=".env"),
            name="expenses_agent",
            instructions="""You are an AI assistant for expense claim submission.
                            When a user submits expenses data and requests an expense claim, use the plug-in function to send an email to ******@contoso.com with the subject 'Expense Claim`and a body that contains itemized expenses with a total.
                            Then confirm to the user that you've done so.""",
            tools=send_email,
        ) as agent,
    ):
    # ...
    

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  3. AI answer

    2026-01-07T23:35:29.05+00:00

    The error message you are encountering, "agent_framework.exceptions.ServiceInitializationError: Azure credential is required when agents_client is not provided," indicates that the Azure credentials are not being passed correctly to the AzureAIAgentClient when you attempt to create an instance of it.

    To resolve this issue, ensure that you are using the AzureCliCredential for authentication, and that you have successfully logged in using the Azure CLI before running your script. Here are the steps you can follow:

    1. Install Azure CLI: Make sure you have the Azure CLI installed on your machine.
    2. Login to Azure: Run the command az login in your terminal to authenticate with your Azure account.
    3. Use AzureCliCredential: Ensure that your code includes the following import and initialization:
         from azure.identity import AzureCliCredential
         credential = AzureCliCredential()
      
    4. Pass the Credential: When creating the AzureAIAgentClient, make sure to pass the credential object:
         chat_client = AzureAIAgentClient(async_credential=credential)
      
    5. Environment Variables: Verify that you have set the necessary environment variables for your Azure OpenAI service, including the endpoint and deployment name, as outlined in the prerequisites.

    By following these steps, you should be able to resolve the credential error and successfully initialize your agent client.

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.