Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4e690c8
add agent rule output args
Oct 30, 2025
9750cc2
refine rule engine
iceljc Oct 30, 2025
920fcc6
rename
iceljc Oct 30, 2025
3ea642d
refine
iceljc Oct 30, 2025
ead4588
rename
iceljc Oct 30, 2025
0af83be
minor change
Oct 30, 2025
cb90c57
add logger inject
Oct 30, 2025
8fce79d
add coding settings
Oct 30, 2025
e67777e
Merge branch 'master' of https://github.com/SciSharp/BotSharp into fe…
Nov 5, 2025
1733e4f
add rule code generate instruction
Nov 5, 2025
7729f55
refine rule trigger code prompt
Nov 5, 2025
511b806
rename
Nov 5, 2025
f5d7ade
refine
iceljc Nov 6, 2025
d3a45c5
Merge branch 'features/refine-agent-rule' of https://github.com/icelj…
Nov 6, 2025
d807ec6
add rule trigger statement
Nov 6, 2025
d4df317
add render text
Nov 6, 2025
fb36f2e
return agent code script time stamp
Nov 6, 2025
7ed9211
refine
Nov 7, 2025
022ba17
resolve conflicts
iceljc Nov 8, 2025
cb7556d
refine coding settings
iceljc Nov 8, 2025
097d8fb
refine mongo collection index
Nov 10, 2025
4411ca8
resolve conflict
Nov 10, 2025
c39d8ae
clean code
Nov 10, 2025
72b24d3
minor change
Nov 10, 2025
bdc37cd
Merge branch 'master' of https://github.com/SciSharp/BotSharp into fe…
Nov 10, 2025
906432d
temp save
Nov 11, 2025
5a9e67b
resolve conflict
Nov 11, 2025
f306616
temp save
Nov 11, 2025
84d1c77
refine file knowledge options
Nov 11, 2025
6c71ddf
minor change
Nov 11, 2025
5ce5aed
add renew token
Nov 11, 2025
12ef4cd
minor change
Nov 11, 2025
31ac069
rename
Nov 11, 2025
45b9002
minor change
iceljc Nov 12, 2025
0894ab5
resolve conflict
Nov 12, 2025
23c4a30
refine instruct log filter
Nov 12, 2025
dfbedf6
refine token
Nov 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ public interface IAgentService
Task<List<AgentCodeScript>> GetAgentCodeScripts(string agentId, AgentCodeScriptFilter? filter = null)
=> Task.FromResult(new List<AgentCodeScript>());

Task<string?> GetAgentCodeScript(string agentId, string scriptName, string scriptType = AgentCodeScriptType.Src)
=> Task.FromResult(string.Empty);
Task<AgentCodeScript?> GetAgentCodeScript(string agentId, string scriptName, string scriptType = AgentCodeScriptType.Src)
=> Task.FromResult((AgentCodeScript?)null);

Task<bool> UpdateAgentCodeScripts(string agentId, List<AgentCodeScript> codeScripts, AgentCodeScriptUpdateOptions? options = null)
=> Task.FromResult(false);

Task<bool> DeleteAgentCodeScripts(string agentId, List<AgentCodeScript>? codeScripts = null)
=> Task.FromResult(false);

Task<CodeGenerationResult> GenerateCodeScript(string agentId, string text, CodeProcessOptions? options = null)
Task<CodeGenerationResult> GenerateCodeScript(string agentId, string text, CodeGenHandleOptions? options = null)
=> Task.FromResult(new CodeGenerationResult());
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public class AgentCodeScript : AgentCodeScriptBase
public string Id { get; set; }
public string AgentId { get; set; } = null!;

public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
public DateTime UpdatedTime { get; set; } = DateTime.UtcNow;

public AgentCodeScript() : base()
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace BotSharp.Abstraction.Coding.Contexts;

