Skip to content

Commit 2437a47

Browse files
Upgrade agent SDK nuget and add email support. (#489)
1 parent 77d9470 commit 2437a47

6 files changed

Lines changed: 31 additions & 66 deletions

File tree

samples/csharp/foundry-autopilot-agent/infra/main.bicep

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ param cognitiveServicesSku string = 'S0'
3333
@allowed(['Basic', 'Standard', 'Premium'])
3434
param containerRegistrySku string = 'Basic'
3535

36-
param agentName string = 'foundry-agent'
36+
param agentName string = 'foundry-autopilot-agent'
3737

3838
param maibName string = '${agentName}-maib'
3939

@@ -51,10 +51,10 @@ param botDisplayName string = '${agentName} Bot'
5151
param botServiceSku string = 'F0'
5252

5353
@description('Model name')
54-
param modelName string = 'gpt-5-chat'
54+
param modelName string = 'gpt-chat-latest'
5555

5656
@description('Model version')
57-
param modelVersion string = '2025-10-03'
57+
param modelVersion string = '2026-05-28'
5858

5959
// =================================================================================================
6060
// Common parameters

samples/csharp/foundry-autopilot-agent/src/hello_world_a365_agent/AgentLogic/A365AgentApplication.cs

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,7 @@ private void ConfigureMessageHandling()
4040
{
4141
var agent = await GetAgentFromRecipient(turnContext.Activity);
4242
var agentService = await _factory.CreateAsync(agent, turnContext, UserAuthorization);
43-
if (agent.IsMessagingEnabled || true)
44-
{
45-
// Use the specific email notification handler
46-
await agentService.HandleEmailNotificationAsync(turnContext, turnState, agentNotificationActivity);
47-
}
48-
else
49-
{
50-
await agentService.NewActivityReceived(turnContext, turnState, cancellationToken);
51-
}
43+
await agentService.HandleEmailNotificationAsync(turnContext, turnState, agentNotificationActivity);
5244
});
5345

5446
// Handle Word notifications
@@ -57,49 +49,25 @@ private void ConfigureMessageHandling()
5749
var agent = await GetAgentFromRecipient(turnContext.Activity);
5850
var agentService = await _factory.CreateAsync(agent, turnContext, UserAuthorization);
5951

60-
if (agent.IsMessagingEnabled)
61-
{
62-
// Use the specific comment notification handler for Word documents
63-
await agentService.HandleCommentNotificationAsync(turnContext, turnState, agentNotificationActivity);
64-
}
65-
else
66-
{
67-
await agentService.NewActivityReceived(turnContext, turnState, cancellationToken);
68-
}
52+
await agentService.HandleCommentNotificationAsync(turnContext, turnState, agentNotificationActivity);
6953
});
7054

7155
// Handle Excel notifications
7256
this.OnAgenticExcelNotification(async (turnContext, turnState, agentNotificationActivity, cancellationToken) =>
7357
{
7458
var agent = await GetAgentFromRecipient(turnContext.Activity);
7559
var agentService = await _factory.CreateAsync(agent, turnContext, UserAuthorization);
76-
77-
if (agent.IsMessagingEnabled)
78-
{
79-
// Use the specific comment notification handler for Excel documents
80-
await agentService.HandleCommentNotificationAsync(turnContext, turnState, agentNotificationActivity);
81-
}
82-
else
83-
{
84-
await agentService.NewActivityReceived(turnContext, turnState, cancellationToken);
85-
}
60+
// Use the specific comment notification handler for Excel documents
61+
await agentService.HandleCommentNotificationAsync(turnContext, turnState, agentNotificationActivity);
8662
});
8763

8864
// Handle PowerPoint notifications
8965
this.OnAgenticPowerPointNotification(async (turnContext, turnState, agentNotificationActivity, cancellationToken) =>
9066
{
9167
var agent = await GetAgentFromRecipient(turnContext.Activity);
9268
var agentService = await _factory.CreateAsync(agent, turnContext, UserAuthorization);
93-
94-
if (agent.IsMessagingEnabled)
95-
{
96-
// Use the specific comment notification handler for PowerPoint documents
97-
await agentService.HandleCommentNotificationAsync(turnContext, turnState, agentNotificationActivity);
98-
}
99-
else
100-
{
101-
await agentService.NewActivityReceived(turnContext, turnState, cancellationToken);
102-
}
69+
// Use the specific comment notification handler for PowerPoint documents
70+
await agentService.HandleCommentNotificationAsync(turnContext, turnState, agentNotificationActivity);
10371
});
10472

10573
OnActivity(ActivityTypes.Message, async (turnContext, turnState, cancellationToken) =>

samples/csharp/foundry-autopilot-agent/src/hello_world_a365_agent/AgentLogic/IAgentLogicService.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ public interface IAgentLogicService
3030
/// </summary>
3131
Task HandleCommentNotificationAsync(ITurnContext turnContext, ITurnState turnState, AgentNotificationActivity commentEvent);
3232

33-
/// <summary>
34-
/// Handles Teams message events
35-
/// </summary>
36-
Task HandleTeamsMessageAsync(ITurnContext turnContext, ITurnState turnState, AgentNotificationActivity teamsEvent);
37-
3833
/// <summary>
3934
/// Handles installation update events
4035
/// </summary>

samples/csharp/foundry-autopilot-agent/src/hello_world_a365_agent/AgentLogic/ResponsesApi/ResponsesApiAgentLogicService.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace HelloWorldA365.AgentLogic.ResponsesApi;
88
using Microsoft.Agents.Builder.State;
99
using Microsoft.Agents.Core.Models;
1010
using System.Net.Http.Headers;
11+
using System.Security.Cryptography;
1112
using System.Text;
1213
using System.Text.Json;
1314
using System.Text.Json.Serialization;
@@ -61,7 +62,8 @@ public async Task NewActivityReceived(ITurnContext turnContext, ITurnState turnS
6162
{
6263
incomingText = $"Respond to this chat message with chat id {turnContext.Activity.Conversation.Id} " +
6364
$"From: {sender?.Name} ({sender?.Id})\n" +
64-
$"Message: {incomingText}";
65+
$"Message: {incomingText}\n" +
66+
"If user hasn't explicitly asked to send teams messages don't use teams mcp tool to respond, that causes double responses.";
6567
}
6668
else if (turnContext.Activity.Type == ActivityTypes.InstallationUpdate)
6769
{
@@ -101,11 +103,17 @@ public async Task<string> NewChatReceived(string chatId, string fromUser, string
101103

102104
public async Task HandleEmailNotificationAsync(ITurnContext turnContext, ITurnState turnState, AgentNotificationActivity emailEvent)
103105
{
104-
_logger.LogInformation("Processing email notification (Responses API) - NotificationType: {NotificationType}", emailEvent.NotificationType);
106+
var fromEmail = emailEvent.From.Id;
107+
var emailJson = JsonSerializer.Serialize(emailEvent, new JsonSerializerOptions { WriteIndented = true });
105108
var conversationId = turnContext.Activity.Conversation?.Id ?? "email-notification";
106-
var response = await InvokeResponsesApiAsync(emailEvent.Text ?? string.Empty, conversationId);
107-
var responseActivity = MessageFactory.Text("a");
108-
responseActivity.Entities.Add(new EmailResponse(response));
109+
var response = await InvokeResponsesApiAsync($"You received a new email. Please look at the email and return a response in html format. From: {fromEmail}\nEmail details:\n{emailJson}", conversationId);
110+
var responseActivity = EmailResponse.CreateEmailResponseActivity(response);
111+
112+
_logger.LogInformation(
113+
"Outgoing email response activity - original ReplyToId={OriginalReplyToId}, ConversationId={ConversationId}",
114+
responseActivity.ReplyToId,
115+
responseActivity.Conversation?.Id);
116+
109117
await turnContext.SendActivityAsync(responseActivity);
110118
}
111119

@@ -115,12 +123,6 @@ public Task HandleCommentNotificationAsync(ITurnContext turnContext, ITurnState
115123
return Task.CompletedTask;
116124
}
117125

118-
public Task HandleTeamsMessageAsync(ITurnContext turnContext, ITurnState turnState, AgentNotificationActivity teamsEvent)
119-
{
120-
_logger.LogInformation("Processing Teams message (Responses API)");
121-
return Task.CompletedTask;
122-
}
123-
124126
public Task HandleInstallationUpdateAsync(ITurnContext turnContext, ITurnState turnState, AgentNotificationActivity installationEvent)
125127
{
126128
_logger.LogInformation("Processing installation update (Responses API)");
@@ -229,9 +231,10 @@ private static string GetResponseStoreDir()
229231

230232
private static string GetResponseIdFilePath(string conversationId)
231233
{
232-
// Sanitize conversation ID for use as filename
233-
var safeId = Convert.ToBase64String(Encoding.UTF8.GetBytes(conversationId))
234-
.Replace('/', '_').Replace('+', '-').TrimEnd('=');
234+
// SHA-256 hash conversation ID to produce a fixed-length, filesystem-safe filename
235+
// and avoid PathTooLongException for long conversation IDs.
236+
var hashBytes = SHA256.HashData(Encoding.UTF8.GetBytes(conversationId));
237+
var safeId = Convert.ToHexString(hashBytes).ToLowerInvariant();
235238
return Path.Combine(GetResponseStoreDir(), $"{safeId}.responseid");
236239
}
237240

samples/csharp/foundry-autopilot-agent/src/hello_world_a365_agent/HelloWorldA365Agent.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.15.1" />
3636
<PackageReference Include="System.Text.Json" Version="10.0.7" />
3737
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
38-
<PackageReference Include="Microsoft.Agents.Authentication.Msal" Version="1.6.9-*" />
39-
<PackageReference Include="Microsoft.Agents.Hosting.AspNetCore" Version="1.6.9-*" />
40-
<PackageReference Include="Microsoft.Agents.Storage" Version="1.6.9-*" />
41-
<PackageReference Include="Microsoft.Agents.Storage.Transcript" Version="1.6.9-*" />
38+
<PackageReference Include="Microsoft.Agents.Authentication.Msal" Version="1.6.109-*" />
39+
<PackageReference Include="Microsoft.Agents.Hosting.AspNetCore" Version="1.6.109-*" />
40+
<PackageReference Include="Microsoft.Agents.Storage" Version="1.6.109-*" />
41+
<PackageReference Include="Microsoft.Agents.Storage.Transcript" Version="1.6.109-*" />
4242
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.23.0" />
4343
<PackageReference Include="Microsoft.Bcl.Memory" Version="10.0.7" />
4444
<PackageReference Include="System.Runtime.Caching" Version="10.0.7" />

samples/csharp/foundry-autopilot-agent/src/hello_world_a365_agent/appsettings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
"Connections": {
4242
"ServiceConnection": {
4343
"Settings": {
44-
"AuthType": "UserManagedIdentity",
45-
"EnableContainerIMDS": true,
44+
"AuthType": "IdentityProxyManager",
4645
// Blueprint Client ID
4746
"ClientId": "",
4847
// https://login.microsoftonline.com/{{BOT_TENANT_ID}}

0 commit comments

Comments
 (0)