Skip to content

Basic Agent Creation - Python yields in error #354

@Jandev

Description

@Jandev

The sample provided on this page: https://learn.microsoft.com/en-us/agent-framework/user-guide/agents/agent-types/azure-ai-foundry-agent?pivots=programming-language-python#basic-agent-creation shows the following code:

        AzureCliCredential() as credential,
        AzureAIAgentClient(async_credential=credential).as_agent(
            name="HelperAgent",
            instructions="You are a helpful assistant."
        ) as agent,
    ):

When trying this code in my FastAPI endpoint I get an error stating:

Azure credential is required when agents_client is not provided.

I had to change my code to the following to get the code working: AzureAIAgentClient(credential=credential).as_agent(

Full sample:

class calculator:
    async def run(self, question: str):
        answer = "I don't know"
        async with AzureCliCredential() as credential:
            async with AzureAIAgentClient(credential=credential).as_agent(
                name="HelperAgent",
                instructions="You are a helpful assistant."
                ) as agent:
                answer = await agent.run(question)

        return answer

I'm not sure if the behavior is different between a console app & FastAPI endpoint (which is also marked as async, but the error is confusing at least. It looks like the code sample needs updating, but might need some more testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions