Merge branch 'master' of https://github.com/SciSharp/BotSharp into features/refine-vector-store

This commit is contained in:
Jicheng Lu 2025-08-07 23:50:58 -05:00
commit 5bb5d69894
4 changed files with 27 additions and 17 deletions

View file

@ -6,8 +6,15 @@ namespace BotSharp.Abstraction.Realtime;
public interface IRealtimeHook : IHookBase public interface IRealtimeHook : IHookBase
{ {
Task OnModelReady(Agent agent, IRealTimeCompletion completer); Task OnModelReady(Agent agent, IRealTimeCompletion completer)
string[] OnModelTranscriptPrompt(Agent agent); => Task.CompletedTask;
Task OnTranscribeCompleted(RoleDialogModel message, TranscriptionData data);
Task<bool> ShouldReconnect(RealtimeHubConnection conn) => Task.FromResult(false); string[] OnModelTranscriptPrompt(Agent agent)
=> [];
Task OnTranscribeCompleted(RoleDialogModel message, TranscriptionData data)
=> Task.CompletedTask;
Task<bool> ShouldReconnect(RealtimeHubConnection conn, RoleDialogModel message)
=> Task.FromResult(false);
} }

View file

@ -16,6 +16,7 @@ public class ConversationFilter
public string? ChannelId { get; set; } public string? ChannelId { get; set; }
public string? UserId { get; set; } public string? UserId { get; set; }
public DateTime? StartTime { get; set; } public DateTime? StartTime { get; set; }
public DateTime? EndTime { get; set; }
/// <summary> /// <summary>
/// Agent task id /// Agent task id

View file

@ -100,6 +100,17 @@ public class RealtimeHub : IRealtimeHub
} }
await routing.InvokeFunction(message.FunctionName, message, options: new() { From = InvokeSource.Llm }); await routing.InvokeFunction(message.FunctionName, message, options: new() { From = InvokeSource.Llm });
var hooks = _services.GetHooks<IRealtimeHook>(_conn.CurrentAgentId);
foreach (var hook in hooks)
{
if (await hook.ShouldReconnect(_conn, message))
{
await _completer.Reconnect(_conn);
_logger.LogWarning("Reconnecting to model due to function call: {FunctionName}", message.FunctionName);
break;
}
}
} }
else else
{ {
@ -117,19 +128,6 @@ public class RealtimeHub : IRealtimeHub
} }
} }
} }
var isReconnect = false;
var realtimeHooks = _services.GetHooks<IRealtimeHook>(_conn.CurrentAgentId);
foreach (var hook in realtimeHooks)
{
isReconnect = await hook.ShouldReconnect(_conn);
if (isReconnect) break;
}
if (isReconnect)
{
await _completer.Reconnect(_conn);
}
}, },
onConversationItemCreated: async response => onConversationItemCreated: async response =>
{ {

View file

@ -393,6 +393,10 @@ public partial class MongoRepository
{ {
convFilters.Add(convBuilder.Gte(x => x.CreatedTime, filter.StartTime.Value)); convFilters.Add(convBuilder.Gte(x => x.CreatedTime, filter.StartTime.Value));
} }
if (filter?.EndTime != null)
{
convFilters.Add(convBuilder.Lte(x => x.CreatedTime, filter.EndTime.Value));
}
if (filter?.Tags != null && filter.Tags.Any()) if (filter?.Tags != null && filter.Tags.Any())
{ {
convFilters.Add(convBuilder.AnyIn(x => x.Tags, filter.Tags)); convFilters.Add(convBuilder.AnyIn(x => x.Tags, filter.Tags));