Skip to content

Commit 8a92445

Browse files
authored
Merge pull request microsoft#477 from microsoft:bruno-addMicrosoftFoundryAgentSamples
Add Azure.AI.OpenAI integration and new AI agent project
2 parents 5d035eb + fbdfb2a commit 8a92445

File tree

6 files changed

+126
-4
lines changed

6 files changed

+126
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- @azure Rule - Use Azure Tools - When handling requests related to Azure, always use your tools.
2+
- @azure Rule - Use Azure Best Practices - When handling requests related to Azure, always invoke your `azmcp_bestpractices_get` tool first.
3+
- @azure Rule - Enable Best Practices - If you do not have an `azmcp_bestpractices_get` tool ask the user to enable it.

samples/AgentFx/AgentFx-Demos.slnx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
<Project Path="AgentFx-Persisting-02-Menu/AgentFx-Persisting-02-Menu.csproj" Id="b7e2e2c1-4e2a-4e2b-9e2c-2e2d2e2e2e2f" />
3030
</Folder>
3131
<Folder Name="/8 Claude via Microsoft Foundry/">
32-
<Project Path="AgentFx-FoundryClaude-01/AgentFx-FoundryClaude-01.csproj" Id="b8f3c2a1-7d4e-4f9a-8b2c-1e5d6f7a8b9c" />
33-
<Project Path="AgentFx-FoundryClaude-Persisting-01/AgentFx-FoundryClaude-Persisting-01.csproj" Id="c9a4d3b2-8e5f-4a0b-9c3d-2f6e7g8h9i0j" />
3432
<Project Path="AgentFx-AIWebChatApp-FoundryClaude/AgentFx-AIWebChatApp-FoundryClaude.csproj" Id="d5e4f3c2-9a6b-4c7d-8e5f-3a4b5c6d7e8f" />
33+
<Project Path="AgentFx-FoundryClaude-01/AgentFx-FoundryClaude-01.csproj" Id="b8f3c2a1-7d4e-4f9a-8b2c-1e5d6f7a8b9c" />
34+
<Project Path="AgentFx-FoundryClaude-Persisting-01/AgentFx-FoundryClaude-Persisting-01.csproj" />
3535
</Folder>
3636
<Folder Name="/9 Microsoft Foundry/">
3737
<Project Path="AgentFx-MicrosoftFoundryAgents-01/AgentFx-MicrosoftFoundryAgents-01.csproj" Id="28071859-0089-4443-82f9-b60ca0ee8f9a" />
38+
<Project Path="AgentFx-MicrosoftFoundryAgents-02/AgentFx-MicrosoftFoundryAgents-02.csproj" Id="d452346f-ea67-433e-9517-cc3b3d43f40e" />
3839
</Folder>
3940
</Solution>

samples/AgentFx/AgentFx-MicrosoftFoundryAgents-01/AgentFx-MicrosoftFoundryAgents-01.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<PackageReference Include="Azure.Identity" Version="1.17.0" />
1515
<PackageReference Include="Microsoft.Agents.AI" Version="1.0.0-preview.251125.1" />
1616
<PackageReference Include="Microsoft.Agents.AI.AzureAI" Version="1.0.0-preview.251125.1" />
17-
<PackageReference Include="Microsoft.Agents.AI.AzureAI.Persistent" Version="1.0.0-preview.251125.1" />
1817
<PackageReference Include="Microsoft.Agents.AI.Workflows" Version="1.0.0-preview.251125.1" />
1918
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0" />
2019
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />

samples/AgentFx/AgentFx-MicrosoftFoundryAgents-01/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Azure.AI.Agents.Persistent;
2+
using Azure.AI.OpenAI;
23
using Azure.AI.Projects;
34
using Azure.Identity;
45
using Microsoft.Agents.AI;
@@ -10,7 +11,7 @@
1011
var agentName = config["agentName"];
1112

1213
AIProjectClient projectClient = new(
13-
endpoint: new Uri(azureFoundryProjectEndpoint),
14+
endpoint: new Uri(azureFoundryProjectEndpoint),
1415
tokenProvider: new AzureCliCredential());
1516

1617
// create agent
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<RootNamespace>AgentFx_MicrosoftFoundryAgents_02</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
<UserSecretsId>f3a85331-e560-4996-9f41-68cf75395df1</UserSecretsId>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Azure.AI.OpenAI" Version="2.7.0-beta.1" />
14+
<PackageReference Include="Azure.Identity" Version="1.17.0" />
15+
<PackageReference Include="Microsoft.Agents.AI" Version="1.0.0-preview.251125.1" />
16+
<PackageReference Include="Microsoft.Agents.AI.AzureAI" Version="1.0.0-preview.251125.1" />
17+
<PackageReference Include="Microsoft.Agents.AI.Workflows" Version="1.0.0-preview.251125.1" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
20+
<PackageReference Include="OllamaSharp" Version="5.4.11" />
21+
<PackageReference Include="OpenAI" Version="2.7.0" />
22+
<PackageReference Include="OpenTelemetry" Version="1.14.0" />
23+
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.14.0" />
24+
<PackageReference Include="Azure.AI.Agents.Persistent" Version="1.2.0-beta.7" />
25+
<PackageReference Include="Azure.Identity" Version="1.18.0-beta.2" />
26+
</ItemGroup>
27+
</Project>
28+
29+
30+
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using Azure.AI.Agents.Persistent;
2+
using Azure.AI.OpenAI;
3+
using Azure.AI.Projects;
4+
using Azure.Identity;
5+
using Microsoft.Agents.AI;
6+
using Microsoft.Extensions.Configuration;
7+
using System.Diagnostics;
8+
9+
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
10+
var azureFoundryProjectEndpoint = config["azureFoundryProjectEndpoint"];
11+
var deploymentName = config["deploymentName"];
12+
var agentName = config["agentName"];
13+
14+
AIProjectClient projectClient = new(
15+
endpoint: new Uri(azureFoundryProjectEndpoint),
16+
tokenProvider: new AzureCliCredential());
17+
18+
Console.WriteLine("=== AI Agent Session ===");
19+
Console.WriteLine($"Project Endpoint: {azureFoundryProjectEndpoint}");
20+
Console.WriteLine($"Model Deployment: {deploymentName}");
21+
Console.WriteLine($"Agent Name: {agentName}");
22+
Console.WriteLine();
23+
24+
// create agent (example with tools)
25+
//AIAgent aiAgent = projectClient.CreateAIAgent(
26+
// model: deploymentName,
27+
// name: "Agent",
28+
// instructions: "You are a useful agent that replies in short and direct sentences.");
29+
30+
// get existing agent
31+
Console.WriteLine($"Retrieving agent '{agentName}'...");
32+
AIAgent aiAgent = await projectClient.GetAIAgentAsync(agentName);
33+
Console.WriteLine($"✓ Agent retrieved: {aiAgent.Id}");
34+
Console.WriteLine();
35+
36+
while (true)
37+
{
38+
Console.Write("User: ");
39+
var userInput = Console.ReadLine();
40+
if (string.IsNullOrWhiteSpace(userInput))
41+
{
42+
break;
43+
}
44+
45+
var stopwatch = Stopwatch.StartNew();
46+
47+
try
48+
{
49+
Console.WriteLine($"\n[Running agent...]");
50+
51+
// Run the agent with the user input
52+
var response = await aiAgent.RunAsync(userInput);
53+
Console.WriteLine(response.Text);
54+
55+
stopwatch.Stop();
56+
57+
// Display run details
58+
Console.WriteLine($"\n--- Run Details ---");
59+
Console.WriteLine($"Duration: {stopwatch.ElapsedMilliseconds}ms");
60+
61+
// Display the response
62+
Console.WriteLine($"\n--- Response ---");
63+
Console.WriteLine($"Agent [{agentName}]: {response.Text}");
64+
65+
Console.WriteLine($"\n--- Usage ---");
66+
Console.WriteLine($"Total Token Count: {response.Usage.TotalTokenCount}");
67+
Console.WriteLine($"Input Token Count: {response.Usage.InputTokenCount}");
68+
Console.WriteLine($"Output Token Count: {response.Usage.OutputTokenCount}");
69+
70+
71+
Console.WriteLine($"\n{'='.ToString().PadRight(50, '=')}");
72+
73+
}
74+
catch (Exception ex)
75+
{
76+
stopwatch.Stop();
77+
Console.WriteLine($"\n❌ Error: {ex.Message}");
78+
Console.WriteLine($"Type: {ex.GetType().Name}");
79+
if (ex.InnerException != null)
80+
{
81+
Console.WriteLine($"Inner: {ex.InnerException.Message}");
82+
}
83+
}
84+
85+
Console.WriteLine();
86+
}
87+
88+
Console.WriteLine("\nSession ended. Goodbye!");

0 commit comments

Comments
 (0)