بنقرة واحدة
researching-azure-ai-sdk
Provides research patterns for Azure AI Foundry Agent Service SDK. Use when implementing agent features, looking up SDK methods, finding code samples, or troubleshooting Azure.AI.Projects API usage.
القائمة
Provides research patterns for Azure AI Foundry Agent Service SDK. Use when implementing agent features, looking up SDK methods, finding code samples, or troubleshooting Azure.AI.Projects API usage.
Provides deployment commands and troubleshooting for Azure Container Apps. Use when running azd commands, deploying containers, debugging deployment failures, or updating infrastructure in this repository.
Provides Playwright MCP testing workflow for the web application. Use when testing UI changes, verifying chat functionality, debugging frontend issues, or validating state transitions in the browser.
Provides authentication troubleshooting for MSAL, JWT, and Entra ID. Use when debugging 401 errors, token issues, MSAL configuration problems, or credential failures in this repository.
Provides step-by-step procedures for validating UI features - theme toggle, new chat, cancel stream, markdown rendering, and token usage info.
Provides C# and ASP.NET Core coding standards for this repository. Use when writing or modifying C# code, implementing API endpoints, configuring middleware, or working with authentication in the backend. Use when writing or modifying C# code, implementing API endpoints,
Provides TypeScript and React coding standards for this repository. Use when writing or modifying TypeScript code, creating React components, implementing MSAL authentication, or working with the frontend.
| name | researching-azure-ai-sdk |
| description | Provides research patterns for Azure AI Foundry Agent Service SDK. Use when implementing agent features, looking up SDK methods, finding code samples, or troubleshooting Azure.AI.Projects API usage. |
CRITICAL: Don't guess SDK usage. Follow this research workflow.
Multi-repo research blows up context (1000+ tokens per file). Delegate to subagent for:
runSubagent(
agentName: "WebAppAgent",
prompt: "RESEARCH task - do NOT write code.
**Question**: [specific SDK question]
**Search these sources in order**:
1. Azure.AI.Projects SDK: github.com/Azure/azure-sdk-for-net/tree/main/sdk/ai/Azure.AI.Projects
2. Azure.AI.Agents.Persistent samples: .../Azure.AI.Agents.Persistent/samples
3. Microsoft Foundry Samples: github.com/microsoft-foundry/foundry-samples
**Find**:
- Method signatures for [specific API]
- Usage examples (pseudocode only)
- Any gotchas or edge cases
**Return** (max 20 lines):
- Key method name and signature
- Code pattern (pseudocode)
- File path where found (for later reference)
Do NOT include full file contents.",
description: "SDK research: [topic]"
)
| Delegate to Subagent | Keep Inline |
|---|---|
| Multi-repo code search | Local codebase grep |
| Finding all usages | Known method lookup |
| API surface exploration | Single file read |
| Pattern comparison | Quick signature check |
| Sample discovery | Using known pattern |
The Azure AI Foundry SDK has two API surfaces for agents:
| API | Endpoint | ID Format | SDK Access |
|---|---|---|---|
| v2 Agents API | /agents/ | Human-readable (e.g., dadjokes) | AIProjectClient.Agents |
| OpenAI Assistants API | /assistants/ | OpenAI format (e.g., asst_xxx) | PersistentAgentsClient |
This project uses v2 Agents API for human-readable agent IDs.
Azure.AI.Projects (Main Entry Point)
├── AIProjectClient
│ ├── .Agents.GetAgentAsync() → AgentRecord (v2 Agents API)
│ ├── .GetPersistentAgentsClient() → PersistentAgentsClient (Assistants API)
│ └── .OpenAI.GetProjectResponsesClientForAgent() → ProjectResponsesClient (Responses API)
└── Sub-namespaces:
├── Azure.AI.Projects.OpenAI (Responses API, conversations)
└── OpenAI.Responses (streaming types)
Azure.AI.Projects SDK: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/ai/Azure.AI.Projects
tests/Samples/ folder with full examplesAzure.AI.Agents.Persistent SDK: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/ai/Azure.AI.Agents.Persistent
Sample9_PersistentAgents_Streaming.md - Basic streaming patternSample8_PersistentAgents_FunctionsWithStreaming.md - Tool calls with streamingSample27_PersistentAgents_MCP_Streaming.md - MCP server integrationMicrosoft Foundry Samples: https://github.com/microsoft-foundry/foundry-samples
samples/csharp/quickstart/quickstart-chat-with-agent.cs - Responses API patternsamples/csharp/quickstart/ - Multiple quickstart examplesKey pattern from official quickstart:
AIProjectClient projectClient = new(new Uri(projectEndpoint), new AzureCliCredential());
ProjectConversation conversation = projectClient.OpenAI.Conversations.CreateProjectConversation();
ProjectResponsesClient responsesClient = projectClient.OpenAI.GetProjectResponsesClientForAgent(
defaultAgent: agentName,
defaultConversationId: conversation.Id);
ResponseResult response = responsesClient.CreateResponse("Your prompt");
Baseline Chat App: https://github.com/Azure-Samples/microsoft-foundry-baseline
website/chatui/Controllers/ChatController.cs - SSE streaming patternBasic Chat Example: https://github.com/Azure-Samples/microsoft-foundry-basic
Semantic Kernel + Foundry: https://github.com/Azure-Samples/app-service-agentic-semantic-kernel-ai-foundry-agent
Azure AI Agents React Sample: https://github.com/Azure-Samples/get-started-with-ai-agents
This is the primary UI reference for this project. Many UI patterns were borrowed from here:
Agent Framework DevUI: https://github.com/microsoft/agent-framework/tree/main/python/packages/devui
Alternative UI patterns for agent development:
When implementing new UI features, check these sources in order:
get-started-with-ai-agents - React + TypeScript patterns for chat UIagent-framework/devui - Development UI patternsRepository: https://github.com/microsoft/semantic-kernel
Relevant paths:
dotnet/src/Agents/OpenAI/ - OpenAI Responses API integrationdotnet/samples/GettingStartedWithAgents/AzureAIAgent/dotnet/samples/Concepts/Agents/ (Step##_*.cs files)Repository: https://github.com/openai/openai-dotnet
docs/guides/streaming-responses/ - Streaming patternsStreamingResponseOutputTextDeltaUpdate and related typesUse GitHub search to find usage examples:
# Find streaming patterns
"StreamingResponseOutputTextDeltaUpdate language:csharp"
# Find Responses API usage
"ProjectResponsesClient CreateResponseStreamingAsync language:csharp"
# Find conversation patterns
"ProjectConversation GetProjectResponsesClientForAgent language:csharp"
| Package | Version | Purpose |
|---|---|---|
Azure.AI.Projects | 1.2.0-beta.5 | Main entry point, AIProjectClient, v2 Agents API, Responses API |
Azure.Identity | 1.17.1 | Authentication (AzureDeveloperCliCredential, ManagedIdentityCredential) |
Microsoft.Identity.Web | 4.3.0 | JWT Bearer authentication for API |
Note: This project uses Azure.AI.Projects beta for v2 Agents API access (AIProjectClient.Agents). The stable version does not include the v2 Agents API.
Sub-namespaces available (not separate packages):
Azure.AI.Projects.OpenAI - Responses API, conversationsOpenAI.Responses - Streaming typesAvailable Package: Microsoft.Agents.AI.AzureAI v1.0.0-preview.260108.1+ now supports v2 Agents API via AIProjectClient extension methods. See "Microsoft Agent Framework" section below for evaluation notes.
Key Resources:
The SDK provides several annotation types for citations (from OpenAI.Responses namespace):
| Type | Class | Use Case | Key Properties |
|---|---|---|---|
| URI Citation | UriCitationMessageAnnotation | Bing, Azure AI Search, SharePoint | Uri, Title, StartIndex, EndIndex |
| File Citation | FileCitationMessageAnnotation | File search (vector stores) | FileId, Filename, Index |
| File Path | FilePathMessageAnnotation | Code interpreter output | FileId, Index |
| Container Citation | ContainerFileCitationMessageAnnotation | Container file citations | FileId, Filename, StartIndex, EndIndex |
Note: FileCitationMessageAnnotation uses Index (not StartIndex/EndIndex) per the SDK. See ExtractAnnotations() in AgentFrameworkService.cs for mapping to AnnotationInfo.
| Type | Purpose |
|---|---|
StreamingResponseOutputTextDeltaUpdate | Text content delta chunks |
StreamingResponseOutputItemDoneUpdate | Item completion signals |
StreamingResponseCompletedUpdate | Response completion with usage |
ResponseItem | Base type for response items |
Pattern used in this project:
await foreach (var update in responsesClient.CreateResponseStreamingAsync(...))
{
if (update is StreamingResponseOutputTextDeltaUpdate textUpdate)
yield return new StreamChunk { Text = textUpdate.Delta };
if (update is StreamingResponseOutputItemDoneUpdate itemDone)
// Extract annotations from itemDone.Item
}
Package: Microsoft.Agents.AI.AzureAI v1.0.0-preview.260108.1
Status: ✅ Installed and active. As of January 2026, Agent Framework supports v2 Agents API via AIProjectClient extension methods.
This project uses a hybrid approach:
// ✅ Agent loading via Agent Framework (simple)
ChatClientAgent agent = await aiProjectClient.GetAIAgentAsync(
name: "dadjokes", // Human-readable agent name
cancellationToken: ct);
// Access AgentVersion for metadata
AgentVersion? version = agent.GetService<AgentVersion>();
var definition = version?.Definition as PromptAgentDefinition;
// ❌ Direct SDK for streaming (Agent Framework can't do this yet)
ProjectResponsesClient responsesClient = projectClient.OpenAI.GetProjectResponsesClientForAgent(
new AgentReference(_agentId), conversationId);
await foreach (var update in responsesClient.CreateResponseStreamingAsync(...)) { }
ChatClientAgent.RunStreamingAsync() returns IAsyncEnumerable<AgentRunResponseUpdate>, which provides:
Text — text content (✅ works)RawRepresentation — underlying SDK object (can cast at runtime)The problem: The IChatClient abstraction doesn't directly expose:
McpToolCallApprovalRequestItem for MCP approval flowsFileSearchCallResponseItem for file search quotesMessageResponseItem.OutputTextAnnotations for citationsWorkaround exists but adds complexity: Cast RawRepresentation to underlying types:
await foreach (var update in agent.RunStreamingAsync(message, thread))
{
if (update.RawRepresentation is StreamingResponseOutputItemDoneUpdate itemDone)
{
if (itemDone.Item is McpToolCallApprovalRequestItem mcpApproval)
{
// Handle MCP approval...
}
}
}
Why we use direct SDK instead:
RawRepresentation defeats the abstraction benefitResponseItem.CreateMcpApprovalResponseItem() anyway.Text propertyAIFunction handlingWhen Agent Framework matures to expose annotations/MCP through its abstractions, we could simplify to:
// Hypothetical future API
await foreach (var update in agent.RunStreamingAsync(message, thread))
{
if (update.IsMcpApproval) { } // Doesn't exist yet
if (update.HasAnnotations) { } // Doesn't exist yet
}
Track progress at: https://github.com/microsoft/Agents-for-net
Resources:
The SDK has evolved from connection string-based auth to project endpoint:
Old pattern (deprecated):
// DON'T USE - connection string deprecated in v1.0.0-beta.9+
var projectClient = new AIProjectClient(connectionString, new DefaultAzureCredential());
New pattern (current):
// USE THIS - project endpoint
var projectClient = new AIProjectClient(new Uri(projectEndpoint), new DefaultAzureCredential());
Type definitions live in these repos—read them directly:
Search across all .NET codebases for real-world usage:
"ProjectResponsesClient CreateResponseStreamingAsync" language:csharp
"StreamingResponseOutputTextDeltaUpdate" language:csharp
This finds how other projects use these APIs, revealing patterns and edge cases.
Only use when all above methods fail and you need to verify exact signatures on a pre-release SDK:
cd backend/WebApp.Api; dotnet build
$asm = [Reflection.Assembly]::LoadFrom((Resolve-Path "bin/Debug/net9.0/Azure.AI.Projects.dll"))
# Find types matching a pattern
$asm.GetExportedTypes() | Where-Object { $_.Name -like "*Streaming*" } | ForEach-Object { $_.FullName }
# Get method signatures
$asm.GetType("Azure.AI.Projects.OpenAI.ProjectResponsesClient").GetMethods() | Select-Object Name, ReturnType
Limitations: