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,6 +3,10 @@ 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";
Comment on lines +6 to +9
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Recordonly leaks to llm 🐞 Bug ⛨ Security

MessageTypeName.RecordOnly is documented as “excluded from default LLM dialog history”, but
ConversationService.GetConversationSummary and EvaluatingService still build LLM inputs from
_storage.GetDialogs without filtering RecordOnly. This can send record/audit-only content to LLM
providers through summarization/evaluation flows.
Agent Prompt
### Issue description
`RecordOnly` dialogs are intended to be persisted for audit/record, but excluded from **default** LLM dialog history. Some LLM-facing flows (conversation summarization + evaluation) currently include dialogs fetched directly from storage without filtering out `MessageTypeName.RecordOnly`, so audit-only content can be sent to LLM providers.

### Issue Context
- `MessageTypeName.RecordOnly`’s XML doc sets an explicit contract.
- `ConversationService.GetConversationSummary` builds a text prompt from stored dialogs and sends it via `GetChatCompletions`.
- `EvaluatingService` converts stored dialogs into `ref_conversation` strings passed into `instructService.Instruct`.

### Fix Focus Areas
- src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs[23-29]
- src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.Summary.cs[101-119]
- src/Infrastructure/BotSharp.Core/Evaluations/Services/EvaluatingService.Evaluate.cs[19-28]
- src/Infrastructure/BotSharp.Core/Evaluations/Services/EvaluatingService.Evaluate.cs[144-159]

### Suggested fix
Apply a consistent “LLM history” filter (at least excluding `RecordOnly`, and ideally using the same comparer conventions as elsewhere) before building prompt content in these flows. Consider centralizing the filter into a shared helper to avoid future drift.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

public const string Notification = "notification";
public const string FunctionCall = "function";
public const string Audio = "audio";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using BotSharp.Abstraction.Conversations.Enums;

namespace BotSharp.Core.Routing;

public partial class RoutingService
Expand All @@ -6,8 +8,8 @@ public async Task<string> GetConversationContent(List<RoleDialogModel> dialogs,
{
var agentService = _services.GetRequiredService<IAgentService>();
var conversation = "";

foreach (var dialog in dialogs.TakeLast(maxDialogCount))
var conversationDialogs = dialogs.Where(x => x.MessageType != MessageTypeName.RecordOnly).TakeLast(maxDialogCount).ToList();
foreach (var dialog in conversationDialogs)
{
var role = dialog.Role;
if (role != AgentRole.User)
Expand Down
Loading