Skip to content

Commit 82affd8

Browse files
authored
Merge pull request #1067 from yileicn/master
hotfix agent instruction cache question
2 parents 53bf0fe + 57f25f3 commit 82affd8

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public async Task<Agent> GetAgent(string id)
7070
}
7171

7272
profile.Plugin = GetPlugin(profile.Id);
73+
74+
//add default instruction to ChannelInstructions
75+
var defaultInstruction = new ChannelInstruction() { Channel = string.Empty, Instruction = profile?.Instruction };
76+
profile.ChannelInstructions.Insert(0, defaultInstruction);
77+
7378
return profile;
7479
}
7580

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,10 @@ private void OverrideInstructionByChannel(Agent agent)
7171

7272
var state = _services.GetRequiredService<IConversationStateService>();
7373
var channel = state.GetState("channel");
74-
75-
if (string.IsNullOrWhiteSpace(channel))
76-
{
77-
return;
78-
}
79-
74+
8075
var found = instructions.FirstOrDefault(x => x.Channel.IsEqualTo(channel));
81-
agent.Instruction = !string.IsNullOrWhiteSpace(found?.Instruction) ? found.Instruction : agent.Instruction;
76+
var defaultInstruction = instructions.FirstOrDefault(x => x.Channel == string.Empty);
77+
agent.Instruction = !string.IsNullOrWhiteSpace(found?.Instruction) ? found.Instruction : defaultInstruction?.Instruction;
8278
}
8379

8480
private void PopulateState(Dictionary<string, object> dict)

0 commit comments

Comments
 (0)