Skip to content

Commit c8149b6

Browse files
authored
Merge pull request #1069 from yileicn/master
hotfix AddDefaultInstruction
2 parents 82affd8 + d222a12 commit c8149b6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,25 @@ public async Task<Agent> GetAgent(string id)
7171

7272
profile.Plugin = GetPlugin(profile.Id);
7373

74-
//add default instruction to ChannelInstructions
75-
var defaultInstruction = new ChannelInstruction() { Channel = string.Empty, Instruction = profile?.Instruction };
76-
profile.ChannelInstructions.Insert(0, defaultInstruction);
74+
AddDefaultInstruction(profile, profile.Instruction);
7775

7876
return profile;
7977
}
8078

79+
/// <summary>
80+
/// Add default instruction to ChannelInstructions
81+
/// </summary>
82+
private void AddDefaultInstruction(Agent agent, string instruction)
83+
{
84+
//check if instruction is empty
85+
if (string.IsNullOrWhiteSpace(instruction)) return;
86+
//check if instruction is already set
87+
if (agent.ChannelInstructions.Exists(p => p.Channel == string.Empty)) return;
88+
//Add default instruction to ChannelInstructions
89+
var defaultInstruction = new ChannelInstruction() { Channel = string.Empty, Instruction = instruction };
90+
agent.ChannelInstructions.Insert(0, defaultInstruction);
91+
}
92+
8193
public async Task InheritAgent(Agent agent)
8294
{
8395
if (string.IsNullOrWhiteSpace(agent?.InheritAgentId)) return;
@@ -98,6 +110,7 @@ public async Task InheritAgent(Agent agent)
98110
if (string.IsNullOrWhiteSpace(agent.Instruction))
99111
{
100112
agent.Instruction = inheritedAgent.Instruction;
113+
AddDefaultInstruction(agent, inheritedAgent.Instruction);
101114
}
102115
}
103116
}

0 commit comments

Comments
 (0)