Skip to content

Unable to successfully create and use current Azure AI Foundry resources for current Azure.AI.Projects SDK (1.0.0-beta.9) using bicep #244

@v-croft

Description

@v-croft

Problem

I am trying to update my code to use the current SDK based on Azure.AI.Projects (Version=1.0.0-beta.9) and Azure.AI.Agents.Persistent library (Version=1.1.0-beta.3) but am not able to dynamically provision the resources to connect to using bicep. Manually provisioning the resources works.

Failing API code to create an agent dynamically

// Retrieve from environment variables added by Aspire AppHost
var endpoint = Environment.GetEnvironmentVariable("OpenAiEndpoint");
var modelDeploymentName = System.Environment.GetEnvironmentVariable("ModelDeployment");

AIProjectClient projectClient = new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential());
PersistentAgentsClient agentsClient = projectClient.GetPersistentAgentsClient();

// Create the agent - fails with a 404 (not found) error
PersistentAgent agent = await agentsClient.Administration.CreateAgentAsync(
    model: modelDeploymentName,
    name: $"agent-{Guid.NewGuid()}",
    instructions: SearchService.Instructions
);

Note that changes to the Azure.AI.Project SDK no longer accept a project connection string and expect an Azure AI Foundry resource rather than an AI hub resource (which I was previously using). See Azure.AI.Projects Change Log.

When I try to create an Azure Foundry AI resource and project with bicep (via Aspire), the resources are provisioned but the above code fails to create an agent returning a 404. The endpoint and modelDeploymentName are correct and correspond to the provisioned resources.

If I access the provisioned resources via the Azure Portal and navigate to the Agents I get the following error, implying the resource is not correctly provisioned.

Image

If I create an Azure AI Foundry resource manually through the Foundry portal then everything works (I can create an agent manually or via the above code). When I compare the generated bicep of the manually created resources with the bicep below, they look exactly the same (naming aside).

The issues seems to be with the AI Foundry resource rather than the project as recreating a project manually in the AI Foundry resource also fails.

Am I missing something or is there a bug here? (I cannot find any examples using the Azure AI Foundry approach, rather than the older AI Hub which does not work with the current SDK). Either way it does not seem possible to marry bicep IaC with the current SDK.

Bicep to provision infrastructure - succeeds but does not allow agents to be created

@description('The location for the resource(s) to be deployed.')
param location string = resourceGroup().location

@description('The principal ID for role assignments')
param principalId string

@description('The principal type for role assignments')
param principalType string

@description('The AI project name')
param aiProjectName string = take('aiProject-${uniqueString(resourceGroup().id)}', 64)

@description('The model deployment name')
param model string = 'gpt-4o'

// Create Azure AI Foundry resource (using CognitiveServices accounts for AI Foundry)
#disable-next-line BCP037
resource aiFoundryResource 'Microsoft.CognitiveServices/accounts@2025-06-01' = {
  name: take('ai-foundry-${uniqueString(resourceGroup().id)}', 64)
  location: location
  sku: {
    name: 'S0'
  }
  kind: 'AIServices'
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    #disable-next-line BCP037
    apiProperties: {}
    customSubDomainName: toLower(take(concat('aifoundry', uniqueString(resourceGroup().id)), 24))
    publicNetworkAccess: 'Enabled'
    disableLocalAuth: false
    networkAcls: {
      defaultAction: 'Allow'
      virtualNetworkRules: []
      ipRules: []
    }
    allowProjectManagement: true
  }
}

// Create GPT-4o model deployment using Standard tier
#disable-next-line BCP037
resource modelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2025-06-01' = {
  parent: aiFoundryResource
  name: model
  sku: {
    name: 'Standard'
    capacity: 30
  }
  properties: {
    model: {
      format: 'OpenAI'
      name: model
      version: '2024-11-20'
    }
    versionUpgradeOption: 'OnceNewDefaultVersionAvailable'
    raiPolicyName: 'Microsoft.DefaultV2'
  }
}

// Create AI Project
#disable-next-line BCP037
resource aiProject 'Microsoft.CognitiveServices/accounts/projects@2025-06-01' = {
  parent: aiFoundryResource
  name: aiProjectName
  location: location
  kind: 'AIServices'
  identity: {
    type: 'SystemAssigned'
  }
  properties: {}
  dependsOn: [
    modelDeployment
  ]
}

// Outputs as required
output modelDeployment string = modelDeployment.name
output openAiEndpoint string = aiProject.properties.endpoints['AI Foundry API']

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