* Add foundry extension samples for python and dotnet * Align foundry extension samples with existing hosted agent patterns - Fix Python multiagent indentation bug (from_agent_framework ran in both modes) - Remove hardcoded personal endpoint from appsettings.Development.json - Rename .NET folders/projects to PascalCase (FoundryMultiAgent, FoundrySingleAgent) - Upgrade .NET multiagent from net9.0 to net10.0 - Add ManagePackageVersionsCentrally=false and analyzer blocks to .csproj files - Replace wildcard package versions with fixed versions - Use alpine Docker images and standard build pattern - Align agent.yaml structure (template nesting, displayName, resources, authors) - Convert .NET multiagent from namespace/class to top-level statements - Add run-requests.http for multiagent sample - Fix Python requirements.txt (remove dev deps, add agent-framework) - Add proper copyright headers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Align foundry samples: fix builds, upgrade AgentServer to beta.8 - Fix TargetFrameworks (plural) to override inherited net472 from Directory.Build.props - Upgrade Azure.AI.AgentServer.AgentFramework to 1.0.0-beta.8 (latest) - Bump OpenTelemetry packages to 1.12.0 (required by beta.8) - Fix Roslynator/format errors (imports ordering, BOM, sealed record, target-typed new) - Verified with docker dotnet format (matching CI pipeline) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Refactor hosted samples to use AIProjectClient.CreateAIAgentAsync Replace PersistentAgentsClient and manual AzureOpenAIClient setup with AIProjectClient.CreateAIAgentAsync() from Microsoft.Agents.AI.AzureAI. - FoundryMultiAgent: Remove Azure.AI.Agents.Persistent, use CreateAIAgentAsync for Writer and Reviewer agents with cleanup in finally block - FoundrySingleAgent: Remove manual GetConnection/AzureOpenAIClient chain, use CreateAIAgentAsync with hotel search tool - Update csproj: add Microsoft.Agents.AI.AzureAI, remove unused packages Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update READMEs to reflect AIProjectClient.CreateAIAgentAsync usage - Reference Microsoft.Agents.AI.AzureAI and Microsoft.Agents.AI.Workflows packages - Add Azure AI Developer role requirement for agents/write data action - Replace PersistentAgentsClient references Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add HostedAgents READMEs and Foundry samples to solution - Create dotnet/samples/05-end-to-end/HostedAgents/README.md with sample index - Create python/samples/05-end-to-end/hosted_agents/README.md with sample index - Add FoundryMultiAgent and FoundrySingleAgent to agent-framework-dotnet.slnx Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Python linting: reorder imports before load_dotenv, remove trailing whitespace Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update uv.lock to match latest package versions Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix trailing whitespace in foundry_single_agent agent.yaml Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Exclude dotnet.microsoft.com from link checker This domain intermittently times out in CI, causing flaky markdown link check failures unrelated to PR changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Align env vars to AZURE_AI_PROJECT_ENDPOINT and default model to gpt-4o-mini Addresses PR review feedback: - Rename PROJECT_ENDPOINT to AZURE_AI_PROJECT_ENDPOINT across all Foundry samples (dotnet + python) to match existing samples - Change default model from gpt-4.1-mini to gpt-4o-mini consistently Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Skip flaky test CreatesWorkflowEndToEndActivities_WithCorrectName_DefaultAsync Tracked in #4398 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove Python foundry samples from PR scope Python hosted agent samples need further alignment with the azure-ai package conventions. Removing from this PR to ship .NET samples first. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Narrow linkspector exclusion to dotnet.microsoft.com/download only Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Leo Yao <leoyao@Leos-MacBook-Pro.local> Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
8.3 KiB
IMPORTANT! All samples and other resources made available in this GitHub repository ("samples") are designed to assist in accelerating development of agents, solutions, and agent workflows for various scenarios. Review all provided resources and carefully test output behavior in the context of your use case. AI responses may be inaccurate and AI actions should be monitored with human oversight. Learn more in the transparency documents for Agent Service and Agent Framework.
Agents, solutions, or other output you create may be subject to legal and regulatory requirements, may require licenses, or may not be suitable for all industries, scenarios, or use cases. By using any sample, you are acknowledging that any output created using those samples are solely your responsibility, and that you will comply with all applicable laws, regulations, and relevant safety standards, terms of service, and codes of conduct.
Third-party samples contained in this folder are subject to their own designated terms, and they have not been tested or verified by Microsoft or its affiliates.
Microsoft has no responsibility to you or others with respect to any of these samples or any resulting output.
What this sample demonstrates
This sample demonstrates a key advantage of code-based hosted agents:
- Multi-agent workflows - Orchestrate multiple agents working together
Code-based agents can execute any C# code you write. This sample includes a Writer-Reviewer workflow where two agents collaborate: a Writer creates content and a Reviewer provides feedback.
The agent is hosted using the Azure AI AgentServer SDK and can be deployed to Microsoft Foundry.
How It Works
Multi-Agent Workflow
In Program.cs, the sample creates two agents using AIProjectClient.CreateAIAgentAsync() from the Microsoft.Agents.AI.AzureAI package:
- Writer - An agent that creates and edits content based on feedback
- Reviewer - An agent that provides actionable feedback on the content
The WorkflowBuilder from the Microsoft.Agents.AI.Workflows package connects these agents in a sequential flow:
- The Writer receives the initial request and generates content
- The Reviewer evaluates the content and provides feedback
- Both agent responses are output to the user
Agent Hosting
The agent is hosted using the Azure AI AgentServer SDK, which provisions a REST API endpoint compatible with the OpenAI Responses protocol.
Running the Agent Locally
Prerequisites
Before running this sample, ensure you have:
-
Azure AI Foundry Project
- Project created.
- Chat model deployed (e.g.,
gpt-4oorgpt-4.1) - Note your project endpoint URL and model deployment name
Note
: You can right-click the project in the Microsoft Foundry VS Code extension and select
Copy Project Endpoint URLto get the endpoint.
-
Azure CLI
- Installed and authenticated
- Run
az loginand verify withaz account show - Your identity needs the Azure AI Developer role on the Foundry resource (for
agents/writedata action required byCreateAIAgentAsync)
-
.NET 10.0 SDK or later
- Verify your version:
dotnet --version - Download from https://dotnet.microsoft.com/download
- Verify your version:
Environment Variables
Set the following environment variables:
PowerShell:
# Replace with your actual values
$env:AZURE_AI_PROJECT_ENDPOINT="https://<your-resource>.services.ai.azure.com/api/projects/<your-project>"
$env:MODEL_DEPLOYMENT_NAME="gpt-4o-mini"
Bash:
export AZURE_AI_PROJECT_ENDPOINT="https://<your-resource>.services.ai.azure.com/api/projects/<your-project>"
export MODEL_DEPLOYMENT_NAME="gpt-4o-mini"
Running the Sample
To run the agent, execute the following command in your terminal:
dotnet restore
dotnet build
dotnet run
This will start the hosted agent locally on http://localhost:8088/.
Interacting with the Agent
VS Code:
- Open the Visual Studio Code Command Palette and execute the
Microsoft Foundry: Open Container Agent Playground Locallycommand. - Execute the following commands to start the containerized hosted agent.
dotnet restore dotnet build dotnet run - Submit a request to the agent through the playground interface. For example, you may enter a prompt such as: "Create a slogan for a new electric SUV that is affordable and fun to drive."
- Review the agent's response in the playground interface.
Note
: Open the local playground before starting the container agent to ensure the visualization functions correctly.
PowerShell (Windows):
$body = @{
input = "Create a slogan for a new electric SUV that is affordable and fun to drive"
stream = $false
} | ConvertTo-Json
Invoke-RestMethod -Uri http://localhost:8088/responses -Method Post -Body $body -ContentType "application/json"
Bash/curl (Linux/macOS):
curl -sS -H "Content-Type: application/json" -X POST http://localhost:8088/responses \
-d '{"input": "Create a slogan for a new electric SUV that is affordable and fun to drive","stream":false}'
You can also use the run-requests.http file in this directory with the VS Code REST Client extension.
The Writer agent will generate content based on your prompt, and the Reviewer agent will provide feedback on the output.
Deploying the Agent to Microsoft Foundry
Preparation (required)
Please check the environment_variables section in agent.yaml and ensure the variables there are set in your target Microsoft Foundry Project.
To deploy the hosted agent:
-
Open the VS Code Command Palette and run the
Microsoft Foundry: Deploy Hosted Agentcommand. -
Follow the interactive deployment prompts. The extension will help you select or create the container files it needs.
-
After deployment completes, the hosted agent appears under the
Hosted Agents (Preview)section of the extension tree. You can select the agent there to view details and test it using the integrated playground.
What the deploy flow does for you:
- Creates or obtains an Azure Container Registry for the target project.
- Builds and pushes a container image from your workspace (the build packages the workspace respecting
.dockerignore). - Creates an agent version in Microsoft Foundry using the built image. If a
.envfile exists at the workspace root, the extension will parse it and include its key/value pairs as the hosted agent's environment variables in the create request (these variables will be available to the agent runtime). - Starts the agent container on the project's capability host. If the capability host is not provisioned, the extension will prompt you to enable it and will guide you through creating it.
MSI Configuration in the Azure Portal
This sample requires the Microsoft Foundry Project to authenticate using a Managed Identity when running remotely in Azure. Grant the project's managed identity the required permissions by assigning the built-in Azure AI User role.
To configure the Managed Identity:
- In the Azure Portal, open the Foundry Project.
- Select "Access control (IAM)" from the left-hand menu.
- Click "Add" and choose "Add role assignment".
- In the role selection, search for and select "Azure AI User", then click "Next".
- For "Assign access to", choose "Managed identity".
- Click "Select members", locate the managed identity associated with your Foundry Project (you can search by the project name), then click "Select".
- Click "Review + assign" to complete the assignment.
- Allow a few minutes for the role assignment to propagate before running the application.