Skip to content

Commit 9593021

Browse files
committed
change code execution response
1 parent ef3b4ff commit 9593021

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using BotSharp.Abstraction.Coding.Responses;
2+
13
namespace BotSharp.Abstraction.Coding.Models;
24

35
public class CodeExecutionResponseModel
@@ -6,5 +8,5 @@ public class CodeExecutionResponseModel
68
public AgentCodeScript CodeScript { get; set; }
79
public IDictionary<string, string>? Arguments { get; set; }
810
public string Text { get; set; } = default!;
9-
public string ExecutionResult { get; set; } = default!;
11+
public CodeInterpretResponse? ExecutionResult { get; set; }
1012
}

src/Infrastructure/BotSharp.Core.Rules/Engines/RuleEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private async Task<bool> TriggerCodeScript(Agent agent, string triggerName, Rule
153153
CodeProcessor = processor.Provider,
154154
CodeScript = codeScript,
155155
Arguments = arguments.DistinctBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value ?? string.Empty),
156-
ExecutionResult = response?.ToString() ?? string.Empty
156+
ExecutionResult = response
157157
};
158158

159159
foreach (var hook in hooks)

src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -268,7 +268,7 @@ await hook.OnResponseGenerated(new InstructResponseModel
268268

269269
if (codeResponse?.Success == true)
270270
{
271-
response = new InstructResult
271+
instructResult = new InstructResult
272272
{
273273
MessageId = message.MessageId,
274274
Template = context.CodeScript?.Name,
@@ -280,19 +280,24 @@ await hook.OnResponseGenerated(new InstructResponseModel
280280
{
281281
CodeProcessor = codeProcessor.Provider,
282282
CodeScript = context.CodeScript,
283-
ExecutionResult = codeResponse?.ToString() ?? string.Empty,
283+
ExecutionResult = codeResponse,
284284
Text = message.Content,
285285
Arguments = context.Arguments?.DistinctBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value ?? string.Empty)
286286
};
287287

288288
// After code execution
289289
foreach (var hook in hooks)
290290
{
291-
await hook.AfterCompletion(agent, response ?? new());
291+
await hook.AfterCompletion(agent, instructResult ?? new());
292292
await hook.AfterCodeExecution(agent, codeExeResponse);
293293
}
294294

295-
return response;
295+
if (instructResult != null)
296+
{
297+
instructResult.Text = codeExeResponse?.ExecutionResult?.ToString() ?? string.Empty;
298+
}
299+
300+
return instructResult;
296301
}
297302

298303
private async Task<string> GetTextCompletion(

src/Infrastructure/BotSharp.Logger/Hooks/InstructionLogHook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public override async Task AfterCodeExecution(Agent agent, CodeExecutionResponse
8282
TemplateName = response.CodeScript?.Name,
8383
UserMessage = response.Text,
8484
SystemInstruction = $"Code script name: {response.CodeScript}, Version: {codeScriptVersion.ToString("o")}",
85-
CompletionText = response.ExecutionResult,
85+
CompletionText = response.ExecutionResult?.ToString() ?? string.Empty,
8686
States = response.Arguments?.ToDictionary() ?? [],
8787
UserId = user?.Id
8888
}

0 commit comments

Comments
 (0)