Skip to content

Commit ad96e08

Browse files
authored
Merge pull request #1312 from SciSharp/lazy-mode-fixing
fix lazy mode
2 parents ee03d8a + 684e0c8 commit ad96e08

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,24 @@ public async Task<bool> SendMessage(string agentId,
8080

8181
if (agent.Type == AgentType.Routing)
8282
{
83+
await routing.Context.Push(agent.Id, reason: "request started", updateLazyRouting: false);
84+
8385
// Check the routing mode
8486
var states = _services.GetRequiredService<IConversationStateService>();
8587
var routingMode = states.GetState(StateConst.ROUTING_MODE, agent.Mode ?? RoutingMode.Eager);
86-
await routing.Context.Push(agent.Id, reason: "request started", updateLazyRouting: false);
88+
var lazyRoutingAgentId = states.GetState(StateConst.LAZY_ROUTING_AGENT_ID);
8789

88-
if (routingMode == RoutingMode.Lazy)
90+
if (routingMode == RoutingMode.Lazy && !string.IsNullOrEmpty(lazyRoutingAgentId))
8991
{
90-
message.CurrentAgentId = states.GetState(StateConst.LAZY_ROUTING_AGENT_ID, message.CurrentAgentId);
92+
message.CurrentAgentId = lazyRoutingAgentId;
93+
agent = await agentService.LoadAgent(message.CurrentAgentId);
9194
await routing.Context.Push(message.CurrentAgentId, reason: "lazy routing", updateLazyRouting: false);
95+
response = await routing.InstructDirect(agent, message, dialogs);
96+
}
97+
else
98+
{
99+
response = await routing.InstructLoop(agent, message, dialogs);
92100
}
93-
94-
response = await routing.InstructLoop(agent, message, dialogs);
95101
}
96102
else
97103
{

src/Infrastructure/BotSharp.Core/Routing/RoutingContext.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,10 @@ private void UpdateLazyRoutingAgent(bool updateLazyRouting)
299299

300300
// Set next handling agent for lazy routing mode
301301
var states = _services.GetRequiredService<IConversationStateService>();
302-
var routingMode = states.GetState(StateConst.ROUTING_MODE, RoutingMode.Eager);
303-
if (routingMode == RoutingMode.Lazy)
302+
var agentId = GetCurrentAgentId();
303+
if (agentId != BuiltInAgentId.Fallback)
304304
{
305-
var agentId = GetCurrentAgentId();
306-
if (agentId != BuiltInAgentId.Fallback)
307-
{
308-
states.SetState(StateConst.LAZY_ROUTING_AGENT_ID, agentId);
309-
}
305+
states.SetState(StateConst.LAZY_ROUTING_AGENT_ID, agentId);
310306
}
311307
}
312308
}

0 commit comments

Comments
 (0)