Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.Agents" Version="2.0.0-alpha.20251016.2" />
<PackageReference Include="Azure.Identity" Version="1.17.0" />
<PackageReference Include="Azure.AI.Projects" Version="1.2.0-alpha.20260128.1" />
<PackageReference Include="Azure.AI.Projects.OpenAI" Version="1.0.0-alpha.20260128.1" />
<PackageReference Include="Azure.Identity" Version="1.17.1" />
<PackageReference Include="DotNetEnv" Version="3.1.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
// <imports_and_includes>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Azure;
using Azure.AI.Agents;
using Azure.AI.Projects;
using Azure.AI.Projects.OpenAI;
using Azure.Core;
using Azure.Identity;
using DotNetEnv;
using OpenAI;
using OpenAI.Responses;
using System;
using System.Collections.Generic;
using System.IO.Enumeration;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Threading.Tasks;
// </imports_and_includes>

#pragma warning disable OPENAI001
class EvaluateProgram
{
private static string GetFile(string name, [CallerFilePath] string pth = "")
{
var dirName = Path.GetDirectoryName(pth) ?? "";
return Path.Combine(dirName, "..", "shared", name);
}

static async Task Main(string[] args)
{
// Load environment variables from shared directory
Env.Load("../shared/.env");
Env.Load(GetFile(".env"));

var projectEndpoint = Environment.GetEnvironmentVariable("PROJECT_ENDPOINT");
var modelDeploymentName = Environment.GetEnvironmentVariable("MODEL_DEPLOYMENT_NAME");
Expand All @@ -38,19 +44,28 @@ static async Task Main(string[] args)
credential = new DefaultAzureCredential();
}

AgentsClient client = new(new Uri(projectEndpoint), credential);
AIProjectClient client = new(new Uri(projectEndpoint), credential);

Console.WriteLine("🧪 Modern Workplace Assistant Evaluation\n");

List<ToolDefinition> tools = new();
var instructions = @"You are a Modern Workplace Assistant for Contoso Corporation.
Answer questions using available tools and provide specific, detailed responses.";
PromptAgentDefinition agentDefinition = new PromptAgentDefinition(modelDeploymentName)
{
Instructions = instructions
};

// Add SharePoint tool if configured
if (!string.IsNullOrEmpty(sharepointConnectionId))
{
try
{
SharepointToolDefinition sharepointTool = new(new SharepointGroundingToolParameters(sharepointConnectionId));
tools.Add(sharepointTool);
SharePointGroundingToolOptions sharepointToolOption = new()
{
ProjectConnections = { new ToolProjectConnection(projectConnectionId: sharepointConnectionId) }
};
SharepointPreviewTool sharepointTool = new(sharepointToolOption);
agentDefinition.Tools.Add(sharepointTool);
Console.WriteLine("✅ SharePoint configured for evaluation");
}
catch (Exception ex)
Expand All @@ -64,8 +79,12 @@ static async Task Main(string[] args)
{
try
{
MCPToolDefinition mcpTool = new("microsoft_learn", mcpServerUrl);
tools.Add(mcpTool);
McpTool mcpTool = ResponseTool.CreateMcpTool(
serverLabel: "microsoft_learn",
serverUri: new Uri(mcpServerUrl),
toolCallApprovalPolicy: new McpToolCallApprovalPolicy(GlobalMcpToolCallApprovalPolicy.NeverRequireApproval)
);
agentDefinition.Tools.Add(mcpTool);
Console.WriteLine("✅ MCP configured for evaluation");
}
catch (Exception ex)
Expand All @@ -76,22 +95,13 @@ static async Task Main(string[] args)

Console.WriteLine();

var instructions = @"You are a Modern Workplace Assistant for Contoso Corporation.
Answer questions using available tools and provide specific, detailed responses.";

AgentDefinition agentDefinition = new PromptAgentDefinition(modelDeploymentName)
{
Instructions = instructions,
Tools = tools
};

AgentVersion agent = await client.CreateAgentVersionAsync(
"Evaluation Agent",
agentDefinition
AgentVersion agent = await client.Agents.CreateAgentVersionAsync(
agentName: "EvaluationAgent",
options: new(agentDefinition)
);

// <load_test_data>
var questions = File.ReadAllLines("../shared/questions.jsonl")
var questions = File.ReadAllLines(GetFile("questions.jsonl"))
.Select(line => JsonSerializer.Deserialize<JsonElement>(line))
.ToList();
// </load_test_data>
Expand All @@ -114,20 +124,14 @@ static async Task Main(string[] args)
.Select(e => e.GetString()!)
.ToArray();
}

Console.WriteLine($"Question {i + 1}/{questions.Count}: {question}");

// Get OpenAI client from the agents client
OpenAIClient openAIClient = client.GetOpenAIClient();
OpenAIResponseClient responseClient = openAIClient.GetOpenAIResponseClient(modelDeploymentName);
Console.WriteLine($"Question {i + 1}/{questions.Count}: {question}");

// Create a conversation to maintain state
AgentConversation conversation = await client.GetConversationsClient().CreateConversationAsync();
ProjectConversation conversation = await client.OpenAI.Conversations.CreateProjectConversationAsync();

// Set up response creation options with agent and conversation references
ResponseCreationOptions responseCreationOptions = new();
responseCreationOptions.SetAgentReference(agent.Name);
responseCreationOptions.SetConversationReference(conversation);
// Get OpenAI client from the agents client
ProjectResponsesClient responseClient = client.OpenAI.GetProjectResponsesClientForAgent(agent, conversation.Id);

// Create the user message item
List<ResponseItem> items = [ResponseItem.CreateUserMessageItem(question)];
Expand All @@ -136,7 +140,7 @@ static async Task Main(string[] args)
try
{
// Create response from the agent
OpenAIResponse openAIResponse = await responseClient.CreateResponseAsync(items, responseCreationOptions);
ResponseResult openAIResponse = await responseClient.CreateResponseAsync(items);
response = openAIResponse.GetOutputText();
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="local-preview" value="F:\git\agentsv2-preview\dotnet\package" />
<add key="local-packages" value="../dist" />
</packageSources>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.Agents" Version="2.0.0-alpha.20251016.2" />
<PackageReference Include="Azure.Identity" Version="1.13.1" />
<PackageReference Include="Azure.AI.Projects" Version="1.2.0-alpha.20260128.1" />
<PackageReference Include="Azure.AI.Projects.OpenAI" Version="1.0.0-alpha.20260128.1" />
<PackageReference Include="Azure.Identity" Version="1.17.1" />
<PackageReference Include="DotNetEnv" Version="3.1.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure;
using Azure.AI.Agents;
using Azure.AI.Projects;
using Azure.AI.Projects.OpenAI;
using Azure.Core;
using Azure.Identity;
using DotNetEnv;
using OpenAI;
using OpenAI.Responses;
// </imports_and_includes>

/*
* Azure AI Foundry Agent Sample - Tutorial 1: Modern Workplace Assistant
*
*
* This sample demonstrates a complete business scenario using Azure AI Agents SDK v2:
* - Agent creation with the new SDK
* - Conversation and response management
* - Robust error handling and graceful degradation
*
*
* Educational Focus:
* - Enterprise AI patterns with Agent SDK v2
* - Real-world business scenarios that enterprises face daily
* - Production-ready error handling and diagnostics
* - Foundation for governance, evaluation, and monitoring (Tutorials 2-3)
*
*
* Business Scenario:
* An employee needs to implement Azure AD multi-factor authentication. They need:
* 1. Company security policy requirements
Expand All @@ -36,9 +35,9 @@

class Program
{
private static AgentsClient? agentsClient;
private static OpenAIResponseClient? responseClient;
private static AgentConversation? conversation;
private static AIProjectClient? projectClient;
private static ProjectResponsesClient? responseClient;
private static ProjectConversation? conversation;

static async Task Main(string[] args)
{
Expand All @@ -57,7 +56,7 @@ static async Task Main(string[] args)
// Offer interactive testing
Console.Write("\n🎯 Try interactive mode? (y/n): ");
var response = Console.ReadLine();
if (response?.ToLower().StartsWith("y") == true)
if (response?.StartsWith("y", StringComparison.CurrentCultureIgnoreCase) == true)
{
await InteractiveModeAsync(agentName);
}
Expand All @@ -79,17 +78,17 @@ static async Task Main(string[] args)

/// <summary>
/// Create a Modern Workplace Assistant using Agent SDK v2.
///
///
/// This demonstrates enterprise AI patterns:
/// 1. Agent creation with the new SDK
/// 2. Robust error handling with graceful degradation
/// 3. Clear diagnostic information for troubleshooting
///
///
/// Educational Value:
/// - Shows real-world complexity of enterprise AI systems
/// - Demonstrates how to handle partial system failures
/// - Provides patterns for agent creation with Agent SDK v2
///
///
/// Note: Tool integration (SharePoint, MCP) is being explored for SDK v2 beta.
/// This version demonstrates the core agent functionality.
/// </summary>
Expand Down Expand Up @@ -124,7 +123,7 @@ private static async Task<string> CreateWorkplaceAssistantAsync()
credential = new DefaultAzureCredential();
}

agentsClient = new AgentsClient(new Uri(projectEndpoint), credential);
projectClient = new AIProjectClient(new Uri(projectEndpoint), credential);
Console.WriteLine($"✅ Connected to Azure AI Foundry: {projectEndpoint}");
// </agent_authentication>

Expand All @@ -133,22 +132,22 @@ private static async Task<string> CreateWorkplaceAssistantAsync()
// ========================================================================
string instructions = @"You are a Technical Assistant specializing in Azure and Microsoft 365 guidance.

CAPABILITIES:
- Provide detailed Azure and Microsoft 365 technical guidance
- Explain implementation steps and best practices
- Help with Azure AD, Conditional Access, MFA, and security configurations
CAPABILITIES:
- Provide detailed Azure and Microsoft 365 technical guidance
- Explain implementation steps and best practices
- Help with Azure AD, Conditional Access, MFA, and security configurations

RESPONSE STRATEGY:
- Provide comprehensive technical guidance
- Include step-by-step implementation instructions
- Reference best practices and security considerations
- For policy questions, explain common enterprise policies and how to implement them
- For technical questions, provide detailed Azure/M365 implementation steps
RESPONSE STRATEGY:
- Provide comprehensive technical guidance
- Include step-by-step implementation instructions
- Reference best practices and security considerations
- For policy questions, explain common enterprise policies and how to implement them
- For technical questions, provide detailed Azure/M365 implementation steps

EXAMPLE SCENARIOS:
- ""What is a typical enterprise MFA policy?"" → Explain common MFA policies and their implementation
- ""How do I configure Azure AD Conditional Access?"" → Provide detailed technical steps
- ""What are the best practices for remote work security?"" → Combine policy recommendations with implementation guidance";
EXAMPLE SCENARIOS:
- ""What is a typical enterprise MFA policy?"" → Explain common MFA policies and their implementation
- ""How do I configure Azure AD Conditional Access?"" → Provide detailed technical steps
- ""What are the best practices for remote work security?"" → Combine policy recommendations with implementation guidance";

// <create_agent>
Console.WriteLine($"🛠️ Creating agent with model: {modelDeploymentName}");
Expand All @@ -158,9 +157,9 @@ private static async Task<string> CreateWorkplaceAssistantAsync()
Instructions = instructions
};

AgentVersion agent = await agentsClient.CreateAgentVersionAsync(
"Modern_Workplace_Assistant",
agentDefinition
AgentVersion agent = await projectClient.Agents.CreateAgentVersionAsync(
agentName: "ModernWorkplaceAssistant",
options: new(agentDefinition)
);

Console.WriteLine("✅ Agent created successfully");
Expand All @@ -172,22 +171,21 @@ private static async Task<string> CreateWorkplaceAssistantAsync()
Console.WriteLine(" - Tool integration patterns being finalized");
// </create_agent>

// Initialize OpenAI client for conversations
OpenAIClient openAIClient = agentsClient.GetOpenAIClient();
responseClient = openAIClient.GetOpenAIResponseClient(modelDeploymentName);

// Create a conversation to maintain state
conversation = await agentsClient.GetConversationsClient().CreateConversationAsync();
conversation = await projectClient.OpenAI.Conversations.CreateProjectConversationAsync();

// Initialize ProjectResponsesClient for conversations
responseClient = projectClient.OpenAI.GetProjectResponsesClientForAgent(agent, conversation.Id);

return agent.Name;
}

/// <summary>
/// Demonstrate realistic business scenarios with Agent SDK v2.
///
///
/// This function showcases the practical value of the Modern Workplace Assistant
/// by walking through scenarios that enterprise employees face regularly.
///
///
/// Educational Value:
/// - Shows real business problems that AI agents can solve
/// - Demonstrates proper conversation and response management
Expand Down Expand Up @@ -274,9 +272,9 @@ private static async Task DemonstrateBusinessScenariosAsync(string agentName)

/// <summary>
/// Execute a conversation with the workplace assistant using Agent SDK v2.
///
///
/// This function demonstrates the conversation pattern for Azure AI Agents SDK v2.
///
///
/// Educational Value:
/// - Shows proper conversation management with Agent SDK v2
/// - Demonstrates conversation creation and message handling
Expand All @@ -287,16 +285,11 @@ private static async Task DemonstrateBusinessScenariosAsync(string agentName)
try
{
// <create_response>
// Set up response creation options with agent and conversation references
ResponseCreationOptions responseCreationOptions = new();
responseCreationOptions.SetAgentReference(agentName);
responseCreationOptions.SetConversationReference(conversation!);

// Create the user message item
List<ResponseItem> items = [ResponseItem.CreateUserMessageItem(message)];

// Create response from the agent
OpenAIResponse response = await responseClient!.CreateResponseAsync(items, responseCreationOptions);
ResponseResult response = await responseClient!.CreateResponseAsync(items);

// Extract the response text
string responseText = response.GetOutputText();
Expand All @@ -317,7 +310,7 @@ private static async Task DemonstrateBusinessScenariosAsync(string agentName)

/// <summary>
/// Interactive mode for testing the workplace assistant.
///
///
/// This provides a simple interface for users to test the agent with their own questions
/// and see how it provides comprehensive technical guidance.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="local-preview" value="F:\git\agentsv2-preview\dotnet\package" />
<add key="local-packages" value="../dist" />
</packageSources>
</configuration>
Loading