Skip to content
Merged
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 @@ -3,11 +3,6 @@ namespace BotSharp.Abstraction.Conversations.Enums;
public static class MessageTypeName
{
public const string Plain = "plain";
/// <summary>
/// Persisted for record/audit but excluded from default LLM dialog history.
/// </summary>
public const string RecordOnly = "record_only";
public const string Notification = "notification";
public const string FunctionCall = "function";
public const string Audio = "audio";
public const string Error = "error";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public class DialogMetaData
[JsonPropertyName("sender_id")]
public string? SenderId { get; set; }

/// <summary>
/// When true, message is persisted but omitted from default LLM dialog history and routing conversation text.
/// </summary>
[JsonPropertyName("exclude_from_context")]
public bool ExcludeFromContext { get; set; }

[JsonPropertyName("create_at")]
public DateTime CreatedTime { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class RoleDialogModel : ITrackableMessage
/// </summary>
public string MessageType { get; set; } = MessageTypeName.Plain;

/// <summary>
/// When true, message is stored but omitted from default LLM history and routing <c>[CONVERSATION]</c> (orthogonal to <see cref="MessageType"/>).
/// </summary>
public bool ExcludeFromContext { get; set; }

/// <summary>
/// The message label
/// </summary>
Expand Down Expand Up @@ -191,6 +196,7 @@ public static RoleDialogModel From(RoleDialogModel source,
CurrentAgentId = source.CurrentAgentId,
MessageId = source.MessageId,
MessageType = source.MessageType,
ExcludeFromContext = source.ExcludeFromContext,
MessageLabel = source.MessageLabel,
ToolCallId = source.ToolCallId,
FunctionName = source.FunctionName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using BotSharp.Abstraction.Conversations.Enums;
using BotSharp.Abstraction.MLTasks;
using BotSharp.Abstraction.Models;
using BotSharp.Abstraction.Settings;
Expand All @@ -24,7 +23,6 @@ public async Task<string> GetConversationSummary(ConversationSummaryModel model)

if (dialogs.IsNullOrEmpty()) continue;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ public async Task<List<RoleDialogModel>> GetDialogHistory(int lastCount = 100, b
}
else
{
var defaultMessageTypes = new List<string> { MessageTypeName.Plain, MessageTypeName.RecordOnly };
dialogs = dialogs.Where(x => string.IsNullOrEmpty(x.MessageType) || defaultMessageTypes.Contains(x.MessageType)).ToList();
dialogs = dialogs.Where(x => string.IsNullOrEmpty(x.MessageType) || x.MessageType.IsEqualTo(MessageTypeName.Plain)).ToList();
}

if (fromBreakpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public async Task<List<RoleDialogModel>> GetDialogs(string conversationId, Conve
CurrentAgentId = meta?.AgentId ?? string.Empty,
MessageId = meta?.MessageId ?? string.Empty,
MessageType = meta?.MessageType ?? string.Empty,
ExcludeFromContext = meta?.ExcludeFromContext ?? false,
MessageLabel = meta?.MessageLabel,
CreatedAt = meta?.CreatedTime ?? default,
SenderId = senderId,
Expand Down Expand Up @@ -115,6 +116,7 @@ public async Task<List<RoleDialogModel>> GetDialogs(string conversationId, Conve
AgentId = dialog.CurrentAgentId,
MessageId = dialog.MessageId,
MessageType = dialog.MessageType,
ExcludeFromContext = dialog.ExcludeFromContext,
MessageLabel = dialog.MessageLabel,
ToolCallId = dialog.ToolCallId,
FunctionName = dialog.FunctionName,
Expand Down Expand Up @@ -143,6 +145,7 @@ public async Task<List<RoleDialogModel>> GetDialogs(string conversationId, Conve
AgentId = dialog.CurrentAgentId,
MessageId = dialog.MessageId,
MessageType = dialog.MessageType,
ExcludeFromContext = dialog.ExcludeFromContext,
MessageLabel = dialog.MessageLabel,
SenderId = dialog.SenderId,
FunctionName = dialog.FunctionName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using BotSharp.Abstraction.Conversations.Enums;

namespace BotSharp.Core.Routing;

public partial class RoutingService
Expand All @@ -8,7 +6,7 @@ public async Task<string> GetConversationContent(List<RoleDialogModel> dialogs,
{
var agentService = _services.GetRequiredService<IAgentService>();
var conversation = "";
var conversationDialogs = dialogs.Where(x => x.MessageType != MessageTypeName.RecordOnly).TakeLast(maxDialogCount).ToList();
var conversationDialogs = dialogs.Where(x => !x.ExcludeFromContext).TakeLast(maxDialogCount).ToList();
foreach (var dialog in conversationDialogs)
{
var role = dialog.Role;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<bool> InvokeAgent(

RoleDialogModel response;
var message = dialogs.Last();
var conversationDialogs = dialogs.Where(x => x.MessageType != MessageTypeName.RecordOnly).ToList();
var conversationDialogs = dialogs.Where(x => !x.ExcludeFromContext).ToList();
if (options?.UseStream == true)
{
response = await chatCompletion.GetChatCompletionsStreamingAsync(agent, conversationDialogs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class DialogMetaDataMongoElement
public string? FunctionArgs { get; set; }
public Dictionary<string, string?>? MetaData { get; set; }
public string? SenderId { get; set; }
public bool ExcludeFromContext { get; set; }
public DateTime CreateTime { get; set; }

public static DialogMetaData ToDomainElement(DialogMetaDataMongoElement meta)
Expand All @@ -68,6 +69,7 @@ public static DialogMetaData ToDomainElement(DialogMetaDataMongoElement meta)
FunctionArgs = meta.FunctionArgs,
MetaData = meta.MetaData,
SenderId = meta.SenderId,
ExcludeFromContext = meta.ExcludeFromContext,
CreatedTime = meta.CreateTime
};
}
Expand All @@ -86,6 +88,7 @@ public static DialogMetaDataMongoElement ToMongoElement(DialogMetaData meta)
FunctionArgs = meta.FunctionArgs,
MetaData = meta.MetaData,
SenderId = meta.SenderId,
ExcludeFromContext = meta.ExcludeFromContext,
CreateTime = meta.CreatedTime
};
}
Expand Down
Loading