Merge pull request #1069 from yileicn/master

hotfix AddDefaultInstruction
This commit is contained in:
易磊 2025-05-29 10:42:14 +08:00 committed by GitHub
commit c8149b63e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -71,13 +71,25 @@ public partial class AgentService
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;
}
/// <summary>
/// Add default instruction to ChannelInstructions
/// </summary>
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 partial class AgentService
if (string.IsNullOrWhiteSpace(agent.Instruction))
{
agent.Instruction = inheritedAgent.Instruction;
AddDefaultInstruction(agent, inheritedAgent.Instruction);
}
}
}