Add SPE Agent with Retrieval from existing source#253
Open
pemtaira-msft wants to merge 1 commit into
Open
Conversation
Originally from: https://github.com/yratna/SPEAgentWithRetrieval This has been updated to work with SPE, not sharepoint.
cindylay
approved these changes
Jul 7, 2026
There was a problem hiding this comment.
Pull request overview
Adds a new .NET 8 console sample (“SPEAgentWithRetrieval”) that demonstrates retrieval-augmented generation over SharePoint Embedded (SPE) content using the Microsoft 365 Copilot Retrieval API for grounding and Azure AI Foundry for response generation.
Changes:
- Introduces a new solution with a console entrypoint and a reusable Core library (retrieval, Foundry chat completion, auth/token acquisition).
- Adds end-to-end sample documentation, example configuration, and helper scripts for app registration fixes.
- Adds throttling retry handling for Retrieval API calls and basic console UX for interactive Q&A.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| AI/agent-with-retrieval-sample-app/SPEAgentWithRetrieval.sln | Adds solution containing console app + Core library projects. |
| AI/agent-with-retrieval-sample-app/SPEAgentWithRetrieval.csproj | Adds .NET 8 console project and references Core library. |
| AI/agent-with-retrieval-sample-app/SPEAgentWithRetrieval.Core/SPEAgentWithRetrieval.Core.csproj | Adds Core library project and NuGet dependencies. |
| AI/agent-with-retrieval-sample-app/SPEAgentWithRetrieval.Core/Services/TokenProvider.cs | Implements auth/token acquisition using Azure Identity credentials and token caching. |
| AI/agent-with-retrieval-sample-app/SPEAgentWithRetrieval.Core/Services/IRetrievalService.cs | Defines retrieval abstraction for grounding content. |
| AI/agent-with-retrieval-sample-app/SPEAgentWithRetrieval.Core/Services/IFoundryService.cs | Defines abstraction for Foundry chat response generation. |
| AI/agent-with-retrieval-sample-app/SPEAgentWithRetrieval.Core/Services/IChatService.cs | Defines orchestration abstraction for chat flow. |
| AI/agent-with-retrieval-sample-app/SPEAgentWithRetrieval.Core/Services/FoundryService.cs | Implements chat completions via Azure AI Foundry inference endpoint. |
| AI/agent-with-retrieval-sample-app/SPEAgentWithRetrieval.Core/Services/CopilotRetrievalService.cs | Implements Microsoft Graph Copilot Retrieval API calls scoped to SPE container type. |
| AI/agent-with-retrieval-sample-app/SPEAgentWithRetrieval.Core/Services/ChatService.cs | Orchestrates retrieval + response synthesis and returns sources. |
| AI/agent-with-retrieval-sample-app/SPEAgentWithRetrieval.Core/Models/Configuration.cs | Adds options models for Foundry, Microsoft 365, and chat settings. |
| AI/agent-with-retrieval-sample-app/SPEAgentWithRetrieval.Core/Models/ChatModels.cs | Adds request/response/source models for the chat pipeline. |
| AI/agent-with-retrieval-sample-app/README.md | Adds setup, architecture, troubleshooting, and usage documentation for the sample. |
| AI/agent-with-retrieval-sample-app/Program.cs | Adds console host wiring, DI registration, and main chat loop UI. |
| AI/agent-with-retrieval-sample-app/fix-azure-app-registration.sh | Adds bash automation for adjusting app registration auth platforms. |
| AI/agent-with-retrieval-sample-app/fix-azure-app-registration.ps1 | Adds PowerShell automation for adjusting app registration auth platforms. |
| AI/agent-with-retrieval-sample-app/appsettings.example.json | Adds example configuration template for Foundry, Graph scopes, and chat settings. |
| AI/agent-with-retrieval-sample-app/.gitignore | Ensures appsettings and related sensitive configs are not committed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+9
to
+12
| <ItemGroup> | ||
| <PackageReference Include="Azure.AI.Projects" Version="1.0.0-beta.2" /> | ||
| <PackageReference Include="Azure.Identity" Version="1.14.2" /> | ||
| <PackageReference Include="System.Text.Json" Version="8.0.5" /> |
Comment on lines
+40
to
+44
| TokenCachePersistenceOptions = new TokenCachePersistenceOptions | ||
| { | ||
| Name = "SPEAgentAuthCache", | ||
| UnsafeAllowUnencryptedStorage = true | ||
| }, |
Comment on lines
+63
to
+67
| TokenCachePersistenceOptions = new TokenCachePersistenceOptions | ||
| { | ||
| Name = "SPEAgentAuthCache", | ||
| UnsafeAllowUnencryptedStorage = true // For development only | ||
| }, |
Comment on lines
+14
to
+18
| private readonly Microsoft365Options _microsoft365Options; | ||
| private readonly ChatSettingsOptions _chatSettings; | ||
| private readonly ILogger<CopilotRetrievalService> _logger; | ||
| private readonly ITokenProvider _tokenProvider; | ||
|
|
| // HTTP 429 or, for the SPE datasource, as an HTTP 500 whose body carries "code":"429". | ||
| // Retry a few times with exponential backoff before giving up. | ||
| const int maxAttempts = 4; | ||
| using var httpClient = new HttpClient(); |
| public bool UseUserAuthentication { get; set; } = true; | ||
| public bool UseDeviceCodeAuth { get; set; } = false; | ||
| public string[] Scopes { get; set; } = { "https://graph.microsoft.com/FileStorageContainer.Selected" }; | ||
| public bool AllowAnonymousRequests { get; set; } = false; // For development only - allows requests without authentication |
Comment on lines
+49
to
+52
| logger.LogInformation("Azure AI Chat Agent with SharePoint RAG started"); | ||
|
|
||
| System.Console.WriteLine("=== Azure AI Chat Agent with SharePoint RAG ==="); | ||
| System.Console.WriteLine("Ask questions about your Microsoft 365 content!"); |
|
|
||
| ```bash | ||
| git clone <your-repo-url> | ||
| cd SPEAgentWithRetrieval |
|
|
||
| ### Bash Script (macOS/Linux) | ||
| ```bash | ||
| ./fix-azure-app-registration.sh |
|
|
||
| ### PowerShell Script (Windows/Cross-platform) | ||
| ```powershell | ||
| ./fix-azure-app-registration.ps1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Originally from: https://github.com/yratna/SPEAgentWithRetrieval
This has been updated to work with SPE, not sharepoint.