Skip to content

Save to Storage as well #380

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 31, 2024
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 @@ -18,4 +18,9 @@ public class FunctionCallingResponse

[JsonPropertyName("args")]
public JsonDocument? Args { get; set; }

public override string ToString()
{
return $"{FunctionName}({JsonSerializer.Serialize(Args)}) => {Content}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public class StateConst
{
public const string EXPECTED_ACTION_AGENT = "expected_next_action_agent";
public const string EXPECTED_GOAL_AGENT = "expected_user_goal_agent";
public const string NEXT_ACTION_AGENT = "next_action_agent";
public const string USER_GOAL_AGENT = "user_goal_agent";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class HumanInterventionNeededHandler : RoutingHandlerBase, IRoutingHandle
{
new ParameterPropertyDef("reason", "why need customer service"),
new ParameterPropertyDef("summary", "the whole conversation summary with important information"),
new ParameterPropertyDef("response", "confirm with user that whether to connect with customer service")
new ParameterPropertyDef("response", "asking user whether to connect with customer service representative")
};

public HumanInterventionNeededHandler(IServiceProvider services, ILogger<HumanInterventionNeededHandler> logger, RoutingSettings settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ public class RouteToAgentRoutingHandler : RoutingHandlerBase, IRoutingHandler
{
public string Name => "route_to_agent";

public string Description => "Route request to appropriate agent.";
public string Description => "Route request to appropriate virtual agent.";

public List<ParameterPropertyDef> Parameters => new List<ParameterPropertyDef>
{
new ParameterPropertyDef("next_action_reason", "the reason why route to this agent")
new ParameterPropertyDef("next_action_reason", "the reason why route to this virtual agent")
{
Required = true
},
new ParameterPropertyDef("next_action_agent", "agent for next action based on user latest response, if user is replying last agent's question, you must route to this agent")
{
Required = true
},
new ParameterPropertyDef("user_goal_description", "user original goal")
new ParameterPropertyDef("user_goal_description", "user goal based on user initial task.")
{
Required = true
},
new ParameterPropertyDef("user_goal_agent", "user original goal")
new ParameterPropertyDef("user_goal_agent", "agent who can acheive user initial task, must align with user_goal_description ")
{
Required = true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace BotSharp.Core.Routing;

public partial class RoutingService
{
private List<FunctionCallingResponse> _functionCallStack = new List<FunctionCallingResponse>();
public async Task<bool> InvokeFunction(string name, RoleDialogModel message)
{
var function = _services.GetServices<IFunctionCallback>().FirstOrDefault(x => x.Name == name);
Expand Down Expand Up @@ -35,6 +36,13 @@ public async Task<bool> InvokeFunction(string name, RoleDialogModel message)
try
{
result = await function.Execute(message);
_functionCallStack.Add(new FunctionCallingResponse
{
Role = AgentRole.Function,
FunctionName = message.FunctionName,
Args = JsonDocument.Parse(message.FunctionArgs ?? "{}"),
Content = message.Content
});
}
catch (JsonException ex)
{
Expand Down Expand Up @@ -69,11 +77,11 @@ public async Task<bool> InvokeFunction(string name, RoleDialogModel message)
}

// Save to Storage as well
/*if (!message.StopCompletion && message.FunctionName != "route_to_agent")
if (!message.StopCompletion && message.FunctionName != "route_to_agent")
{
var storage = _services.GetRequiredService<IConversationStorage>();
storage.Append(Context.ConversationId, message);
}*/
}

return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
What is the next step based on the CONVERSATION?
Route to the last handling agent in priority.

{% if expected_next_action_agent != empty -%}
Expected next action agent is {{ expected_next_action_agent }}.
{%- endif -%}
{%- if expected_user_goal_agent != empty -%}
{%- else -%}
Next action agent is inferred based on user lastest response.
{%- endif %}
{% if expected_user_goal_agent != empty -%}
Expected user goal agent is {{ expected_user_goal_agent }}.
{%- else -%}
User goal agent is inferred based on user initial request.
{%- endif %}

If user wants to speak to customer service, use function human_intervention_needed.
If user wants to or is processing with a specific task that can be handled by agents, respond in appropriate output format defined to let proper agent to handle the task.