Prerequisites
- Install Microsoft Foundry Toolkit for Visual Studio Code.
- Select a Foundry project with a deployed model. Use a supported hosted-agent region.
- Permission to use the model and deploy hosted agents. For source-code deployment, the Foundry Project Manager role at project scope includes agent operations and role assignment permissions. See Hosted agent permissions.
The Foundry RBAC roles were recently renamed. Foundry User, Foundry Owner, Foundry Account Owner, and Foundry Project Manager were previously named Azure AI User, Azure AI Owner, Azure AI Account Owner, and Azure AI Project Manager. You might still see the previous names in some places while the rename rolls out. The role IDs and core permissions are unchanged by the rename.
- Azure CLI for the local authentication steps in this article.
- For container deployment, the registry and image access required by Azure Container Registry setup. These registry requirements don’t apply to a source-code deployment.
Create a hosted agent workflow
Choose an Agent Framework sample that uses the Responses protocol. You don’t need to create a separate prompt agent first. To compare samples, Agent Builder, and Copilot-assisted coding, see Choose a creation route.- In the Foundry Toolkit view, select Developer Tools > Build > Create Agent.
- Under Code an agent from samples, select Browse all samples.
-
In Create Hosted Agent from Sample, filter by your Language,
Framework = Agent Framework, and Protocol Type = Responses.
Search for
workflow. The following screenshot shows the gallery with Basic Hosted Agent selected as an example. For this guide, select the workflow sample for your language instead.

- Select the workflow sample for your language.
- Select Next.
- On Create, choose the Workspace Folder. If the folder already contains files, enter a Folder Name for a new child folder.
- If Environment Setup appears, select Setup with Microsoft Foundry, and then select your subscription and project. When a default project is already selected, the form uses that project.
- Select an existing compatible Model Deployment. The following screenshot shows example project settings with local paths hidden. Use your own destination and the model deployment required by your sample.

- Review the destination, and then select Create.
- Open the generated project in Visual Studio Code and read its
README.md.
Configure the local project
Keep the folder that containsazure.yaml open as the workspace root. Check
the hosted-agent service’s project path in that file to find its source
directory.
Sample layouts can change. Use the generated
README.md and azure.yaml
instead of assuming that the code and environment file are at the workspace root.
Install dependencies
Use the generated sample’s dependency files. Keep the selected interpreter or SDK consistent with its runtime configuration.Set the project and model
Review the.env file in the source directory. If it doesn’t exist, create it
with the values required by the sample.
Both workflow samples load
.env during startup. The project endpoint is not
an Azure OpenAI account endpoint. Keep the file out of source control, and
don’t put credentials in your application code.
Authenticate locally
The samples useDefaultAzureCredential. For the Azure CLI credential path,
sign in with an account that can access the project’s model:
Run your hosted workflow locally
Use the generated debug configuration to start the HTTP server and open Agent Inspector. Opening Agent Inspector alone doesn’t start the server.- Return to the generated project workspace.
- Set a breakpoint in the workflow code if you want to inspect execution.
- Press F5. If prompted, select Debug Local Agent HTTP Server.
- Wait for the server to start and Agent Inspector to open.
- Send the test request for your sample.
- Inspect the response and repeat with another request. If you set a breakpoint, inspect the values and continue execution.