public class CodeExecutionContext
{
public AgentCodeScript CodeScript { get; set; }
public List<KeyValue> Arguments { get; set; } = [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace BotSharp.Abstraction.Coding.Enums;

public static class BuiltInCodeProcessor
{
public const string PyInterpreter = "botsharp-py-interpreter";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BotSharp.Abstraction.Coding.Models;

public class CodeExecutionResponseModel
{
public string CodeProcessor { get; set; } = default!;
public AgentCodeScript CodeScript { get; set; }
public IDictionary<string, string>? Arguments { get; set; }
public string Text { get; set; } = default!;
public string ExecutionResult { get; set; } = default!;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BotSharp.Abstraction.Coding.Options;

public class CodeProcessOptions : CodeGenerationOptions
public class CodeGenHandleOptions : CodeGenerationOptions
{
/// <summary>
/// Code processor provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ public class CodeGenerationOptions : LlmConfigBase
public string? TemplateName { get; set; }

/// <summary>
/// The programming language
/// Programming language
/// </summary>
[JsonPropertyName("language")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Language { get; set; } = "python";
[JsonPropertyName("programming_language")]
public string? ProgrammingLanguage { get; set; }

/// <summary>
/// Data that can be used to fill in the prompt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public class CodeInterpretResponse : ResponseBase

public override string ToString()
{
return Result.IfNullOrEmptyAs(ErrorMsg ?? $"Success: {Success}")!;
return Result.IfNullOrEmptyAs(ErrorMsg.IfNullOrEmptyAs($"Success: {Success}"))!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class CodeScriptExecutionSettings
public string? Processor { get; set; }
public bool UseLock { get; set; }
public bool UseProcess { get; set; }
public int? TimeoutSeconds { get; set; }
public int TimeoutSeconds { get; set; } = 3;
public int MaxConcurrency { get; set; } = 1;
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
namespace BotSharp.Abstraction.Files.Options;

public class FileHandleOptions
public class FileHandleOptions : LlmConfigBase
{
/// <summary>
/// Llm provider
/// </summary>
public string? Provider { get; set; }

/// <summary>
/// llm model
/// </summary>
public string? Model { get; set; }

/// <summary>
/// Llm maximum output tokens
/// </summary>
public int? MaxOutputTokens { get; set; }

/// <summary>
/// Reasoning effort level
/// </summary>
public string? ReasoningEfforLevel { get; set; }

/// <summary>
/// Instruction
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using BotSharp.Abstraction.Files.Options;
using BotSharp.Abstraction.Files.Responses;
using BotSharp.Abstraction.Knowledges.Options;
using BotSharp.Abstraction.Knowledges.Responses;

namespace BotSharp.Abstraction.Files.Proccessors;

Expand All @@ -9,4 +11,7 @@ public interface IFileProcessor

Task<FileHandleResponse> HandleFilesAsync(Agent agent, string text, IEnumerable<InstructFileModel> files, FileHandleOptions? options = null)
=> throw new NotImplementedException();

Task<FileKnowledgeResponse> GetFileKnowledgeAsync(FileBinaryDataModel file, FileKnowledgeHandleOptions? options = null)
=> throw new NotImplementedException();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BotSharp.Abstraction.Coding.Contexts;
using BotSharp.Abstraction.Coding.Models;
using BotSharp.Abstraction.Hooks;
using BotSharp.Abstraction.Instructs.Contexts;
using BotSharp.Abstraction.Instructs.Models;

namespace BotSharp.Abstraction.Instructs;
Expand All @@ -10,6 +11,6 @@ public interface IInstructHook : IHookBase
Task AfterCompletion(Agent agent, InstructResult result) => Task.CompletedTask;
Task OnResponseGenerated(InstructResponseModel response) => Task.CompletedTask;

Task BeforeCodeExecution(Agent agent, RoleDialogModel message, CodeInstructContext context) => Task.CompletedTask;
Task AfterCodeExecution(Agent agent, InstructResult result) => Task.CompletedTask;
Task BeforeCodeExecution(Agent agent, CodeExecutionContext context) => Task.CompletedTask;
Task AfterCodeExecution(Agent agent, CodeExecutionResponseModel response) => Task.CompletedTask;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using BotSharp.Abstraction.Coding.Contexts;
using BotSharp.Abstraction.Coding.Models;
using BotSharp.Abstraction.Instructs.Models;

namespace BotSharp.Abstraction.Instructs;
Expand All @@ -20,4 +22,14 @@ public virtual async Task OnResponseGenerated(InstructResponseModel response)
{
await Task.CompletedTask;
}

public virtual async Task BeforeCodeExecution(Agent agent, CodeExecutionContext context)
{
await Task.CompletedTask;
}

public virtual async Task AfterCodeExecution(Agent agent, CodeExecutionResponseModel response)
{
await Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ public class InstructOptions
/// <summary>
/// Image convert provider
/// </summary>
public string? ImageConvertProvider { get; set; }
public string? ImageConverter { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public interface IKnowledgeService
/// </summary>
/// <param name="collectionName"></param>
/// <param name="files"></param>
/// <param name="option"></param>
/// <returns></returns>
Task<UploadKnowledgeResponse> UploadDocumentsToKnowledge(string collectionName, IEnumerable<ExternalFileModel> files, ChunkOption? option = null);
Task<UploadKnowledgeResponse> UploadDocumentsToKnowledge(string collectionName, IEnumerable<ExternalFileModel> files, KnowledgeDocOptions? options = null);
/// <summary>
/// Save document content to knowledgebase without saving the document
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using BotSharp.Abstraction.VectorStorage.Models;

namespace BotSharp.Abstraction.Knowledges.Models;

public class FileKnowledgeModel
{
public IEnumerable<string> Contents { get; set; } = [];
public IDictionary<string, VectorPayloadValue>? Payload { get; set; }
}


public class FileKnowledgeWrapper
{
public Guid FileId { get; set; }
public string? FileSource { get; set; }
public FileBinaryDataModel FileData { get; set; }
public IEnumerable<FileKnowledgeModel> FileKnowledges { get; set; } = [];
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BotSharp.Abstraction.Files.Models;
namespace BotSharp.Abstraction.Knowledges.Models;

public class KnowledgeFileModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace BotSharp.Abstraction.Knowledges.Options;

public class FileKnowledgeHandleOptions : LlmConfigBase
{
/// <summary>
/// Agent id
/// </summary>
public string? AgentId { get; set; }

/// <summary>
/// Instruction
/// </summary>
public string? Instruction { get; set; }

/// <summary>
/// Message from user
/// </summary>
public string? UserMessage { get; set; }

/// <summary>
/// Template name in Agent
/// </summary>
public string? TemplateName { get; set; }

/// <summary>
/// The upstream where the file llm is invoked
/// </summary>
public string? InvokeFrom { get; set; }

/// <summary>
/// Data that is used to render instruction
/// </summary>
public Dictionary<string, object>? Data { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace BotSharp.Abstraction.Knowledges.Options;

public class KnowledgeDocOptions : FileKnowledgeHandleOptions
{
public string? Processor { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace BotSharp.Abstraction.Knowledges.Responses;

public class FileKnowledgeResponse : ResponseBase
{
public IEnumerable<FileKnowledgeModel> Knowledges { get; set; } = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class InstructLogFilter : Pagination
public List<string>? TemplateNames { get; set; }
public List<string>? UserIds { get; set; }
public List<KeyValue>? States { get; set; }
public string? SimilarTemplateName { get; set; }
public DateTime? StartTime { get; set; }
public DateTime? EndTime { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
List<User> GetUsersByAffiliateId(string affiliateId) => throw new NotImplementedException();
User? GetUserByUserName(string userName) => throw new NotImplementedException();
void UpdateUserName(string userId, string userName) => throw new NotImplementedException();
Dashboard? GetDashboard(string id = null) => throw new NotImplementedException();

Check warning on line 51 in src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Cannot convert null literal to non-nullable reference type.

Check warning on line 51 in src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Cannot convert null literal to non-nullable reference type.

Check warning on line 51 in src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Cannot convert null literal to non-nullable reference type.

Check warning on line 51 in src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Cannot convert null literal to non-nullable reference type.

Check warning on line 51 in src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Cannot convert null literal to non-nullable reference type.

Check warning on line 51 in src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Cannot convert null literal to non-nullable reference type.
void CreateUser(User user) => throw new NotImplementedException();
void UpdateExistUser(string userId, User user) => throw new NotImplementedException();
void UpdateUserVerified(string userId) => throw new NotImplementedException();
Expand Down Expand Up @@ -114,7 +114,7 @@
#region Agent Code
List<AgentCodeScript> GetAgentCodeScripts(string agentId, AgentCodeScriptFilter? filter = null)
=> throw new NotImplementedException();
string? GetAgentCodeScript(string agentId, string scriptName, string scriptType = AgentCodeScriptType.Src)
AgentCodeScript? GetAgentCodeScript(string agentId, string scriptName, string scriptType = AgentCodeScriptType.Src)
=> throw new NotImplementedException();
bool UpdateAgentCodeScripts(string agentId, List<AgentCodeScript> scripts, AgentCodeScriptDbUpdateOptions? options = null)
=> throw new NotImplementedException();
Expand Down
12 changes: 11 additions & 1 deletion src/Infrastructure/BotSharp.Abstraction/Rules/IRuleEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@ namespace BotSharp.Abstraction.Rules;

public interface IRuleEngine
{
Task<IEnumerable<string>> Triggered(IRuleTrigger trigger, string data, List<MessageState>? states = null);
/// <summary>
/// Trigger the rule that is subscribed by agents.
/// </summary>
/// <param name="trigger"></param>
/// <param name="text"></param>
/// <param name="states"></param>
/// <param name="options"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
Task<IEnumerable<string>> Triggered(IRuleTrigger trigger, string text, IEnumerable<MessageState>? states = null, RuleTriggerOptions? options = null)
=> throw new NotImplementedException();
}
12 changes: 12 additions & 0 deletions src/Infrastructure/BotSharp.Abstraction/Rules/IRuleTrigger.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Text.Json;

namespace BotSharp.Abstraction.Rules;

public interface IRuleTrigger
Expand All @@ -9,4 +11,14 @@ public interface IRuleTrigger
string EntityType { get; set; }

string EntityId { get; set; }

/// <summary>
/// The default arguments as input to code trigger (display purpose)
/// </summary>
JsonDocument OutputArgs => JsonDocument.Parse("{}");

/// <summary>
/// Explain the purpose of rule trigger (display purpose)
/// </summary>
string Statement => string.Empty;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Text.Json;

namespace BotSharp.Abstraction.Rules.Options;

public class RuleTriggerOptions
{
/// <summary>
/// Code processor provider
/// </summary>
public string? CodeProcessor { get; set; }

/// <summary>
/// Code script name
/// </summary>
public string? CodeScriptName { get; set; }

/// <summary>
/// Argument name as an input key to the code script
/// </summary>
public string? ArgumentName { get; set; }

/// <summary>
/// Json arguments as an input value to the code script
/// </summary>
public JsonDocument? ArgumentContent { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ public interface IAuthenticationHook
Task<User> Authenticate(string id, string password)
=> Task.FromResult(new User());

/// <summary>
/// Renew token for authentication
/// </summary>
/// <param name="refreshToken"></param>
/// <param name="accessToken"></param>
/// <returns></returns>
Task<User?> RenewAuthentication(string refreshToken, string? accessToken = null)
=> Task.FromResult((User?)null);

/// <summary>
/// Add extra claims to user
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public interface IUserService
Task<Token?> GetAffiliateToken(string authorization);
Task<Token?> GetAdminToken(string authorization);
Task<Token?> GetToken(string authorization);
Task<Token?> RenewToken(string refreshToken, string? accessToken = null);
Task<Token> CreateTokenByUser(User user);
Task<Token> RenewToken();
Task<User> GetMyProfile();
Task<bool> VerifyUserNameExisting(string userName);
Task<bool> VerifyEmailExisting(string email);
Expand Down
1 change: 1 addition & 0 deletions src/Infrastructure/BotSharp.Abstraction/Using.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
global using BotSharp.Abstraction.Crontab.Models;
global using BotSharp.Abstraction.MCP.Models;
global using BotSharp.Abstraction.Settings;
global using BotSharp.Abstraction.Rules.Options;
global using BotSharp.Abstraction.Coding.Settings;
Loading
Loading