mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
628bb1af48
* 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
166 lines
7.4 KiB
C#
166 lines
7.4 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.ClientModel.Primitives;
|
|
using System.IO;
|
|
using Azure.AI.Projects.Agents;
|
|
|
|
namespace Microsoft.Agents.AI.Foundry.UnitTests;
|
|
|
|
/// <summary>
|
|
/// Utility class for loading and processing test data files.
|
|
/// </summary>
|
|
internal static class TestDataUtil
|
|
{
|
|
private static readonly string s_agentResponseJson = File.ReadAllText("TestData/AgentResponse.json");
|
|
private static readonly string s_agentVersionResponseJson = File.ReadAllText("TestData/AgentVersionResponse.json");
|
|
private static readonly string s_openAIDefaultResponseJson = File.ReadAllText("TestData/OpenAIDefaultResponse.json");
|
|
|
|
private const string AgentDefinitionPlaceholder = "\"agent-definition-placeholder\"";
|
|
|
|
private const string DefaultAgentDefinition = """
|
|
{
|
|
"kind": "prompt",
|
|
"model": "gpt-5-mini",
|
|
"instructions": "You are a storytelling agent. You craft engaging one-line stories based on user prompts and context.",
|
|
"tools": []
|
|
}
|
|
""";
|
|
|
|
/// <summary>
|
|
/// Gets the agent response JSON with optional placeholder replacements applied.
|
|
/// </summary>
|
|
public static string GetAgentResponseJson(string? agentName = null, AgentDefinition? agentDefinition = null, string? instructions = null, string? description = null)
|
|
{
|
|
var json = s_agentResponseJson;
|
|
json = ApplyAgentName(json, agentName);
|
|
json = ApplyAgentDefinition(json, agentDefinition);
|
|
json = ApplyInstructions(json, instructions);
|
|
json = ApplyDescription(json, description);
|
|
return json;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the agent version response JSON with optional placeholder replacements applied.
|
|
/// </summary>
|
|
public static string GetAgentVersionResponseJson(string? agentName = null, AgentDefinition? agentDefinition = null, string? instructions = null, string? description = null)
|
|
{
|
|
var json = s_agentVersionResponseJson;
|
|
json = ApplyAgentName(json, agentName);
|
|
json = ApplyAgentDefinition(json, agentDefinition);
|
|
json = ApplyInstructions(json, instructions);
|
|
json = ApplyDescription(json, description);
|
|
return json;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the agent version response JSON with empty version and ID fields for testing hosted agents like MCP agents.
|
|
/// </summary>
|
|
public static string GetAgentVersionResponseJsonWithEmptyVersion(string? agentName = null, AgentDefinition? agentDefinition = null, string? instructions = null, string? description = null)
|
|
{
|
|
var json = s_agentVersionResponseJson;
|
|
json = ApplyAgentName(json, agentName);
|
|
json = ApplyAgentDefinition(json, agentDefinition);
|
|
json = ApplyInstructions(json, instructions);
|
|
json = ApplyDescription(json, description);
|
|
// Remove the version and id fields to simulate hosted agents without version
|
|
json = json.Replace("\"version\": \"1\",", "\"version\": \"\",")
|
|
.Replace("\"id\": \"agent_abc123:1\",", "\"id\": \"\",");
|
|
return json;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the agent response JSON with empty version and ID fields in the latest version for testing hosted agents like MCP agents.
|
|
/// </summary>
|
|
public static string GetAgentResponseJsonWithEmptyVersion(string? agentName = null, AgentDefinition? agentDefinition = null, string? instructions = null, string? description = null)
|
|
{
|
|
var json = s_agentResponseJson;
|
|
json = ApplyAgentName(json, agentName);
|
|
json = ApplyAgentDefinition(json, agentDefinition);
|
|
json = ApplyInstructions(json, instructions);
|
|
json = ApplyDescription(json, description);
|
|
// Remove the version and id fields to simulate hosted agents without version
|
|
json = json.Replace("\"version\": \"1\",", "\"version\": \"\",")
|
|
.Replace("\"id\": \"agent_abc123:1\",", "\"id\": \"\",");
|
|
return json;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the agent version response JSON with whitespace-only version and ID fields for testing hosted agents like MCP agents.
|
|
/// </summary>
|
|
public static string GetAgentVersionResponseJsonWithWhitespaceVersion(string? agentName = null, AgentDefinition? agentDefinition = null, string? instructions = null, string? description = null)
|
|
{
|
|
var json = s_agentVersionResponseJson;
|
|
json = ApplyAgentName(json, agentName);
|
|
json = ApplyAgentDefinition(json, agentDefinition);
|
|
json = ApplyInstructions(json, instructions);
|
|
json = ApplyDescription(json, description);
|
|
// Use whitespace-only version and id fields to simulate hosted agents without version
|
|
return json
|
|
.Replace("\"version\": \"1\",", "\"version\": \" \",")
|
|
.Replace("\"id\": \"agent_abc123:1\",", "\"id\": \" \",");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the agent response JSON with whitespace-only version and ID fields in the latest version for testing hosted agents like MCP agents.
|
|
/// </summary>
|
|
public static string GetAgentResponseJsonWithWhitespaceVersion(string? agentName = null, AgentDefinition? agentDefinition = null, string? instructions = null, string? description = null)
|
|
{
|
|
var json = s_agentResponseJson;
|
|
json = ApplyAgentName(json, agentName);
|
|
json = ApplyAgentDefinition(json, agentDefinition);
|
|
json = ApplyInstructions(json, instructions);
|
|
json = ApplyDescription(json, description);
|
|
// Use whitespace-only version and id fields to simulate hosted agents without version
|
|
return json
|
|
.Replace("\"version\": \"1\",", "\"version\": \" \",")
|
|
.Replace("\"id\": \"agent_abc123:1\",", "\"id\": \" \",");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the OpenAI default response JSON with optional placeholder replacements applied.
|
|
/// </summary>
|
|
public static string GetOpenAIDefaultResponseJson(string? agentName = null, AgentDefinition? agentDefinition = null, string? instructions = null, string? description = null)
|
|
{
|
|
var json = s_openAIDefaultResponseJson;
|
|
json = ApplyAgentName(json, agentName);
|
|
json = ApplyAgentDefinition(json, agentDefinition);
|
|
json = ApplyInstructions(json, instructions);
|
|
json = ApplyDescription(json, description);
|
|
return json;
|
|
}
|
|
|
|
private static string ApplyAgentName(string json, string? agentName)
|
|
{
|
|
if (!string.IsNullOrEmpty(agentName))
|
|
{
|
|
return json.Replace("\"agent_abc123\"", $"\"{agentName}\"");
|
|
}
|
|
return json;
|
|
}
|
|
|
|
private static string ApplyAgentDefinition(string json, AgentDefinition? definition)
|
|
{
|
|
return (definition is not null)
|
|
? json.Replace(AgentDefinitionPlaceholder, ModelReaderWriter.Write(definition).ToString())
|
|
: json.Replace(AgentDefinitionPlaceholder, DefaultAgentDefinition);
|
|
}
|
|
|
|
private static string ApplyInstructions(string json, string? instructions)
|
|
{
|
|
if (!string.IsNullOrEmpty(instructions))
|
|
{
|
|
return json.Replace("You are a storytelling agent. You craft engaging one-line stories based on user prompts and context.", instructions);
|
|
}
|
|
return json;
|
|
}
|
|
|
|
private static string ApplyDescription(string json, string? description)
|
|
{
|
|
if (!string.IsNullOrEmpty(description))
|
|
{
|
|
return json.Replace("\"description\": \"\"", $"\"description\": \"{description}\"");
|
|
}
|
|
return json;
|
|
}
|
|
}
|