Skip to content

.NET: Hosted Agents - RAG Sample with Azure AI Search (#5693)#5701

Open
rogerbarreto wants to merge 2 commits intomicrosoft:mainfrom
rogerbarreto:issues/5693-net-hosted-agents-rag-sample-with-azure-ai-search
Open

.NET: Hosted Agents - RAG Sample with Azure AI Search (#5693)#5701
rogerbarreto wants to merge 2 commits intomicrosoft:mainfrom
rogerbarreto:issues/5693-net-hosted-agents-rag-sample-with-azure-ai-search

Conversation

@rogerbarreto
Copy link
Copy Markdown
Member

Closes #5693.

Adds a hosted-agent RAG sample backed by Azure AI Search, plus a live Foundry.Hosting integration test scenario with canary-token assertions that prove the model grounded its answer in retrieved content (not training data).

Sample (Hosted-AzureSearchRag)

  • SearchClient adapter into TextSearchProvider (keyword-only, no embeddings)
  • Scope-aware DevTemporaryTokenCredential consuming AZURE_BEARER_TOKEN_FOUNDRY + AZURE_BEARER_TOKEN_SEARCH (single chained credential serves both clients in local Docker)
  • README documents the index schema + provisioning REST snippet (search service treated as pre-existing infra)
  • Mirrors Hosted-TextRag structure (Dockerfile, contributor Dockerfile, .env.example, agent.yaml, agent.manifest.yaml)

Integration test (Foundry.Hosting.IntegrationTests)

  • New AzureSearchRagHostedAgentFixture extends HostedAgentFixture with the azure-search-rag scenario branch in the shared TestContainer/Program.cs
  • 3 live tests asking for unique canary tokens (TR-CANARY-7821, SHIP-CANARY-4493) that exist only in the seeded Contoso Outdoors documents
  • Verified end to end against tao-foundry-prj + aisearch-integration-test-basic: 3/3 passed in 30s
  • IT_HOSTED_AGENT_REGISTRY ACR push works; CI workflow extended with AZURE_SEARCH_ENDPOINT / AZURE_SEARCH_INDEX_NAME (reuses existing integration secrets shared with python-sample-validation.yml)

One-time bootstrap (documented, not scripted)

The it-azure-search-rag agent's MI needs Search Index Data Reader on the search service; it-bootstrap-agents.ps1 notes this and the IT README has copy-pasteable az role assignment create template plus the aadOrApiKey flip command for services stuck on key-only auth.

Out of scope (follow-ups)

  • Promoting the search adapter to a Microsoft.Agents.AI.AzureAISearch package
  • Vector / hybrid / agentic search modes (separate samples)
  • Retrofitting Hosted-TextRag's DevTemporaryTokenCredential to be scope-aware

Adds a Hosted-AzureSearchRag sample plus a live Foundry.Hosting integration
test scenario backed by a real Azure AI Search index.

Sample (Hosted-AzureSearchRag): keyword-only Azure AI Search via
SearchClient adapter into TextSearchProvider, scope-aware
DevTemporaryTokenCredential consuming AZURE_BEARER_TOKEN_FOUNDRY +
AZURE_BEARER_TOKEN_SEARCH for local Docker, Dockerfile + contributor
Dockerfile mirroring Hosted-TextRag.

Integration test: AzureSearchRagHostedAgentFixture extends the PR microsoft#5598
HostedAgentFixture with the new azure-search-rag scenario branch in the
shared test container; AzureSearchRagHostedAgentTests asserts the model
returns canary tokens (TR-CANARY-7821, SHIP-CANARY-4493) that exist only
in the seeded documents - real proof the agent grounded its answer in
retrieved content rather than training data.
Copilot AI review requested due to automatic review settings May 7, 2026 19:51
@rogerbarreto rogerbarreto self-assigned this May 7, 2026
@rogerbarreto rogerbarreto moved this to In Review in Agent Framework May 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new Hosted Agents RAG sample backed by Azure AI Search, and extends the Foundry.Hosting live integration tests + CI to validate grounding via canary tokens.

Changes:

  • Introduces Hosted-AzureSearchRag sample (agent YAML/manifest, .NET app, Dockerfiles, env template, and provisioning README).
  • Adds a new azure-search-rag integration test scenario (fixture + tests) and wires it into the test container.
  • Updates bootstrap/docs, central packages, solution, and CI workflow to support Azure AI Search configuration.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
dotnet/tests/Foundry.Hosting.IntegrationTests/scripts/it-bootstrap-agents.ps1 Adds scenario name and documents that data-plane RBAC is manual/out-of-band.
dotnet/tests/Foundry.Hosting.IntegrationTests/README.md Documents new AZURE_SEARCH_* vars + manual Search RBAC + index prerequisite steps.
dotnet/tests/Foundry.Hosting.IntegrationTests/Foundry.Hosting.IntegrationTests.csproj Adds Azure AI Search SDK dependency for integration test project.
dotnet/tests/Foundry.Hosting.IntegrationTests/Fixtures/AzureSearchRagHostedAgentFixture.cs New fixture to provision hosted agent env vars for the Search-backed scenario.
dotnet/tests/Foundry.Hosting.IntegrationTests/AzureSearchRagHostedAgentTests.cs New live canary-token grounding tests for the Search-backed scenario.
dotnet/tests/Foundry.Hosting.IntegrationTests.TestContainer/Program.cs Adds azure-search-rag scenario branch and SearchClient→TextSearchProvider adapter.
dotnet/tests/Foundry.Hosting.IntegrationTests.TestContainer/Foundry.Hosting.IntegrationTests.TestContainer.csproj Adds Azure AI Search SDK dependency for the test container.
dotnet/src/Shared/IntegrationTests/TestSettings.cs Adds shared constants for AZURE_SEARCH_ENDPOINT / AZURE_SEARCH_INDEX_NAME.
dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AzureSearchRag/agent.yaml New hosted agent YAML for the sample.
dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AzureSearchRag/agent.manifest.yaml New manifest metadata/template for the sample.
dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AzureSearchRag/README.md New sample documentation including index schema + provisioning snippet.
dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AzureSearchRag/Program.cs New sample app: Search-backed TextSearchProvider + scope-aware dev credential.
dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AzureSearchRag/HostedAzureSearchRag.csproj New sample project file with Azure SDK dependencies and local ProjectReferences.
dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AzureSearchRag/Dockerfile.contributor Contributor docker flow using pre-published output.
dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AzureSearchRag/Dockerfile Standard multi-stage docker build for package consumers.
dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-AzureSearchRag/.env.example Adds sample env var template including Search settings + dev token placeholders.
dotnet/agent-framework-dotnet.slnx Adds the new sample project to the solution.
dotnet/Directory.Packages.props Pins Azure.Search.Documents version centrally.
.github/workflows/dotnet-build-and-test.yml Extends paths filter + injects AZURE_SEARCH_* secrets for integration tests.

Comment thread dotnet/tests/Foundry.Hosting.IntegrationTests.TestContainer/Program.cs Outdated
@moonbox3 moonbox3 added documentation Improvements or additions to documentation .NET labels May 7, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 4 | Confidence: 86% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by rogerbarreto's agents

- Sample README: drop stale 'bootstraps the index on first run' line; index is pre-provisioned out of band

- Sample + TestContainer search adapters: propagate CancellationToken to await foreach via .WithCancellation()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation .NET

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

.NET Hosted Agents - RAG Sample (with Azure AI Search)

3 participants