Skip to content

Commit ea52d21

Browse files
author
Jicheng Lu
committed
resolve conflict
2 parents 74060c0 + 98ce9b8 commit ea52d21

11 files changed

Lines changed: 48 additions & 12 deletions

File tree

src/Infrastructure/BotSharp.Abstraction/Conversations/Enums/MessageTypeName.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ namespace BotSharp.Abstraction.Conversations.Enums;
33
public static class MessageTypeName
44
{
55
public const string Plain = "plain";
6-
public const string Notification = "notification";
76
public const string FunctionCall = "function";
87
public const string Audio = "audio";
98
public const string Error = "error";

src/Infrastructure/BotSharp.Abstraction/Conversations/Models/Conversation.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ public class DialogMetaData
121121
[JsonPropertyName("sender_id")]
122122
public string? SenderId { get; set; }
123123

124+
/// <summary>
125+
/// When true, message is persisted but omitted from default LLM dialog history and routing conversation text.
126+
/// </summary>
127+
[JsonPropertyName("exclude_from_context")]
128+
public bool ExcludeFromContext { get; set; }
129+
124130
[JsonPropertyName("create_at")]
125131
public DateTime CreatedTime { get; set; }
126132
}

src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public class RoleDialogModel : ITrackableMessage
1919
/// </summary>
2020
public string MessageType { get; set; } = MessageTypeName.Plain;
2121

22+
/// <summary>
23+
/// When true, message is stored but omitted from default LLM history and routing <c>[CONVERSATION]</c> (orthogonal to <see cref="MessageType"/>).
24+
/// </summary>
25+
public bool ExcludeFromContext { get; set; }
26+
2227
/// <summary>
2328
/// The message label
2429
/// </summary>
@@ -191,6 +196,7 @@ public static RoleDialogModel From(RoleDialogModel source,
191196
CurrentAgentId = source.CurrentAgentId,
192197
MessageId = source.MessageId,
193198
MessageType = source.MessageType,
199+
ExcludeFromContext = source.ExcludeFromContext,
194200
MessageLabel = source.MessageLabel,
195201
ToolCallId = source.ToolCallId,
196202
FunctionName = source.FunctionName,

src/Infrastructure/BotSharp.Abstraction/MCP/Models/McpServerConfigModel.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@ public class McpServerConfigModel
2828
public string? Description { get; set; }
2929

3030
public McpSseServerConfig? SseConfig { get; set; }
31+
public McpHttpServerConfig? HttpConfig { get; set; }
3132
public McpStdioServerConfig? StdioConfig { get; set; }
3233
}
3334

34-
public class McpSseServerConfig
35+
public class McpSseServerConfig : McpHttpServerConfigBase
36+
{
37+
}
38+
39+
public class McpHttpServerConfig : McpHttpServerConfigBase
40+
{
41+
}
42+
43+
public class McpHttpServerConfigBase
3544
{
3645
public string EndPoint { get; set; } = null!;
3746
public TimeSpan ConnectionTimeout { get; init; } = TimeSpan.FromSeconds(30);
@@ -42,6 +51,6 @@ public class McpStdioServerConfig
4251
{
4352
public string Command { get; set; } = null!;
4453
public IList<string>? Arguments { get; set; }
45-
public Dictionary<string, string>? EnvironmentVariables { get; set; }
54+
public Dictionary<string, string?>? EnvironmentVariables { get; set; }
4655
public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromSeconds(5);
4756
}

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using BotSharp.Abstraction.Conversations.Enums;
21
using BotSharp.Abstraction.MLTasks;
32
using BotSharp.Abstraction.Models;
43
using BotSharp.Abstraction.Settings;
@@ -24,7 +23,6 @@ public async Task<string> GetConversationSummary(ConversationSummaryModel model)
2423

2524
if (dialogs.IsNullOrEmpty()) continue;
2625

27-
dialogs = dialogs.Where(x => x.MessageType != MessageTypeName.Notification).ToList();
2826
var content = GetConversationContent(dialogs);
2927
if (string.IsNullOrWhiteSpace(content)) continue;
3028

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStorage.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public async Task<List<RoleDialogModel>> GetDialogs(string conversationId, Conve
7575
CurrentAgentId = meta?.AgentId ?? string.Empty,
7676
MessageId = meta?.MessageId ?? string.Empty,
7777
MessageType = meta?.MessageType ?? string.Empty,
78+
ExcludeFromContext = meta?.ExcludeFromContext ?? false,
7879
MessageLabel = meta?.MessageLabel,
7980
CreatedAt = meta?.CreatedTime ?? default,
8081
SenderId = senderId,
@@ -115,6 +116,7 @@ public async Task<List<RoleDialogModel>> GetDialogs(string conversationId, Conve
115116
AgentId = dialog.CurrentAgentId,
116117
MessageId = dialog.MessageId,
117118
MessageType = dialog.MessageType,
119+
ExcludeFromContext = dialog.ExcludeFromContext,
118120
MessageLabel = dialog.MessageLabel,
119121
ToolCallId = dialog.ToolCallId,
120122
FunctionName = dialog.FunctionName,
@@ -143,6 +145,7 @@ public async Task<List<RoleDialogModel>> GetDialogs(string conversationId, Conve
143145
AgentId = dialog.CurrentAgentId,
144146
MessageId = dialog.MessageId,
145147
MessageType = dialog.MessageType,
148+
ExcludeFromContext = dialog.ExcludeFromContext,
146149
MessageLabel = dialog.MessageLabel,
147150
SenderId = dialog.SenderId,
148151
FunctionName = dialog.FunctionName,

src/Infrastructure/BotSharp.Core/MCP/Managers/McpClientManager.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,17 @@ public McpClientManager(
2828
}
2929

3030
IClientTransport? transport = null;
31-
if (config.SseConfig != null)
31+
if (config.HttpConfig != null)
32+
{
33+
transport = new HttpClientTransport(new HttpClientTransportOptions
34+
{
35+
Name = config.Name,
36+
Endpoint = new Uri(config.HttpConfig.EndPoint),
37+
AdditionalHeaders = config.HttpConfig.AdditionalHeaders,
38+
ConnectionTimeout = config.HttpConfig.ConnectionTimeout
39+
});
40+
}
41+
else if (config.SseConfig != null)
3242
{
3343
transport = new HttpClientTransport(new HttpClientTransportOptions
3444
{

src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetConversationContent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ public async Task<string> GetConversationContent(List<RoleDialogModel> dialogs,
66
{
77
var agentService = _services.GetRequiredService<IAgentService>();
88
var conversation = "";
9-
10-
foreach (var dialog in dialogs.TakeLast(maxDialogCount))
9+
var conversationDialogs = dialogs.Where(x => !x.ExcludeFromContext).TakeLast(maxDialogCount).ToList();
10+
foreach (var dialog in conversationDialogs)
1111
{
1212
var role = dialog.Role;
1313
if (role != AgentRole.User)

src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeAgent.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ public async Task<bool> InvokeAgent(
3838

3939
RoleDialogModel response;
4040
var message = dialogs.Last();
41+
var conversationDialogs = dialogs.Where(x => !x.ExcludeFromContext).ToList();
4142
if (options?.UseStream == true)
4243
{
43-
response = await chatCompletion.GetChatCompletionsStreamingAsync(agent, dialogs);
44+
response = await chatCompletion.GetChatCompletionsStreamingAsync(agent, conversationDialogs);
4445
}
4546
else
4647
{
47-
response = await chatCompletion.GetChatCompletions(agent, dialogs);
48+
response = await chatCompletion.GetChatCompletions(agent, conversationDialogs);
4849
}
4950

5051
if (response.Role == AgentRole.Function && !string.IsNullOrEmpty(response.FunctionName))

src/Plugins/BotSharp.Plugin.Membase/GraphDb/MembaseGraphDb.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Net;
12
using BotSharp.Plugin.Membase.Models.Graph;
23
using Polly;
34
using Polly.Timeout;
@@ -54,7 +55,7 @@ public async Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryEx
5455
}
5556
catch (ApiException ex)
5657
{
57-
_logger.LogError($"Error when executing query in {Provider} graph db:\r\n{ex.Content}\r\n{query}\r\n{argLogs}");
58+
_logger.LogError(ex, $"Error when executing query in {Provider} graph db:\r\n{ex.Content}\r\n{query}\r\n{argLogs}");
5859
throw;
5960
}
6061
catch (Exception ex)
@@ -154,7 +155,7 @@ private AsyncPolicy BuildRetryPolicy()
154155
.Handle<HttpRequestException>()
155156
.Or<TaskCanceledException>()
156157
.Or<TimeoutRejectedException>()
157-
.Or<ApiException>(ex => ex.StatusCode == HttpStatusCode.ServiceUnavailable)
158+
.Or<ApiException>(ex => ex.StatusCode == HttpStatusCode.ServiceUnavailable || ex.StatusCode == HttpStatusCode.InternalServerError)
158159
.WaitAndRetryAsync(
159160
retryCount: RETRY_COUNT,
160161
sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),

0 commit comments

Comments
 (0)