Formerly known as Azure AI Services or Azure Cognitive Services is a unified collection of prebuilt AI capabilities within the Microsoft Foundry platform
Hello @Deepankar ,
Welcome to Microsoft Q&A .Thank you for reaching out to us.
The behavior is expected because Azure AI Foundry separates the agent configuration from the service-generated agent resource identity. The YAML/code-first definition is used to describe the agent’s behavior and configuration, while the Agent ID is generated by the service when the agent resource is created
The right approach is not to predefine the Agent ID, but to make the application’s create/reuse logic idempotent.
- Agent definition vs. Agent ID n the code-first flow, the YAML or SDK definition should be treated as the agent specification. It defines what the agent should be configured with, such as:
- Agent name
- Model
- Instructions
- Tools
- Additional configuration or metadata
CreateAgentAsync()API accepts creation inputs such asmodel, optionalname,description, andinstructions, but it does not expose a parameter for supplying a custom Agent ID during creation. This indicates that the Agent ID is returned by the service rather than authored by the user at create time.YAML / SDK definition = input configurationAgent ID = output generated by Foundry after creation - Agent ID vs. managed agent identity It is also useful to separate the Agent ID from the security identity used by the platform.
- Agent ID: Resource identifier used to reference the created agent.
- Agent identity / Microsoft Entra identity: Security identity used for authentication and authorization when the agent accesses tools or other resources.
Regarding the a custom Agent ID be predefined in YAML - No documented workflow currently supports predefining a custom Agent ID in YAML or passing a custom Agent ID during agent creation.
The YAML definition should be used to define the agent configuration. The Agent ID should be captured after creation and reused for future operations. In other words, the YAML file should not be used as a mechanism to reserve or assign a specific Agent ID.
The suggested code-first pattern is:
- Define a stable logical agent name in YAML or configuration.
- Create the agent using the SDK or deployment workflow.
- Capture the generated Agent ID returned by the service.
- Persist the generated Agent ID in durable configuration.
- On later executions, reuse the stored Agent ID.
- If the stored ID is missing or stale, attempt to find the existing agent using the stable logical name.
- Create a new agent only if no existing reusable agent can be found.
Durable storage options can include:
- Azure App Configuration
- Azure Key Vault-backed configuration
- Database
- Environment-specific application settings
Azure App Configuration is suitable for centralizing agent-related settings such as endpoint, agent name, model configuration, instructions and YAML-based agent specifications.
To avoid duplicate agents
- Read stored Agent ID from configuration at startup
- If the stored Agent ID is valid, reuse the existing agent
- If the stored Agent ID is missing or stale, search for an existing agent using a stable logical name
- If a matching agent is found, reuse it and refresh the stored Agent ID
- If no existing agent is found, create a new agent and persist the newly generated Agent ID for future use
If the application can run in parallel, it is recommended to add synchronization around the create step, because two concurrent startup flows could otherwise both check for an agent and then both attempt creation before either one persists the generated ID.
Multi-environment ,like for Dev/Test/Prod deployments, use separate logical names and separate stored Agent IDs per environment.
invoice-triage-agent-dev
invoice-triage-agent-test
invoice-triage-agent-prod
Each environment should maintain its own generated Agent ID in that environment’s configuration store. This avoids accidental reuse across environments and keeps deployments predictable.
The following references might be helpful , please check them out
- PersistentAgentsAdministrationClient.CreateAgentAsync Method (Azure.AI.Agents.Persistent) - Azure for .NET Developers | Microsoft Learn
- Quickstart: Get started with Microsoft Foundry SDK - Microsoft Foundry | Microsoft Learn
- Hosted agents in Foundry Agent Service - Microsoft Foundry | Microsoft Learn
- Configuring agents in Agent framework with Azure App Configuration | Microsoft Learn
- What is Azure App Configuration? | Microsoft Learn
Thank you
Please "Accept" the answer with an "Upvote" if the response was helpful. This will be benefitting other community members who face the same issue.