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
15 changes: 11 additions & 4 deletions src/Infrastructure/BotSharp.Abstraction/Realtime/IRealtimeHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ namespace BotSharp.Abstraction.Realtime;

public interface IRealtimeHook : IHookBase
{
Task OnModelReady(Agent agent, IRealTimeCompletion completer);
string[] OnModelTranscriptPrompt(Agent agent);
Task OnTranscribeCompleted(RoleDialogModel message, TranscriptionData data);
Task<bool> ShouldReconnect(RealtimeHubConnection conn) => Task.FromResult(false);
Task OnModelReady(Agent agent, IRealTimeCompletion completer)
=> Task.CompletedTask;

string[] OnModelTranscriptPrompt(Agent agent)
=> [];

Task OnTranscribeCompleted(RoleDialogModel message, TranscriptionData data)
=> Task.CompletedTask;

Task<bool> ShouldReconnect(RealtimeHubConnection conn, RoleDialogModel message)
=> Task.FromResult(false);
}
24 changes: 11 additions & 13 deletions src/Infrastructure/BotSharp.Core.Realtime/Services/RealtimeHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ await HookEmitter.Emit<IRoutingHook>(_services, async hook => await hook.OnRouti
}

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
{
Expand All @@ -117,19 +128,6 @@ await HookEmitter.Emit<IRoutingHook>(_services, async hook => await hook.OnRouti
}
}
}

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 =>
{
Expand Down
Loading