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 @@ -4,10 +4,16 @@ public class ConversationStateLogModel
{
[JsonPropertyName("conversation_id")]
public string ConversationId { get; set; }

[JsonPropertyName("agent_id")]
public string AgentId { get; set; }

[JsonPropertyName("message_id")]
public string MessageId { get; set; }

[JsonPropertyName("states")]
public Dictionary<string, string> States { get; set; }

[JsonPropertyName("created_at")]
public DateTime CreateTime { get; set; } = DateTime.UtcNow;
}
10 changes: 6 additions & 4 deletions src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ public override async Task OnResponseGenerated(RoleDialogModel message)
if (string.IsNullOrEmpty(conversationId)) return;

var conv = _services.GetRequiredService<IConversationService>();
await SendStateLog(conv.ConversationId, _state.GetStates(), message);
var routingCtx = _services.GetRequiredService<IRoutingContext>();
await SendStateLog(conv.ConversationId, routingCtx.EntryAgentId, _state.GetStates(), message);

if (message.Role == AgentRole.Assistant)
{
Expand Down Expand Up @@ -438,9 +439,9 @@ private async Task SendContentLog(ContentLogInputModel input)
await _chatHub.Clients.User(_user.Id).SendAsync(CONTENT_LOG_GENERATED, BuildContentLog(input));
}

private async Task SendStateLog(string conversationId, Dictionary<string, string> states, RoleDialogModel message)
private async Task SendStateLog(string conversationId, string agentId, Dictionary<string, string> states, RoleDialogModel message)
{
await _chatHub.Clients.User(_user.Id).SendAsync(STATE_LOG_GENERATED, BuildStateLog(conversationId, states, message));
await _chatHub.Clients.User(_user.Id).SendAsync(STATE_LOG_GENERATED, BuildStateLog(conversationId, agentId, states, message));
}

private async Task SendAgentQueueLog(string conversationId, string log)
Expand Down Expand Up @@ -479,11 +480,12 @@ private string BuildContentLog(ContentLogInputModel input)
return json;
}

private string BuildStateLog(string conversationId, Dictionary<string, string> states, RoleDialogModel message)
private string BuildStateLog(string conversationId, string agentId, Dictionary<string, string> states, RoleDialogModel message)
{
var log = new ConversationStateLogModel
{
ConversationId = conversationId,
AgentId = agentId,
MessageId = message.MessageId,
States = states,
CreateTime = DateTime.UtcNow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ namespace BotSharp.Plugin.MongoStorage.Collections;
public class ConversationDialogDocument : MongoBase
{
public string ConversationId { get; set; }
public string AgentId { get; set; }
public List<DialogMongoElement> Dialogs { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace BotSharp.Plugin.MongoStorage.Collections;
public class ConversationStateDocument : MongoBase
{
public string ConversationId { get; set; }
public string AgentId { get; set; }
public List<StateMongoElement> States { get; set; } = new List<StateMongoElement>();
public List<BreakpointMongoElement> Breakpoints { get; set; } = new List<BreakpointMongoElement>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace BotSharp.Plugin.MongoStorage.Collections;
public class ConversationStateLogDocument : MongoBase
{
public string ConversationId { get; set; }
public string AgentId { get; set; }
public string MessageId { get; set; }
public Dictionary<string, string> States { get; set; }
public DateTime CreateTime { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ public void CreateNewConversation(Conversation conversation)
{
Id = Guid.NewGuid().ToString(),
ConversationId = convDoc.Id,
AgentId = conversation.AgentId,
Dialogs = new List<DialogMongoElement>()
};

var stateDoc = new ConversationStateDocument
{
Id = Guid.NewGuid().ToString(),
ConversationId = convDoc.Id,
AgentId = conversation.AgentId,
States = new List<StateMongoElement>(),
Breakpoints = new List<BreakpointMongoElement>()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void SaveConversationStateLog(ConversationStateLogModel log)
var logDoc = new ConversationStateLogDocument
{
ConversationId = log.ConversationId,
AgentId= log.AgentId,
MessageId = log.MessageId,
States = log.States,
CreateTime = log.CreateTime
Expand All @@ -129,6 +130,7 @@ public List<ConversationStateLogModel> GetConversationStateLogs(string conversat
.Select(x => new ConversationStateLogModel
{
ConversationId = x.ConversationId,
AgentId = x.AgentId,
MessageId = x.MessageId,
States = x.States,
CreateTime = x.CreateTime
Expand Down