Skip to content

Commit 8fce79d

Browse files
author
Jicheng Lu
committed
add coding settings
1 parent cb90c57 commit 8fce79d

File tree

9 files changed

+66
-9
lines changed

9 files changed

+66
-9
lines changed

src/Infrastructure/BotSharp.Abstraction/Agents/Settings/AgentSettings.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ public class AgentSettings
1010
/// <summary>
1111
/// This is the default LLM config for agent
1212
/// </summary>
13-
public AgentLlmConfig LlmConfig { get; set; }
14-
= new AgentLlmConfig();
13+
public AgentLlmConfig LlmConfig { get; set; } = new AgentLlmConfig();
14+
15+
/// <summary>
16+
/// General coding settings
17+
/// </summary>
18+
public CodingSettings Coding { get; set; } = new CodingSettings();
1519
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace BotSharp.Abstraction.Coding.Settings;
2+
3+
public class CodingSettings
4+
{
5+
/// <summary>
6+
/// Llm provider to generate code script
7+
/// </summary>
8+
public string? Provider { get; set; }
9+
10+
/// <summary>
11+
/// Llm model to generate code script
12+
/// </summary>
13+
public string? Model { get; set; }
14+
}

src/Infrastructure/BotSharp.Abstraction/Using.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
global using BotSharp.Abstraction.Crontab.Models;
2323
global using BotSharp.Abstraction.MCP.Models;
2424
global using BotSharp.Abstraction.Settings;
25-
global using BotSharp.Abstraction.Rules.Options;
25+
global using BotSharp.Abstraction.Rules.Options;
26+
global using BotSharp.Abstraction.Coding.Settings;

src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using BotSharp.Abstraction.Templating;
66
using BotSharp.Abstraction.Users.Enums;
77
using BotSharp.Core.Agents.Hooks;
8-
using BotSharp.Core.Coding;
98
using Microsoft.Extensions.Configuration;
109

1110
namespace BotSharp.Core.Agents;
@@ -49,8 +48,6 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
4948
render.RegisterType(typeof(AgentSettings));
5049
return settingService.Bind<AgentSettings>("Agent");
5150
});
52-
53-
services.AddSingleton<CodeScriptExecutor>();
5451
}
5552

5653
public bool AttachMenu(List<PluginMenuDef> menu)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.Extensions.Configuration;
2+
3+
namespace BotSharp.Core.Coding;
4+
5+
public class CodingPlugin : IBotSharpPlugin
6+
{
7+
public string Id => "31bc334b-9462-4191-beac-cb4a139b78c1";
8+
public string Name => "Coding";
9+
public string Description => "Handling execution and generation of code scripts";
10+
11+
public void RegisterDI(IServiceCollection services, IConfiguration config)
12+
{
13+
services.AddSingleton<CodeScriptExecutor>();
14+
}
15+
}

src/Infrastructure/BotSharp.Core/Using.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
global using BotSharp.Abstraction.Conversations.Models;
77
global using BotSharp.Abstraction.Conversations.Settings;
88
global using BotSharp.Abstraction.Coding.Models;
9+
global using BotSharp.Abstraction.Coding.Settings;
910
global using BotSharp.Abstraction.Crontab.Models;
1011
global using BotSharp.Abstraction.Files;
1112
global using BotSharp.Abstraction.Files.Enums;

src/Plugins/BotSharp.Plugin.PythonInterpreter/Services/PyCodeInterpreter.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ public class PyCodeInterpreter : ICodeProcessor
1010
private readonly IServiceProvider _services;
1111
private readonly ILogger<PyCodeInterpreter> _logger;
1212
private readonly CodeScriptExecutor _executor;
13+
private readonly AgentSettings _agentSettings;
1314

1415
public PyCodeInterpreter(
1516
IServiceProvider services,
1617
ILogger<PyCodeInterpreter> logger,
17-
CodeScriptExecutor executor)
18+
CodeScriptExecutor executor,
19+
AgentSettings agentSettings)
1820
{
1921
_services = services;
2022
_logger = logger;
2123
_executor = executor;
24+
_agentSettings = agentSettings;
2225
}
2326

2427
public string Provider => BuiltInCodeProcessor.PyInterpreter;
@@ -54,15 +57,16 @@ public async Task<CodeGenerationResult> GenerateCodeScriptAsync(string text, Cod
5457
instruction = agent.Templates?.FirstOrDefault(x => x.Name.IsEqualTo(templateName))?.Content;
5558
}
5659

60+
var (provider, model) = GetLlmProviderModel();
5761
var innerAgent = new Agent
5862
{
5963
Id = agent?.Id ?? BuiltInAgentId.AIProgrammer,
6064
Name = agent?.Name ?? "AI Programmer",
6165
Instruction = instruction,
6266
LlmConfig = new AgentLlmConfig
6367
{
64-
Provider = options?.Provider ?? "openai",
65-
Model = options?.Model ?? "gpt-5-mini",
68+
Provider = options?.Provider ?? provider,
69+
Model = options?.Model ?? model,
6670
MaxOutputTokens = options?.MaxOutputTokens,
6771
ReasoningEffortLevel = options?.ReasoningEffortLevel
6872
},
@@ -178,5 +182,21 @@ private CodeInterpretResponse CoreRun(string codeScript, CodeInterpretOptions? o
178182
}
179183
}
180184
}
185+
186+
private (string, string) GetLlmProviderModel()
187+
{
188+
var provider = _agentSettings.Coding?.Provider;
189+
var model = _agentSettings.Coding?.Model;
190+
191+
if (!string.IsNullOrEmpty(provider) && !string.IsNullOrEmpty(model))
192+
{
193+
return (provider, model);
194+
}
195+
196+
provider = "openai";
197+
model = "gpt-5-mini";
198+
199+
return (provider, model);
200+
}
181201
#endregion
182202
}

src/Plugins/BotSharp.Plugin.PythonInterpreter/Using.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
global using BotSharp.Abstraction.Coding;
2424
global using BotSharp.Abstraction.Coding.Enums;
2525
global using BotSharp.Abstraction.Coding.Models;
26+
global using BotSharp.Abstraction.Coding.Settings;
2627
global using BotSharp.Abstraction.Coding.Options;
2728
global using BotSharp.Abstraction.Coding.Responses;
2829
global using BotSharp.Core.Coding;

src/WebStarter/appsettings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@
468468
"LlmConfig": {
469469
"Provider": "openai",
470470
"Model": "gpt-4.1-nano"
471+
},
472+
"Coding": {
473+
"Provider": "openai",
474+
"Model": "gpt-5-mini"
471475
}
472476
},
473477

0 commit comments

Comments
 (0)