Files
agent-framework/dotnet/tests/Foundry.IntegrationTests/ResponsesAgentExtensionCreateTests.cs
Roger Barreto 628bb1af48 .NET: Rename Microsoft.Agents.AI.AzureAI to Microsoft.Agents.AI.Foundry and consolidate FoundryMemory (#5042)
* Update Foundry Responses as ChatClientAgent

* Migrate obsolete AzureAI integration tests to versioned agent pattern

Replace obsolete CreateAIAgentAsync/GetAIAgentAsync calls with
Agents.CreateAgentVersionAsync() + AsAIAgent(AgentVersion) in all
AzureAI integration tests.

- Rename AIProjectClient* test files to FoundryVersionedAgent*
- Register AIFunction tools in PromptAgentDefinition.Tools for
  server-side visibility via AsOpenAIResponseTool()
- Skip structured output tests (AzureAIProjectChatClient clears
  ResponseFormat for versioned agents)
- Remove all [Obsolete] attributes and #pragma warning disable CS0618

* Merge FoundryMemory package into AzureAI under Memory/ folder

Move all FoundryMemory source, unit tests, and integration tests into
the Microsoft.Agents.AI.AzureAI package. Change namespace from
Microsoft.Agents.AI.FoundryMemory to Microsoft.Agents.AI.AzureAI.

- Add [Experimental] to FoundryMemoryProviderOptions and Scope
- Rename internal AIProjectClientExtensions to MemoryStoreExtensions
- Update AzureAI .csproj with Compliance.Abstractions, Redaction
- Remove FoundryMemory from solution and release filter
- Update sample to reference AzureAI instead of FoundryMemory
- Delete old Microsoft.Agents.AI.FoundryMemory project and tests

* Add EnsureMemoryStoreCreatedAsync and memory existence checks to integration tests

- Ensure memory store is created before testing memory operations
- Add AZURE_AI_EMBEDDING_DEPLOYMENT_NAME config setting
- Assert memories exist in store via SearchMemoriesAsync before cleanup
- Verify scope isolation with direct memory store queries

* Fix and rename AzureAI unit tests for RAPI vs Versioned clarity

- Rename AsAIAgentAsync_* to AsAIAgent_* (drop Async from method group)
- Add _Rapi_ prefix to non-versioned (Responses API) tests
- Add _Versioned_ prefix to versioned agent tests where needed
- Fix RAPI tests: assert GetService<AIProjectClient>() is null
- Fix Versioned tests: assert IsType<FoundryAgent> and
  GetService<AIProjectClient>() returns the client instance
- Fix UserAgent header tests: proper HTTP handler routing
- Fix ChatClient_UsesDefaultConversationIdAsync test setup
- All 153 unit tests pass with 0 failures

* Rename Microsoft.Agents.AI.AzureAI to Microsoft.Agents.AI.Foundry

Rename the project, namespace, folder, and all references from
Microsoft.Agents.AI.AzureAI to Microsoft.Agents.AI.Foundry.
Also rename Workflows.Declarative.AzureAI to .Foundry.

- Rename src, unit test, integration test, and workflow folders
- Update namespaces in all source and test .cs files
- Update ProjectReferences in ~47 sample and test .csproj files
- Update solution files (.slnx, .slnf)
- Update sample using statements
- Update READMEs, SKILL.md, ADRs in docs/
- Disable package validation baseline for renamed packages
- Fix UTF-8 BOM encoding on all affected .cs files
- AzureAI.Persistent left completely unchanged

* Fix format: remove ImplicitUsings, add explicit usings, fix BOM encoding

- Remove ImplicitUsings=enable from Foundry csproj to resolve IDE0005
  on shared ReplacingRedactor.cs
- Add explicit System usings to all source files that relied on them
- Sort usings alphabetically per editorconfig rules
- Fix UTF-8 BOM on 12 sample Program.cs files
- Rename Azure AI Foundry Agents to Microsoft Foundry Agents in docs
2026-04-02 01:25:24 +00:00

139 lines
5.3 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Threading.Tasks;
using AgentConformance.IntegrationTests.Support;
using Azure.AI.Extensions.OpenAI;
using Azure.AI.Projects;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using Shared.IntegrationTests;
namespace Foundry.IntegrationTests;
/// <summary>
/// Integration tests for non-versioned <see cref="ChatClientAgent"/> creation via <see cref="AIProjectClient"/> extension methods.
/// </summary>
public class ResponsesAgentExtensionCreateTests
{
private static Uri Endpoint => new(TestConfiguration.GetRequiredValue(TestSettings.AzureAIProjectEndpoint));
private static string Model => TestConfiguration.GetRequiredValue(TestSettings.AzureAIModelDeploymentName);
private readonly AIProjectClient _client = new(Endpoint, TestAzureCliCredentials.CreateAzureCliCredential());
[Fact]
public async Task AsAIAgent_WithModelAndInstructions_CreatesChatClientAgentAndRunsAsync()
{
// Arrange
const string AgentName = "ResponsesAgentExtensionSimple";
const string AgentDescription = "Integration test agent created from AIProjectClient.AsAIAgent(model, instructions).";
const string VerificationToken = "integration-extension-ok";
ChatClientAgent agent = this._client.AsAIAgent(
model: Model,
instructions: $"You are a helpful assistant. When asked for verification, reply with exactly '{VerificationToken}'.",
name: AgentName,
description: AgentDescription);
AgentSession? session = null;
try
{
var conversation = await CreateConversationAsync(this._client);
session = await agent.CreateSessionAsync(conversation.Id);
// Act
AgentResponse response = await agent.RunAsync("Return the verification token.", session);
// Assert
Assert.NotNull(agent);
Assert.Equal(AgentName, agent.Name);
Assert.Equal(AgentDescription, agent.Description);
Assert.NotNull(agent.GetService<IChatClient>());
Assert.Contains(VerificationToken, response.Text, StringComparison.OrdinalIgnoreCase);
}
finally
{
await DeleteSessionAsync(this._client, session);
}
}
[Fact]
public async Task AsAIAgent_WithOptions_CreatesChatClientAgentAndRunsAsync()
{
// Arrange
const string VerificationToken = "integration-options-ok";
ChatClientAgentOptions options = new()
{
Name = "ResponsesAgentExtensionOptions",
Description = "Integration test agent created from AIProjectClient.AsAIAgent(options).",
ChatOptions = new ChatOptions
{
ModelId = Model,
Instructions = $"You are a helpful assistant. When asked for verification, reply with exactly '{VerificationToken}'.",
},
};
ChatClientAgent agent = this._client.AsAIAgent(options);
ChatClientAgentSession? session = null;
try
{
var conversation = await CreateConversationAsync(this._client);
session = ((await agent.CreateSessionAsync(conversation.Id)) as ChatClientAgentSession)!;
// Act
AgentResponse response = await agent.RunAsync("Return the verification token.", session);
// Assert
Assert.StartsWith("conv_", session!.ConversationId, StringComparison.OrdinalIgnoreCase);
Assert.Equal(options.Name, agent.Name);
Assert.Equal(options.Description, agent.Description);
Assert.Contains(VerificationToken, response.Text, StringComparison.OrdinalIgnoreCase);
}
finally
{
await DeleteSessionAsync(this._client, session);
}
}
private static async Task DeleteSessionAsync(AIProjectClient client, AgentSession? session)
{
if (session is null)
{
return;
}
ChatClientAgentSession typedSession = (ChatClientAgentSession)session;
if (typedSession.ConversationId?.StartsWith("conv_", StringComparison.OrdinalIgnoreCase) == true)
{
await client.GetProjectOpenAIClient().GetProjectConversationsClient().DeleteConversationAsync(typedSession.ConversationId);
}
else if (typedSession.ConversationId?.StartsWith("resp_", StringComparison.OrdinalIgnoreCase) == true)
{
await DeleteResponseChainAsync(client, typedSession.ConversationId);
}
}
private static async Task DeleteResponseChainAsync(AIProjectClient client, string lastResponseId)
{
var responsesClient = client.GetProjectOpenAIClient().GetProjectResponsesClient();
var response = await responsesClient.GetResponseAsync(lastResponseId);
await responsesClient.DeleteResponseAsync(lastResponseId);
if (response.Value.PreviousResponseId is not null)
{
await DeleteResponseChainAsync(client, response.Value.PreviousResponseId);
}
}
private static async Task<ProjectConversation> CreateConversationAsync(AIProjectClient client)
{
ProjectConversationsClient conversationsClient = client.GetProjectOpenAIClient().GetProjectConversationsClient();
return (await conversationsClient.CreateProjectConversationAsync()).Value!;
}
}