Return instruction for realtime response.create.
This commit is contained in:
parent
b86c26665a
commit
17bb86b311
|
|
@ -23,7 +23,7 @@ public interface IRealTimeCompletion
|
|||
Task Disconnect();
|
||||
|
||||
Task<RealtimeSession> CreateSession(Agent agent, List<RoleDialogModel> conversations);
|
||||
Task UpdateSession(RealtimeHubConnection conn, bool turnDetection = true);
|
||||
Task<string> UpdateSession(RealtimeHubConnection conn, bool turnDetection = true);
|
||||
Task InsertConversationItem(RoleDialogModel message);
|
||||
Task RemoveConversationItem(string itemId);
|
||||
Task TriggerModelInference(string? instructions = null);
|
||||
|
|
|
|||
|
|
@ -12,10 +12,6 @@ public class RoutingArgs
|
|||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? NextActionReason { get; set; }
|
||||
|
||||
[JsonPropertyName("reason")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? Reason { get; set; }
|
||||
|
||||
[JsonPropertyName("conversation_end")]
|
||||
public bool ConversationEnd { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -36,12 +36,12 @@ public class RealtimeConversationHook : ConversationHookBase, IConversationHook
|
|||
if (message.FunctionName == "route_to_agent")
|
||||
{
|
||||
var inst = JsonSerializer.Deserialize<RoutingArgs>(message.FunctionArgs ?? "{}") ?? new();
|
||||
message.Content = $"Connected to agent of {inst.AgentName}";
|
||||
message.Content = $"I'm your AI assistant '{inst.AgentName}' to help with: '{inst.NextActionReason}'";
|
||||
hub.HubConn.CurrentAgentId = routing.Context.GetCurrentAgentId();
|
||||
|
||||
await hub.Completer.UpdateSession(hub.HubConn);
|
||||
var instruction = await hub.Completer.UpdateSession(hub.HubConn);
|
||||
await hub.Completer.InsertConversationItem(message);
|
||||
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.");
|
||||
await hub.Completer.TriggerModelInference($"{instruction}\r\n\r\nAssist user task: {inst.NextActionReason}");
|
||||
}
|
||||
else if (message.FunctionName == "util-routing-fallback_to_router")
|
||||
{
|
||||
|
|
@ -49,16 +49,16 @@ public class RealtimeConversationHook : ConversationHookBase, IConversationHook
|
|||
message.Content = $"Returned to Router due to {inst.Reason}";
|
||||
hub.HubConn.CurrentAgentId = routing.Context.GetCurrentAgentId();
|
||||
|
||||
await hub.Completer.UpdateSession(hub.HubConn);
|
||||
var instruction = await hub.Completer.UpdateSession(hub.HubConn);
|
||||
await hub.Completer.InsertConversationItem(message);
|
||||
await hub.Completer.TriggerModelInference($"Check with user whether to proceed the new request: {inst.Reason}");
|
||||
await hub.Completer.TriggerModelInference(instruction);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update session for changed states
|
||||
await hub.Completer.UpdateSession(hub.HubConn);
|
||||
var instruction = await hub.Completer.UpdateSession(hub.HubConn);
|
||||
await hub.Completer.InsertConversationItem(message);
|
||||
await hub.Completer.TriggerModelInference("Reply based on the function's output.");
|
||||
await hub.Completer.TriggerModelInference(instruction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -285,7 +285,7 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
return session;
|
||||
}
|
||||
|
||||
public async Task UpdateSession(RealtimeHubConnection conn, bool turnDetection = true)
|
||||
public async Task<string> UpdateSession(RealtimeHubConnection conn, bool turnDetection = true)
|
||||
{
|
||||
var convService = _services.GetRequiredService<IConversationService>();
|
||||
var conv = await convService.GetConversation(conn.ConversationId);
|
||||
|
|
@ -347,6 +347,8 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
|||
});
|
||||
|
||||
await SendEventToModel(sessionUpdate);
|
||||
|
||||
return instruction;
|
||||
}
|
||||
|
||||
public async Task InsertConversationItem(RoleDialogModel message)
|
||||
|
|
|
|||
|
|
@ -1 +1,3 @@
|
|||
** Please call util-twilio-hangup_phone_call if user wants to end the phone call.
|
||||
{% if channel == 'phone' %}
|
||||
** Please call util-twilio-hangup_phone_call if user wants to end the phone call.
|
||||
{% endif %}
|
||||
Loading…
Reference in a new issue