@@ -71,13 +71,25 @@ public async Task<Agent> GetAgent(string id)
71
71
72
72
profile . Plugin = GetPlugin ( profile . Id ) ;
73
73
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 ) ;
77
75
78
76
return profile ;
79
77
}
80
78
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
+
81
93
public async Task InheritAgent ( Agent agent )
82
94
{
83
95
if ( string . IsNullOrWhiteSpace ( agent ? . InheritAgentId ) ) return ;
@@ -98,6 +110,7 @@ public async Task InheritAgent(Agent agent)
98
110
if ( string . IsNullOrWhiteSpace ( agent . Instruction ) )
99
111
{
100
112
agent . Instruction = inheritedAgent . Instruction ;
113
+ AddDefaultInstruction ( agent , inheritedAgent . Instruction ) ;
101
114
}
102
115
}
103
116
}
0 commit comments