hotfix AddDefaultInstruction

This commit is contained in:
nick.yi 2025-05-29 10:33:22 +08:00
parent 57f25f3c82
commit d222a120ac

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);
}
}
}