Skip to content

Return instruction for realtime response.create. #924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Task Connect(RealtimeHubConnection conn,
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ public async Task OnFunctionExecuted(RoleDialogModel message)
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")
{
var inst = JsonSerializer.Deserialize<FallbackArgs>(message.FunctionArgs ?? "{}") ?? new();
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public async Task<RealtimeSession> CreateSession(Agent agent, List<RoleDialogMod
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);
Expand Down Expand Up @@ -347,6 +347,8 @@ await HookEmitter.Emit<IContentGeneratingHook>(_services, async hook =>
});

await SendEventToModel(sessionUpdate);

return instruction;
}

public async Task InsertConversationItem(RoleDialogModel message)
Expand Down
Original file line number Diff line number Diff line change
@@ -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