diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs index d9baafb73..576002f2f 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs @@ -71,13 +71,25 @@ public async Task GetAgent(string id) profile.Plugin = GetPlugin(profile.Id); - //add default instruction to ChannelInstructions - var defaultInstruction = new ChannelInstruction() { Channel = string.Empty, Instruction = profile?.Instruction }; - profile.ChannelInstructions.Insert(0, defaultInstruction); + AddDefaultInstruction(profile, profile.Instruction); return profile; } + /// + /// Add default instruction to ChannelInstructions + /// + private void AddDefaultInstruction(Agent agent, string instruction) + { + //check if instruction is empty + if (string.IsNullOrWhiteSpace(instruction)) return; + //check if instruction is already set + if (agent.ChannelInstructions.Exists(p => p.Channel == string.Empty)) return; + //Add default instruction to ChannelInstructions + var defaultInstruction = new ChannelInstruction() { Channel = string.Empty, Instruction = instruction }; + agent.ChannelInstructions.Insert(0, defaultInstruction); + } + public async Task InheritAgent(Agent agent) { if (string.IsNullOrWhiteSpace(agent?.InheritAgentId)) return; @@ -98,6 +110,7 @@ public async Task InheritAgent(Agent agent) if (string.IsNullOrWhiteSpace(agent.Instruction)) { agent.Instruction = inheritedAgent.Instruction; + AddDefaultInstruction(agent, inheritedAgent.Instruction); } } }