Skip to content

Commit 6af7a3e

Browse files
authored
Merge pull request #924 from hchen2020/master
Return instruction for realtime response.create.
2 parents b86c266 + 17bb86b commit 6af7a3e

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

src/Infrastructure/BotSharp.Abstraction/MLTasks/IRealTimeCompletion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Task Connect(RealtimeHubConnection conn,
2323
Task Disconnect();
2424

2525
Task<RealtimeSession> CreateSession(Agent agent, List<RoleDialogModel> conversations);
26-
Task UpdateSession(RealtimeHubConnection conn, bool turnDetection = true);
26+
Task<string> UpdateSession(RealtimeHubConnection conn, bool turnDetection = true);
2727
Task InsertConversationItem(RoleDialogModel message);
2828
Task RemoveConversationItem(string itemId);
2929
Task TriggerModelInference(string? instructions = null);

src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ public class RoutingArgs
1212
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
1313
public string? NextActionReason { get; set; }
1414

15-
[JsonPropertyName("reason")]
16-
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
17-
public string? Reason { get; set; }
18-
1915
[JsonPropertyName("conversation_end")]
2016
public bool ConversationEnd { get; set; }
2117

src/Infrastructure/BotSharp.Core.Realtime/Hooks/RealtimeConversationHook.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,29 @@ public async Task OnFunctionExecuted(RoleDialogModel message)
3636
if (message.FunctionName == "route_to_agent")
3737
{
3838
var inst = JsonSerializer.Deserialize<RoutingArgs>(message.FunctionArgs ?? "{}") ?? new();
39-
message.Content = $"Connected to agent of {inst.AgentName}";
39+
message.Content = $"I'm your AI assistant '{inst.AgentName}' to help with: '{inst.NextActionReason}'";
4040
hub.HubConn.CurrentAgentId = routing.Context.GetCurrentAgentId();
4141

42-
await hub.Completer.UpdateSession(hub.HubConn);
42+
var instruction = await hub.Completer.UpdateSession(hub.HubConn);
4343
await hub.Completer.InsertConversationItem(message);
44-
await hub.Completer.TriggerModelInference($"Guide the user through the next steps of the process as this Agent ({inst.AgentName}), following its instructions and operational procedures.");
44+
await hub.Completer.TriggerModelInference($"{instruction}\r\n\r\nAssist user task: {inst.NextActionReason}");
4545
}
4646
else if (message.FunctionName == "util-routing-fallback_to_router")
4747
{
4848
var inst = JsonSerializer.Deserialize<FallbackArgs>(message.FunctionArgs ?? "{}") ?? new();
4949
message.Content = $"Returned to Router due to {inst.Reason}";
5050
hub.HubConn.CurrentAgentId = routing.Context.GetCurrentAgentId();
5151

52-
await hub.Completer.UpdateSession(hub.HubConn);
52+
var instruction = await hub.Completer.UpdateSession(hub.HubConn);
5353
await hub.Completer.InsertConversationItem(message);
54-
await hub.Completer.TriggerModelInference($"Check with user whether to proceed the new request: {inst.Reason}");
54+
await hub.Completer.TriggerModelInference(instruction);
5555
}
5656
else
5757
{
5858
// Update session for changed states
59-
await hub.Completer.UpdateSession(hub.HubConn);
59+
var instruction = await hub.Completer.UpdateSession(hub.HubConn);
6060
await hub.Completer.InsertConversationItem(message);
61-
await hub.Completer.TriggerModelInference("Reply based on the function's output.");
61+
await hub.Completer.TriggerModelInference(instruction);
6262
}
6363
}
6464
}

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public async Task<RealtimeSession> CreateSession(Agent agent, List<RoleDialogMod
285285
return session;
286286
}
287287

288-
public async Task UpdateSession(RealtimeHubConnection conn, bool turnDetection = true)
288+
public async Task<string> UpdateSession(RealtimeHubConnection conn, bool turnDetection = true)
289289
{
290290
var convService = _services.GetRequiredService<IConversationService>();
291291
var conv = await convService.GetConversation(conn.ConversationId);
@@ -347,6 +347,8 @@ await HookEmitter.Emit<IContentGeneratingHook>(_services, async hook =>
347347
});
348348

349349
await SendEventToModel(sessionUpdate);
350+
351+
return instruction;
350352
}
351353

352354
public async Task InsertConversationItem(RoleDialogModel message)
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
** Please call util-twilio-hangup_phone_call if user wants to end the phone call.
1+
{% if channel == 'phone' %}
2+
** Please call util-twilio-hangup_phone_call if user wants to end the phone call.
3+
{% endif %}

0 commit comments

Comments
 (0)