This repository is a beginner-friendly workshop for building a Microsoft Foundry Hosted Agent with .NET 10.
If you are new to Microsoft Foundry hosted agents, follow the labs in order from Lab 0 to Lab 5. Each lab builds on the previous lab and keeps commands copy-paste ready.
The scenario is a Hosted Agent Readiness Coach. The agent helps delivery teams answer practical questions such as:
- Should this use case start as a prompt agent or a hosted agent?
- What should a pilot launch checklist include?
- How should a team troubleshoot common early setup problems?
By the end of the workshop, you will have worked through the full development path for a simple hosted agent:
- Environment setup and local run
- Copilot customization
- Feature implementation with local tools
- CI automation
- Deployment preparation for hosted agents
- UI integration for end-to-end usage
This repository demonstrates three distinct stages:
- local and CI validation inside the repo
- Azure resource provisioning and image publishing for deployment readiness
- Microsoft Foundry control-plane deployment as an explicit separate step
That split is intentional. azd provisions the Azure resource group and Azure Container Registry, GitHub Actions can publish the agent image to ACR, and the final Microsoft Foundry agent create or update step remains explicit because it depends on your real project endpoint, manifest values, and hosted-agent lifecycle controls.
You build a code-based hosted agent that exposes the OpenAI Responses-compatible /responses endpoint on port 8088.
The agent uses deterministic local tools backed by WorkshopLab.Core:
RecommendImplementationShapeBuildLaunchChecklistTroubleshootHostedAgent
These tools make the scenario useful for teams who are evaluating or onboarding to Microsoft Foundry Hosted Agents.
Before working through the workshop, make sure you have the accounts, access, and tools the labs assume.
- An Azure subscription. A trial subscription is fine if it can create and use Microsoft Foundry resources, or you can bring your own subscription.
- Permission to sign in with Azure CLI and Azure Developer CLI using the account that will run the workshop.
- Sufficient Azure access to the target subscription and resource group. At minimum, you should be able to provision workshop resources, use the Microsoft Foundry project endpoint, and deploy or use a chat model.
- A GitHub account, since the later labs use repository workflows and GitHub Actions.
- Permission to create or update GitHub Actions workflows and repository settings in the repo used for the workshop.
If you are using a shared enterprise environment, make sure you know in advance which subscription, resource group, Microsoft Foundry project, and model deployment you are expected to use.
If you are new to this topic, use the repo in this order:
- Read the setup requirements in this README.
- Follow the lab sequence in the course map below.
- Run the agent locally before thinking about Azure deployment.
- Use the Azure provisioning and deployment sections only after the local and CI steps are working.
If this is your first time with hosted agents, use this simple path:
- Complete Lab 0 and confirm
/responsesworks locally. - Complete Labs 1 to 3 and make sure tests and CI pass.
- Complete Lab 4 to deploy and verify your hosted agent in Microsoft Foundry.
- Complete Lab 5 to use the deployed agent through a UI.
Use the labs in order. Each one builds on the previous one.
| Lab | Focus | What You Finish With |
|---|---|---|
| Lab 0 | Microsoft Foundry setup | A working local hosted agent and a validated /responses endpoint |
| Lab 1 | Copilot config | Repo-specific Copilot guidance for this hosted-agent project |
| Lab 2 | Implementation shape | A real feature change in one of the agent's deterministic tools |
| Lab 3 | CI | Build, test, and container validation in GitHub Actions |
| Lab 4 | Deploy | Azure-ready packaging plus the deployment handoff steps |
| Lab 5 | UI | A working chat UI that calls your deployed hosted agent |
For the full lab guide, see labs/README.md.
.
├── .devcontainer/ # Codespaces/dev container configuration
├── .github/workflows/ # CI and deployment-oriented workflows
├── labs/ # Guided labs in sequential order
├── src/
│ ├── WorkshopLab.AgentHost/ # Hosted agent entrypoint, Dockerfile, agent.yaml
│ └── WorkshopLab.Core/ # Deterministic domain logic used by the agent tools
├── tests/WorkshopLab.Tests/ # xUnit tests for the deterministic core logic
└── WorkshopLab.sln
Use this section if you want to prove the app works locally before starting the later Azure steps.
- .NET 10 SDK
- Azure CLI
- Azure Developer CLI (
azd) - Access to a Microsoft Foundry project
- A deployed chat model in that project
The agent host expects:
AZURE_AI_PROJECT_ENDPOINTMODEL_DEPLOYMENT_NAME
Example PowerShell session:
$env:AZURE_AI_PROJECT_ENDPOINT = "https://<resource>.services.ai.azure.com/api/projects/<project>"
$env:MODEL_DEPLOYMENT_NAME = "gpt-4.1-mini"dotnet restore
dotnet build
dotnet test
dotnet run --project src/WorkshopLab.AgentHostThen send a local request:
$body = @{
input = "We need an internal agent that uses private APIs and workflow handoffs. Should we start with a hosted agent?"
stream = $false
} | ConvertTo-Json
Invoke-RestMethod -Uri http://localhost:8088/responses -Method Post -Body $body -ContentType "application/json"Use this section when you are ready to provision Azure resources for the deployment path.
This repo includes an azd and infra/ path for the Azure-owned part of deployment.
- Create an environment:
azd env new <environment-name>- Preview the infrastructure:
azd provision --preview- Provision the resource group and Azure Container Registry:
azd provisionThe Bicep template in infra/main.bicep provisions an Azure Container Registry and exports:
AZURE_CONTAINER_REGISTRY_NAMEAZURE_CONTAINER_REGISTRY_ENDPOINTAZURE_RESOURCE_GROUP_NAME
You still need to set your Microsoft Foundry-specific environment values in the azd environment or shell:
AZURE_AI_PROJECT_ENDPOINTMODEL_DEPLOYMENT_NAME
Example:
azd env set AZURE_AI_PROJECT_ENDPOINT "https://<resource>.services.ai.azure.com/api/projects/<project>"
azd env set MODEL_DEPLOYMENT_NAME "gpt-4.1-mini"Use this step after azd provision when you are ready to publish the hosted-agent image.
The workflow in .github/workflows/deploy.yml publishes the hosted-agent image to Azure Container Registry and stops there.
It uses Azure OIDC login and the recommended cloud-build path:
AZURE_CLIENT_ID,AZURE_TENANT_ID, andAZURE_SUBSCRIPTION_IDas GitHub secretsAZURE_CONTAINER_REGISTRY_NAMEas a GitHub repository variable, usually copied fromazd env get-values
The workflow does not create or start the Microsoft Foundry hosted agent. That remains a separate step.
Use this step after the image is available in ACR.
Use the helper project in src/WorkshopLab.FoundryDeployment/Program.cs or the wrapper script in scripts/deploy-foundry-agent.ps1 to call the Microsoft Foundry manifest APIs explicitly.
Example:
./scripts/deploy-foundry-agent.ps1The wrapper reads:
AZURE_AI_PROJECT_ENDPOINTMODEL_DEPLOYMENT_NAME- optional
FOUNDRY_AGENT_ID
If FOUNDRY_AGENT_ID is set, the helper updates that agent from manifest. Otherwise, it creates a new agent from manifest.
The helper intentionally stops after manifest create or update. Until the hosted-agent start and status control-plane surface is pinned cleanly in the SDK path, use the Microsoft Foundry portal or the Microsoft Foundry MCP tools for:
- container start
- status polling
- final
/responsesverification
This workshop separates deployment into a few clear stages so beginners can understand what happens where.
- Azure prerequisites are explicit: Azure CLI auth, a Microsoft Foundry project endpoint, and a deployed chat model.
- The hosted agent contract is explicit in src/WorkshopLab.AgentHost/agent.yaml:
kind: hosted,responsesprotocol, and environment-variable placeholders. - Azure provisioning is explicit in azure.yaml and infra/main.bicep: provision the Azure resource group path and Azure Container Registry with azd.
- CI publishing is explicit in .github/workflows/deploy.yml: build a timestamped Linux AMD64 image and publish it to ACR with
az acr build. - Microsoft Foundry manifest deployment is explicit in src/WorkshopLab.FoundryDeployment/Program.cs: create or update the hosted agent from manifest as a separate control-plane step.
- The remaining hosted-agent lifecycle operations are environment-dependent: start the container, verify status, and test the deployed agent.
That matches the Microsoft Foundry deploy skill workflow for hosted agents:
- Detect the project and collect environment variables.
- Build a Linux AMD64 container image.
- Push the image to Azure Container Registry.
- Create or update the hosted agent definition in Microsoft Foundry.
- Start the hosted agent container and verify it reaches
Running.
The repo intentionally stops after ACR publish plus manifest apply so the remaining hosted-agent lifecycle actions stay tied to your real subscription, registry, and Microsoft Foundry project.
- Validate the
/responsescontract locally before attempting deployment. - Keep the hosted agent HTTP server as the default process entrypoint.
- Build Linux AMD64 containers for hosted-agent deployment targets.
- Start with deterministic local tools before adding external connections.
For workshop safety and production readiness, apply these basics from day one:
- Keep credentials out of source control. Use environment variables, GitHub secrets, or Azure-managed identities.
- Treat
.envfiles as local-only and commit only safe examples like.env.example. - Keep dependencies and GitHub Actions updated regularly, and prefer pinned action SHAs in workflows.
- Run the pull-request secret scan workflow and resolve findings before merging.
- Contributor and coding-agent guidance: AGENTS.md
- Release and update history: CHANGELOG.md