1+ using BotSharp . Abstraction . Agents ;
12using BotSharp . Abstraction . Agents . Models ;
3+ using BotSharp . Abstraction . Conversations . Models ;
24using BotSharp . Abstraction . Loggers ;
35using BotSharp . Abstraction . Loggers . Models ;
6+ using BotSharp . Abstraction . Messaging . Models . RichContent ;
7+ using BotSharp . Abstraction . Messaging ;
48using BotSharp . Abstraction . Repositories ;
9+ using BotSharp . Core . Agents . Services ;
510using Microsoft . AspNetCore . SignalR ;
11+ using Microsoft . VisualBasic ;
612
713namespace BotSharp . Plugin . ChatHub . Hooks ;
814
@@ -54,9 +60,20 @@ public async Task BeforeGenerating(Agent agent, List<RoleDialogModel> conversati
5460
5561 public override async Task OnFunctionExecuted ( RoleDialogModel message )
5662 {
57-
63+ var agentService = _services . GetRequiredService < IAgentService > ( ) ;
64+ var conversationId = _state . GetConversationId ( ) ;
65+ var agent = await agentService . LoadAgent ( message . CurrentAgentId ) ;
66+ var log = $ "[{ agent ? . Name } ]: { message . FunctionName } ({ message . FunctionArgs } ) => { message . Content } ";
67+ log += $ "\r \n <== MessageId: { message . MessageId } ";
68+ await _chatHub . Clients . User ( _user . Id ) . SendAsync ( "OnConversationContentLogGenerated" , BuildContentLog ( conversationId , agent ? . Name , log , message ) ) ;
5869 }
5970
71+ /// <summary>
72+ /// Used to log prompt
73+ /// </summary>
74+ /// <param name="message"></param>
75+ /// <param name="tokenStats"></param>
76+ /// <returns></returns>
6077 public async Task AfterGenerated ( RoleDialogModel message , TokenStatsModel tokenStats )
6178 {
6279 if ( ! _convSettings . ShowVerboseLog ) return ;
@@ -66,20 +83,33 @@ public async Task AfterGenerated(RoleDialogModel message, TokenStatsModel tokenS
6683 var agent = await agentService . LoadAgent ( message . CurrentAgentId ) ;
6784
6885 await _chatHub . Clients . User ( _user . Id ) . SendAsync ( "OnConversationContentLogGenerated" , BuildContentLog ( conversationId , agent ? . Name , tokenStats . Prompt , message ) ) ;
69-
70- var log = message . Role == AgentRole . Function ?
71- $ "[{ agent ? . Name } ]: { message . FunctionName } ({ message . FunctionArgs } )" :
72- $ "[{ agent ? . Name } ]: { message . Content } ";
73- log += $ "\r \n <== MessageId: { message . MessageId } ";
74- await _chatHub . Clients . User ( _user . Id ) . SendAsync ( "OnConversationContentLogGenerated" , BuildContentLog ( conversationId , agent ? . Name , log , message ) ) ;
7586 }
7687
88+ /// <summary>
89+ /// Used to log final response
90+ /// </summary>
91+ /// <param name="message"></param>
92+ /// <returns></returns>
7793 public override async Task OnResponseGenerated ( RoleDialogModel message )
7894 {
7995 var conv = _services . GetRequiredService < IConversationService > ( ) ;
8096 var state = _services . GetRequiredService < IConversationStateService > ( ) ;
8197
8298 await _chatHub . Clients . User ( _user . Id ) . SendAsync ( "OnConversateStateLogGenerated" , BuildStateLog ( conv . ConversationId , state . GetStates ( ) , message ) ) ;
99+
100+ if ( message . Role == AgentRole . Assistant )
101+ {
102+ var agentService = _services . GetRequiredService < IAgentService > ( ) ;
103+ var agent = await agentService . LoadAgent ( message . CurrentAgentId ) ;
104+ var log = $ "[{ agent ? . Name } ]: { message . Content } ";
105+ if ( message . RichContent != null && message . RichContent . Message . RichType != "text" )
106+ {
107+ var richContent = JsonSerializer . Serialize ( message . RichContent , _serializerOptions ) ;
108+ log += $ "\r \n { richContent } ";
109+ }
110+ log += $ "\r \n <== MessageId: { message . MessageId } ";
111+ await _chatHub . Clients . User ( _user . Id ) . SendAsync ( "OnConversationContentLogGenerated" , BuildContentLog ( conv . ConversationId , agent ? . Name , log , message ) ) ;
112+ }
83113 }
84114
85115 private string BuildContentLog ( string conversationId , string ? name , string content , RoleDialogModel message )
0 commit comments