@@ -49,7 +49,7 @@ public async Task<InstructResult> Execute(
4949
5050 // Run code template
5151 var codeResponse = await RunCode ( agent , message , templateName , codeOptions ) ;
52- if ( codeResponse != null )
52+ if ( ! string . IsNullOrWhiteSpace ( codeResponse ? . Text ) )
5353 {
5454 return codeResponse ;
5555 }
@@ -169,11 +169,11 @@ await hook.OnResponseGenerated(new InstructResponseModel
169169 string templateName ,
170170 CodeInstructOptions ? codeOptions )
171171 {
172- InstructResult ? response = null ;
172+ InstructResult ? instructResult = null ;
173173
174174 if ( agent == null )
175175 {
176- return response ;
176+ return instructResult ;
177177 }
178178
179179 var agentService = _services . GetRequiredService < IAgentService > ( ) ;
@@ -192,7 +192,7 @@ await hook.OnResponseGenerated(new InstructResponseModel
192192#if DEBUG
193193 _logger . LogWarning ( $ "No code processor found. (Agent: { agent . Id } , Code processor: { codeProvider } )") ;
194194#endif
195- return response ;
195+ return instructResult ;
196196 }
197197
198198 // Get code script name
@@ -211,7 +211,7 @@ await hook.OnResponseGenerated(new InstructResponseModel
211211#if DEBUG
212212 _logger . LogWarning ( $ "Empty code script name. (Agent: { agent . Id } , { scriptName } )") ;
213213#endif
214- return response ;
214+ return instructResult ;
215215 }
216216
217217 // Get code script
@@ -222,7 +222,7 @@ await hook.OnResponseGenerated(new InstructResponseModel
222222#if DEBUG
223223 _logger . LogWarning ( $ "Empty code script. (Agent: { agent . Id } , { scriptName } )") ;
224224#endif
225- return response ;
225+ return instructResult ;
226226 }
227227
228228 // Get code arguments
@@ -266,33 +266,30 @@ await hook.OnResponseGenerated(new InstructResponseModel
266266 UseProcess = useProcess
267267 } , cancellationToken : cts . Token ) ;
268268
269- if ( codeResponse ? . Success == true )
269+ instructResult = new InstructResult
270270 {
271- response = new InstructResult
272- {
273- MessageId = message . MessageId ,
274- Template = context . CodeScript ? . Name ,
275- Text = codeResponse . Result
276- } ;
277- }
271+ MessageId = message . MessageId ,
272+ Template = context . CodeScript ? . Name ,
273+ Text = codeResponse ? . Result ?? string . Empty
274+ } ;
278275
279- var codeExeResponse = new CodeExecutionResponseModel
276+ var codeExecution = new CodeExecutionResponseModel
280277 {
281278 CodeProcessor = codeProcessor . Provider ,
282279 CodeScript = context . CodeScript ,
283- ExecutionResult = codeResponse ? . ToString ( ) ?? string . Empty ,
280+ ExecutionResult = codeResponse ,
284281 Text = message . Content ,
285282 Arguments = context . Arguments ? . DistinctBy ( x => x . Key ) . ToDictionary ( x => x . Key , x => x . Value ?? string . Empty )
286283 } ;
287284
288285 // After code execution
289286 foreach ( var hook in hooks )
290287 {
291- await hook . AfterCompletion ( agent , response ?? new ( ) ) ;
292- await hook . AfterCodeExecution ( agent , codeExeResponse ) ;
288+ await hook . AfterCompletion ( agent , instructResult ) ;
289+ await hook . AfterCodeExecution ( agent , codeExecution ) ;
293290 }
294291
295- return response ;
292+ return instructResult ;
296293 }
297294
298295 private async Task < string > GetTextCompletion (
0 commit comments