Skip to content

Commit cad9200

Browse files
authored
Merge pull request #853 from iceljc/master
add entry agent id
2 parents 9706c95 + 16d3e92 commit cad9200

File tree

7 files changed

+19
-4
lines changed

7 files changed

+19
-4
lines changed

src/Infrastructure/BotSharp.Abstraction/Loggers/Models/ConversationStateLogModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ public class ConversationStateLogModel
44
{
55
[JsonPropertyName("conversation_id")]
66
public string ConversationId { get; set; }
7+
8+
[JsonPropertyName("agent_id")]
9+
public string AgentId { get; set; }
10+
711
[JsonPropertyName("message_id")]
812
public string MessageId { get; set; }
13+
914
[JsonPropertyName("states")]
1015
public Dictionary<string, string> States { get; set; }
16+
1117
[JsonPropertyName("created_at")]
1218
public DateTime CreateTime { get; set; } = DateTime.UtcNow;
1319
}

src/Plugins/BotSharp.Plugin.ChatHub/Hooks/StreamingLogHook.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ public override async Task OnResponseGenerated(RoleDialogModel message)
188188
if (string.IsNullOrEmpty(conversationId)) return;
189189

190190
var conv = _services.GetRequiredService<IConversationService>();
191-
await SendStateLog(conv.ConversationId, _state.GetStates(), message);
191+
var routingCtx = _services.GetRequiredService<IRoutingContext>();
192+
await SendStateLog(conv.ConversationId, routingCtx.EntryAgentId, _state.GetStates(), message);
192193

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

441-
private async Task SendStateLog(string conversationId, Dictionary<string, string> states, RoleDialogModel message)
442+
private async Task SendStateLog(string conversationId, string agentId, Dictionary<string, string> states, RoleDialogModel message)
442443
{
443-
await _chatHub.Clients.User(_user.Id).SendAsync(STATE_LOG_GENERATED, BuildStateLog(conversationId, states, message));
444+
await _chatHub.Clients.User(_user.Id).SendAsync(STATE_LOG_GENERATED, BuildStateLog(conversationId, agentId, states, message));
444445
}
445446

446447
private async Task SendAgentQueueLog(string conversationId, string log)
@@ -479,11 +480,12 @@ private string BuildContentLog(ContentLogInputModel input)
479480
return json;
480481
}
481482

482-
private string BuildStateLog(string conversationId, Dictionary<string, string> states, RoleDialogModel message)
483+
private string BuildStateLog(string conversationId, string agentId, Dictionary<string, string> states, RoleDialogModel message)
483484
{
484485
var log = new ConversationStateLogModel
485486
{
486487
ConversationId = conversationId,
488+
AgentId = agentId,
487489
MessageId = message.MessageId,
488490
States = states,
489491
CreateTime = DateTime.UtcNow

src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationDialogDocument.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ namespace BotSharp.Plugin.MongoStorage.Collections;
33
public class ConversationDialogDocument : MongoBase
44
{
55
public string ConversationId { get; set; }
6+
public string AgentId { get; set; }
67
public List<DialogMongoElement> Dialogs { get; set; }
78
}

src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateDocument.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace BotSharp.Plugin.MongoStorage.Collections;
33
public class ConversationStateDocument : MongoBase
44
{
55
public string ConversationId { get; set; }
6+
public string AgentId { get; set; }
67
public List<StateMongoElement> States { get; set; } = new List<StateMongoElement>();
78
public List<BreakpointMongoElement> Breakpoints { get; set; } = new List<BreakpointMongoElement>();
89
}

src/Plugins/BotSharp.Plugin.MongoStorage/Collections/ConversationStateLogDocument.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace BotSharp.Plugin.MongoStorage.Collections;
33
public class ConversationStateLogDocument : MongoBase
44
{
55
public string ConversationId { get; set; }
6+
public string AgentId { get; set; }
67
public string MessageId { get; set; }
78
public Dictionary<string, string> States { get; set; }
89
public DateTime CreateTime { get; set; }

src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ public void CreateNewConversation(Conversation conversation)
2929
{
3030
Id = Guid.NewGuid().ToString(),
3131
ConversationId = convDoc.Id,
32+
AgentId = conversation.AgentId,
3233
Dialogs = new List<DialogMongoElement>()
3334
};
3435

3536
var stateDoc = new ConversationStateDocument
3637
{
3738
Id = Guid.NewGuid().ToString(),
3839
ConversationId = convDoc.Id,
40+
AgentId = conversation.AgentId,
3941
States = new List<StateMongoElement>(),
4042
Breakpoints = new List<BreakpointMongoElement>()
4143
};

src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public void SaveConversationStateLog(ConversationStateLogModel log)
113113
var logDoc = new ConversationStateLogDocument
114114
{
115115
ConversationId = log.ConversationId,
116+
AgentId= log.AgentId,
116117
MessageId = log.MessageId,
117118
States = log.States,
118119
CreateTime = log.CreateTime
@@ -129,6 +130,7 @@ public List<ConversationStateLogModel> GetConversationStateLogs(string conversat
129130
.Select(x => new ConversationStateLogModel
130131
{
131132
ConversationId = x.ConversationId,
133+
AgentId = x.AgentId,
132134
MessageId = x.MessageId,
133135
States = x.States,
134136
CreateTime = x.CreateTime

0 commit comments

Comments
 (0)