Skip to content

Commit 76b1e6d

Browse files
authored
Merge pull request #112 from hchen2020/master
Fix dead loop when depth exceeds the limit.
2 parents bccf362 + 9fd7457 commit 76b1e6d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,21 @@ private async Task<bool> GetChatCompletionsAsyncRecursively(IChatCompletion chat
2121
currentRecursiveDepth++;
2222
if (currentRecursiveDepth > maxRecursiveDepth)
2323
{
24-
_logger.LogError($"Exceeded max recursive depth.");
25-
await HandleAssistantMessage(new RoleDialogModel(AgentRole.Assistant, "I'm sorry, can you see it again?")
24+
_logger.LogWarning($"Exceeded max recursive depth.");
25+
26+
var latestResponse = wholeDialogs.Last();
27+
var text = latestResponse.Content;
28+
if (latestResponse.Role == AgentRole.Function)
29+
{
30+
text = latestResponse.Content.Split("=>").Last();
31+
}
32+
33+
await HandleAssistantMessage(new RoleDialogModel(AgentRole.Assistant, text)
2634
{
2735
CurrentAgentId = agent.Id,
2836
Channel = wholeDialogs.Last().Channel
2937
}, onMessageReceived);
38+
3039
return false;
3140
}
3241

0 commit comments

Comments
 (0)