Files
agent-framework/dotnet/samples/HostedAgents/AgentWithTextSearchRag
T
SergeyMenshykh c1830c20c9 .NET: Add hosting capabilities to hosted agents (#2124)
* move catalog samples to the HostedAgents folder

* move the catalog samples' projects to the HostedAgents folder

* host agents, add dockerfile, add http for testing, and use explicit nuget packages

* add agents` manifests

* Update dotnet/samples/HostedAgents/AgentWithTextSearchRag/Dockerfile

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dotnet/samples/HostedAgents/AgentsInWorkflows/Dockerfile

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dotnet/samples/HostedAgents/AgentWithTextSearchRag/agent.yaml

Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>

* Update dotnet/samples/HostedAgents/AgentsInWorkflows/agent.yaml

Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>

* remove BOMs, decrease identation and remove unecessary `parameters` node.

* remove unnecessary analyzers and align the packages' versions

* remove end-of-line breaks in agents' descriptions, eliminated unnecessary double quotes around versions, and changed the descriptions to be more agent-centric rather than sample-centric

* use DefaultAzureCredential

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
c1830c20c9 ยท 2025-11-12 14:35:25 +00:00
History
..

What this sample demonstrates

This sample demonstrates how to use TextSearchProvider to add retrieval augmented generation (RAG) capabilities to an AI agent. The provider runs a search against an external knowledge base before each model invocation and injects the results into the model context.

Key features:

  • Configuring TextSearchProvider with custom search behavior
  • Running searches before AI invocations to provide relevant context
  • Managing conversation memory with a rolling window approach
  • Citing source documents in AI responses

Prerequisites

Before running this sample, ensure you have:

  1. An Azure OpenAI endpoint configured
  2. A deployment of a chat model (e.g., gpt-4o-mini)
  3. Azure CLI installed and authenticated

Environment Variables

Set the following environment variables:

# Replace with your Azure OpenAI endpoint
$env:AZURE_OPENAI_ENDPOINT="https://your-openai-resource.openai.azure.com/"

# Optional, defaults to gpt-4o-mini
$env:AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o-mini"

How It Works

The sample uses a mock search function that demonstrates the RAG pattern:

  1. When the user asks a question, the TextSearchProvider intercepts it
  2. The search function looks for relevant documents based on the query
  3. Retrieved documents are injected into the model's context
  4. The AI responds using both its training and the provided context
  5. The agent can cite specific source documents in its answers

The mock search function returns pre-defined snippets for demonstration purposes. In a production scenario, you would replace this with actual searches against your knowledge base (e.g., Azure AI Search, vector database, etc.).