/validate-microsoft-foundry-hosted-agent in Copilot Chat to review the project
against Foundry best practices. This Chat command opens a report; it isn’t a
terminal command or a substitute for running the workflow.
The generated tasks use port 8088 for the agent server. Python debugging
also uses port 5679. If startup reports a port conflict, stop the conflicting
process that you own or adjust the generated task configuration consistently.
Run without the debugger
To run manually, open a terminal in the sample’s source directory with its dependencies, environment values, and Azure credential available. Then run Foundry Toolkit: Open Agent Inspector from the Command Palette and connect to the local server on port8088. Running a sample with python
or dotnet run starts a local process, not a container.
Visualize hosted agent workflow execution
Use Agent Inspector to inspect the events, responses, and tool calls that your running agent emits. When the runtime emits workflow events, use the workflow visualization to inspect the sequence of steps. The available details depend on the sample’s instrumentation. Follow the sample’s telemetry setup instructions for runtime-specific requirements. These steps use the Responses protocol. Other samples need clients that match their protocol: the HTTP Invocations view isn’t a WebSocket client, and Python Activity samples use Microsoft 365 Agents Playground. Follow the selected sample’s local-testing instructions. Changing a protocol name in configuration doesn’t add that protocol to your server. See Choose a hosted-agent protocol.Deploy the hosted agent
After the local workflow behaves as expected, deploy it from the project workspace. Python and C# share the deployment procedure. Start with Code and Remote package mode to upload source and let Foundry restore dependencies.Prepare deployment configuration
Review and save the hosted-agent service inazure.yaml. Preserve the sample’s
protocol configuration and declare the model deployment and other required
runtime settings there.
Deployment resolves declared environment values from the source directory’s
.env or the process environment. It doesn’t forward every local .env entry.
The platform supplies reserved runtime values such as FOUNDRY_PROJECT_ENDPOINT;
don’t redeclare them as deployment settings. See
Platform-injected environment variables.
Review the source directory’s ignore rules before packaging. Keep .env,
credentials, virtual environments, and caches out of the package. For ZIP
deployment, a source-root .agentignore replaces the rules in .gitignore
and .dockerignore, so retain the necessary exclusions if you add that file.
Don’t commit or package secrets. Local sign-in doesn’t transfer your user’s
permissions to the deployed agent. Configure access for the agent’s runtime
identity and supported connections. See
Hosted agent permissions.
Deploy source with Remote package mode
Use the generated workspace root so the Toolkit can read the service configuration and locate its source directory.- Stop the local debugging session.
- Select Developer Tools > Build > Deploy to Microsoft Foundry. You can also run Foundry Toolkit: Deploy Hosted Agent from the Command Palette.

- If Foundry Project Setup appears, select the subscription and project, and then select Next. Otherwise, confirm that the default project is the intended destination.
- On Basics, select Code as Deployment Method and Remote as Package Mode.
- Select New agent and enter the Hosted Agent Name. To update a deployed agent, select Existing agent and choose that agent instead.

- Select Next.
-
On Review + Deploy, check Language, Runtime Version, Entry Point,
and CPU and Memory against the sample. Confirm that the source directory
matches the service’s
projectpath. The following screenshot shows an example with Python 3.14 and its entry point hidden, not the settings for these workflow samples. For Python, use Python 3.13 withpython3 main.py. For C#, use .NET 10 and the detected entry point for your generated project.

- Select Deploy. Follow progress in notifications and Output.
- Continue to Test the deployed workflow.
Choose another ZIP package mode
The Toolkit offers these source-code packaging options:
The selectable ZIP runtimes are Python 3.13, Python 3.14, and .NET 10. Match the
runtime to your code and dependencies. For layouts, limits, and service
requirements, see Deploy from source code.
For the runtime support policy, see
Supported hosted-agent runtimes.
Deploy a container image
Choose Container on Basics when you need a custom runtime image or already have a compatible image.
For the build options, review the Dockerfile and build context before deploying.
If you generate a Dockerfile in the wizard, review the file and select
Continue and deploy. These options use remote ACR builds, not local Docker builds.
Custom registry options use a registry in the selected subscription. The
custom-registry build path requires public network access; the prebuilt-image
path has separate private-network requirements. Choosing an image doesn’t
configure network connectivity.
Review container requirements
and private networking guidance
before using a custom registry. These deployments target Foundry Agent Service,
not the retired Azure Container Apps hosted-agent path. To move an older agent,
follow Migrate from the hosted-agent preview.
Test the deployed workflow
A successful create request doesn’t prove that the runtime is ready or that its model and tools are reachable. Test the exact deployed version.- Under My Resources > Agents > Hosted Agent, select the agent name.
- Select the numbered version you just deployed.
- On Details, wait for the deployment status to indicate that the agent is running. If it fails, inspect the deployment output before retrying.
- Open Playground and send the same request you tested locally.
- Review the response. If you added tools, send a request that requires those tools and inspect the calls.
Inspect and update the deployed agent
Use the remote playground to test and inspect your deployed agent. Unlike local testing with Agent Inspector, requests in this playground run against the agent hosted in Foundry.- In Foundry Toolkit, select Developer Tools > Build > Hosted Agent Playground.

- In the Hosted Agent dropdown, select your deployed agent and the version to inspect. Open Playground to send a request and view the response and session details. The following screenshot shows an illustrative deployed agent’s response, not the expected output of either workflow sample. Agent and session identifiers are hidden.

Use Traces and Evaluation, when available, for investigation and quality
measurement beyond one successful response. Follow the prerequisites for
hosted-agent tracing
and hosted-agent evaluation.
Deployment gives the agent an endpoint for programmatic use. A separate
publication step isn’t required for API access. Publishing to Teams or
Microsoft 365 is a separate task. See the
current agent endpoint and publishing model.