Skip to content

Commit da9becb

Browse files
authored
Merge pull request #380 from hchen2020/master
Save to Storage as well
2 parents f751d75 + 8f9e2ad commit da9becb

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallingResponse.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ public class FunctionCallingResponse
1818

1919
[JsonPropertyName("args")]
2020
public JsonDocument? Args { get; set; }
21+
22+
public override string ToString()
23+
{
24+
return $"{FunctionName}({JsonSerializer.Serialize(Args)}) => {Content}";
25+
}
2126
}

src/Infrastructure/BotSharp.Abstraction/Infrastructures/Enums/StateConst.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ public class StateConst
44
{
55
public const string EXPECTED_ACTION_AGENT = "expected_next_action_agent";
66
public const string EXPECTED_GOAL_AGENT = "expected_user_goal_agent";
7+
public const string NEXT_ACTION_AGENT = "next_action_agent";
8+
public const string USER_GOAL_AGENT = "user_goal_agent";
79
}

src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class HumanInterventionNeededHandler : RoutingHandlerBase, IRoutingHandle
1212
{
1313
new ParameterPropertyDef("reason", "why need customer service"),
1414
new ParameterPropertyDef("summary", "the whole conversation summary with important information"),
15-
new ParameterPropertyDef("response", "confirm with user that whether to connect with customer service")
15+
new ParameterPropertyDef("response", "asking user whether to connect with customer service representative")
1616
};
1717

1818
public HumanInterventionNeededHandler(IServiceProvider services, ILogger<HumanInterventionNeededHandler> logger, RoutingSettings settings)

src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ public class RouteToAgentRoutingHandler : RoutingHandlerBase, IRoutingHandler
66
{
77
public string Name => "route_to_agent";
88

9-
public string Description => "Route request to appropriate agent.";
9+
public string Description => "Route request to appropriate virtual agent.";
1010

1111
public List<ParameterPropertyDef> Parameters => new List<ParameterPropertyDef>
1212
{
13-
new ParameterPropertyDef("next_action_reason", "the reason why route to this agent")
13+
new ParameterPropertyDef("next_action_reason", "the reason why route to this virtual agent")
1414
{
1515
Required = true
1616
},
1717
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")
1818
{
1919
Required = true
2020
},
21-
new ParameterPropertyDef("user_goal_description", "user original goal")
21+
new ParameterPropertyDef("user_goal_description", "user goal based on user initial task.")
2222
{
2323
Required = true
2424
},
25-
new ParameterPropertyDef("user_goal_agent", "user original goal")
25+
new ParameterPropertyDef("user_goal_agent", "agent who can acheive user initial task, must align with user_goal_description ")
2626
{
2727
Required = true
2828
},

src/Infrastructure/BotSharp.Core/Routing/RoutingService.InvokeFunction.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace BotSharp.Core.Routing;
44

55
public partial class RoutingService
66
{
7+
private List<FunctionCallingResponse> _functionCallStack = new List<FunctionCallingResponse>();
78
public async Task<bool> InvokeFunction(string name, RoleDialogModel message)
89
{
910
var function = _services.GetServices<IFunctionCallback>().FirstOrDefault(x => x.Name == name);
@@ -35,6 +36,13 @@ public async Task<bool> InvokeFunction(string name, RoleDialogModel message)
3536
try
3637
{
3738
result = await function.Execute(message);
39+
_functionCallStack.Add(new FunctionCallingResponse
40+
{
41+
Role = AgentRole.Function,
42+
FunctionName = message.FunctionName,
43+
Args = JsonDocument.Parse(message.FunctionArgs ?? "{}"),
44+
Content = message.Content
45+
});
3846
}
3947
catch (JsonException ex)
4048
{
@@ -69,11 +77,11 @@ public async Task<bool> InvokeFunction(string name, RoleDialogModel message)
6977
}
7078

7179
// Save to Storage as well
72-
/*if (!message.StopCompletion && message.FunctionName != "route_to_agent")
80+
if (!message.StopCompletion && message.FunctionName != "route_to_agent")
7381
{
7482
var storage = _services.GetRequiredService<IConversationStorage>();
7583
storage.Append(Context.ConversationId, message);
76-
}*/
84+
}
7785

7886
return result;
7987
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
What is the next step based on the CONVERSATION?
22
Route to the last handling agent in priority.
3-
43
{% if expected_next_action_agent != empty -%}
54
Expected next action agent is {{ expected_next_action_agent }}.
6-
{%- endif -%}
7-
{%- if expected_user_goal_agent != empty -%}
5+
{%- else -%}
6+
Next action agent is inferred based on user lastest response.
7+
{%- endif %}
8+
{% if expected_user_goal_agent != empty -%}
89
Expected user goal agent is {{ expected_user_goal_agent }}.
10+
{%- else -%}
11+
User goal agent is inferred based on user initial request.
912
{%- endif %}
10-
1113
If user wants to speak to customer service, use function human_intervention_needed.
1214
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.

0 commit comments

Comments
 (0)