Skip to content

Create and Manage Persistent Agents - Use Provider pattern not Project Client #355

@Jandev

Description

@Jandev

The sample provided in the Create and Manage Persistent Agents shows the following code:

    async with (
        AzureCliCredential() as credential,
        AIProjectClient(
            endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
            credential=credential
        ) as project_client,
    ):
        # Create a persistent agent
        created_agent = await project_client.agents.create_agent(
            model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
            name="PersistentAgent",
            instructions="You are a helpful assistant."
        )

When trying this the create_agent method is not found for the project_client.agents.

After searching through the repository, it looks like the Provider-pattern should be used nowadays. Maybe the code is referring to an old version of the package?

When changing my code to use the provider pattern I get no squiglies anymore.:

        async with AzureCliCredential() as credential:
            async with AzureAIAgentsProvider(
                credential=credential
            ) as provider:
                calculator_agent = await provider.create_agent(
                    model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
                    name="CalculatorAgent",
                    instructions="You are a helpful assistant."
                )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions