Merge pull request #113 from hchen2020/master
Allow agent redirect directly.
This commit is contained in:
commit
c798ed2c9e
|
|
@ -13,6 +13,9 @@ public class RoutingTable
|
|||
[JsonPropertyName("required")]
|
||||
public List<string> RequiredFields { get; set; }
|
||||
|
||||
[JsonPropertyName("redirect_to")]
|
||||
public string RedirectTo { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return AgentName;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,12 @@ public class RouteToAgentFn : IFunctionCallback
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!HasMissingRequiredField(message, out var agentId))
|
||||
var missingfield = HasMissingRequiredField(message, out var agentId);
|
||||
if (missingfield && message.CurrentAgentId != agentId)
|
||||
{
|
||||
message.CurrentAgentId = agentId;
|
||||
}
|
||||
else
|
||||
{
|
||||
message.CurrentAgentId = agentId;
|
||||
message.ExecutionResult = $"Routed to {args.AgentName}";
|
||||
|
|
@ -47,21 +52,21 @@ public class RouteToAgentFn : IFunctionCallback
|
|||
var args = JsonSerializer.Deserialize<RoutingArgs>(message.FunctionArgs);
|
||||
|
||||
var routes = GetRoutingTable();
|
||||
var agent = routes.FirstOrDefault(x => x.AgentName.ToLower() == args.AgentName.ToLower());
|
||||
var routingRule = routes.FirstOrDefault(x => x.AgentName.ToLower() == args.AgentName.ToLower());
|
||||
|
||||
if (agent == null)
|
||||
if (routingRule == null)
|
||||
{
|
||||
agentId = message.CurrentAgentId;
|
||||
message.ExecutionResult = $"Can't find agent {args.AgentName}";
|
||||
return true;
|
||||
}
|
||||
|
||||
agentId = agent.AgentId;
|
||||
agentId = routingRule.AgentId;
|
||||
|
||||
// Check required fields
|
||||
var jo = JsonSerializer.Deserialize<object>(message.FunctionArgs);
|
||||
bool hasMissingField = false;
|
||||
foreach (var field in agent.RequiredFields)
|
||||
foreach (var field in routingRule.RequiredFields)
|
||||
{
|
||||
if (jo is JsonElement root)
|
||||
{
|
||||
|
|
@ -71,9 +76,21 @@ public class RouteToAgentFn : IFunctionCallback
|
|||
hasMissingField = true;
|
||||
break;
|
||||
}
|
||||
else if (root.EnumerateObject().Any(x => x.Name == field) &&
|
||||
string.IsNullOrEmpty(root.EnumerateObject().FirstOrDefault(x => x.Name == field).Value.ToString()))
|
||||
{
|
||||
message.ExecutionResult = $"missing {field}.";
|
||||
hasMissingField = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasMissingField && !string.IsNullOrEmpty(routingRule.RedirectTo))
|
||||
{
|
||||
agentId = routingRule.RedirectTo;
|
||||
}
|
||||
|
||||
return hasMissingField;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue