diff --git a/src/Infrastructure/BotSharp.Abstraction/Instructs/Models/CodeInstructOptions.cs b/src/Infrastructure/BotSharp.Abstraction/Instructs/Models/CodeInstructOptions.cs index 673e3825..72126653 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Instructs/Models/CodeInstructOptions.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Instructs/Models/CodeInstructOptions.cs @@ -4,4 +4,5 @@ public class CodeInstructOptions { public string? CodeScriptName { get; set; } public string? CodeInterpretProvider { get; set; } + public List? Arguments { get; set; } } diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index f13af9a6..3da95e02 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -112,7 +112,7 @@ public interface IBotSharpRepository : IHaveServiceProvider string? GetAgentCodeScript(string agentId, string scriptName) => throw new NotImplementedException(); - bool UpdateAgentCodeScript(string agentId, AgentCodeScript script) + bool PatchAgentCodeScript(string agentId, AgentCodeScript script) => throw new NotImplementedException(); #endregion diff --git a/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs index 85960878..3916beb1 100644 --- a/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs +++ b/src/Infrastructure/BotSharp.Core/Instructs/Services/InstructService.Execute.cs @@ -56,9 +56,7 @@ public partial class InstructService var db = _services.GetRequiredService(); var state = _services.GetRequiredService(); - var arguments = state.GetStates().Select(x => new KeyValue(x.Key, x.Value)); var codeScript = db.GetAgentCodeScript(agentId, codeOptions.CodeScriptName); - if (string.IsNullOrWhiteSpace(codeScript)) { var error = $"Empty code script. (Agent: {agentId}, Code script: {codeOptions.CodeScriptName})"; @@ -67,7 +65,7 @@ public partial class InstructService } else { - var result = await codeInterpreter.RunCode(codeScript, arguments); + var result = await codeInterpreter.RunCode(codeScript, codeOptions.Arguments); response.Text = result?.Result?.ToString(); } } diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs index 35351311..bd259952 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs @@ -547,6 +547,12 @@ namespace BotSharp.Core.Repository public string GetAgentTemplate(string agentId, string templateName) { + if (string.IsNullOrWhiteSpace(agentId) + || string.IsNullOrWhiteSpace(templateName)) + { + return string.Empty; + } + var dir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId, AGENT_TEMPLATES_FOLDER); if (!Directory.Exists(dir)) return string.Empty; diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentCode.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentCode.cs index b8c18ddd..a60d8146 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentCode.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentCode.cs @@ -13,7 +13,7 @@ public partial class FileRepository return null; } - var dir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId, AGENT_CODE_FOLDER); + var dir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId, AGENT_CODES_FOLDER); if (!Directory.Exists(dir)) { return null; @@ -30,14 +30,14 @@ public partial class FileRepository return string.Empty; } - public bool UpdateAgentCodeScript(string agentId, AgentCodeScript script) + public bool PatchAgentCodeScript(string agentId, AgentCodeScript script) { if (string.IsNullOrEmpty(agentId) || script == null) { return false; } - var dir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId, AGENT_CODE_FOLDER); + var dir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir, agentId, AGENT_CODES_FOLDER); if (!Directory.Exists(dir)) { return false; diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs index 78ff764c..69e8bd38 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.cs @@ -26,7 +26,7 @@ public partial class FileRepository : IBotSharpRepository private const string AGENT_FUNCTIONS_FOLDER = "functions"; private const string AGENT_TEMPLATES_FOLDER = "templates"; private const string AGENT_RESPONSES_FOLDER = "responses"; - private const string AGENT_CODE_FOLDER = "codes"; + private const string AGENT_CODES_FOLDER = "codes"; private const string AGENT_TASKS_FOLDER = "tasks"; private const string AGENT_TASK_PREFIX = "#metadata"; private const string AGENT_TASK_SUFFIX = "/metadata"; diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs index cf076259..eab8637c 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/InstructModeController.cs @@ -37,7 +37,7 @@ public class InstructModeController : ControllerBase var result = await instructor.Execute(agentId, new RoleDialogModel(AgentRole.User, input.Text), instruction: input.Instruction, - llmTemplateName: input.Template, + templateName: input.Template, files: input.Files, codeOptions: input.CodeOptions); diff --git a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyInterpretService.cs b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyInterpretService.cs index 5f7a8961..82739f2a 100644 --- a/src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyInterpretService.cs +++ b/src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyInterpretService.cs @@ -79,7 +79,7 @@ public class PyInterpretService : ICodeInterpretService } catch (Exception ex) { - var errorMsg = $"Error when executing python code in {nameof(PyInterpretService)}-{Provider}. {ex.Message}"; + var errorMsg = $"Error when executing python code in {nameof(PyInterpretService)}: {Provider}. {ex.Message}"; _logger.LogError(ex, errorMsg); return new CodeInterpretResult