Skip to content

merge latest #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a3c6a6b
planner get remaining task.
Feb 1, 2024
3f3aee3
Merge branch 'master' of https://github.com/hchen2020/BotSharp
Feb 1, 2024
2ad0f23
Optimize WebDriver.
Feb 2, 2024
0116baf
fix : GenerateJwtToken not null
geffzhang Feb 2, 2024
b29b074
Merge pull request #285 from hchen2020/master
Oceania2018 Feb 2, 2024
a8c2b49
AgentTask
Oceania2018 Feb 2, 2024
1ca4979
minor change
Feb 3, 2024
326bcd2
add agent task fetch, create, delete
Feb 4, 2024
9ea4b02
refine code
Feb 4, 2024
e7223f1
add update agent task
Feb 4, 2024
041d2df
refine page search
Feb 4, 2024
620bd02
Merge pull request #287 from iceljc/features/add-agent-task-mongo
Oceania2018 Feb 4, 2024
c5f15b8
Allow WebDriver use persistent context.
Oceania2018 Feb 4, 2024
63e5fdb
Added DirectAgentId in AgentTask
Oceania2018 Feb 4, 2024
ce13c90
add direct agent id
Feb 5, 2024
834b4e5
Merge pull request #288 from iceljc/features/add-agent-task-mongo
Oceania2018 Feb 5, 2024
8aa7158
Fix sequential planning infinite loop.
Oceania2018 Feb 5, 2024
37ce5f4
Allow send 3rd original bearer token.
Feb 5, 2024
c45b01a
Merge pull request #289 from hchen2020/master
Oceania2018 Feb 5, 2024
911b2aa
add task migration
iceljc Feb 5, 2024
fbc2760
minor change
iceljc Feb 5, 2024
08620ab
Merge pull request #290 from iceljc/features/migrate-agent-task-mongo
Oceania2018 Feb 5, 2024
19ee935
Abstract IWebBrowser.
Feb 6, 2024
4a1ae03
Add more dialog history for SequentialPlanner
Feb 6, 2024
c84da67
Add screenshots.
Feb 6, 2024
1d69fe1
Merge pull request #291 from hchen2020/master
Oceania2018 Feb 6, 2024
b5ab7ca
Add hook of OnDialogRecordLoaded.
Feb 6, 2024
5c852df
Merge branch 'SciSharp:master' into master
hchen2020 Feb 6, 2024
6cb4aa2
Merge pull request #292 from hchen2020/master
Oceania2018 Feb 7, 2024
0473923
improve webdrive action response.
Feb 8, 2024
8985fc9
.net 8.0
Feb 8, 2024
b86bf02
Merge pull request #293 from hchen2020/master
Oceania2018 Feb 8, 2024
1518def
Merge branch 'docker' into dotnet8
geffzhang Feb 9, 2024
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
14 changes: 7 additions & 7 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>10.0</LangVersion>
<BotSharpVersion>0.22.0</BotSharpVersion>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>10.0</LangVersion>
<BotSharpVersion>0.22.0</BotSharpVersion>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ BotSharp uses component design, the kernel is kept to a minimum, and business fu
- BotSharp.Plugin.PaddleSharp

#### Tools
- BotSharp.Plugin.Dashboard
- BotSharp.Plugin.RoutingSpeeder
- BotSharp.Plugin.WebDriver
- BotSharp.Plugin.PizzaBot
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@

# General information about the project.
project = 'BotSharp'
copyright = 'Since 2018, Haiping Chen'
copyright = 'Since 2018, SciSharp STACK'
author = 'Haiping Chen'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.21'
version = '0.23'
# The full version, including alpha/beta/rc tags.
release = '0.21.0'
release = '0.23.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
10 changes: 10 additions & 0 deletions src/Infrastructure/BotSharp.Abstraction/Agents/Enums/AgentField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ public enum AgentField
Sample,
LlmConfig
}

public enum AgentTaskField
{
All = 1,
Name,
Description,
Enabled,
Content,
DirectAgentId
}
14 changes: 14 additions & 0 deletions src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BotSharp.Abstraction.Functions.Models;
using BotSharp.Abstraction.Plugins.Models;
using BotSharp.Abstraction.Routing.Models;
using BotSharp.Abstraction.Tasks.Models;

namespace BotSharp.Abstraction.Agents.Models;

Expand Down Expand Up @@ -36,6 +37,13 @@ public class Agent
public List<AgentTemplate> Templates { get; set; }
= new List<AgentTemplate>();

/// <summary>
/// Agent tasks
/// </summary>
[JsonIgnore]
public List<AgentTask> Tasks { get; set; }
= new List<AgentTask>();

/// <summary>
/// Samples
/// </summary>
Expand Down Expand Up @@ -136,6 +144,12 @@ public Agent SetTemplates(List<AgentTemplate> templates)
return this;
}

public Agent SetTasks(List<AgentTask> tasks)
{
Tasks = tasks ?? new List<AgentTask>();
return this;
}

public Agent SetFunctions(List<FunctionDef> functions)
{
Functions = functions ?? new List<FunctionDef>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public virtual Task OnStateChanged(string name, string preValue, string currentV
return Task.CompletedTask;
}

public virtual Task OnDialogRecordLoaded(RoleDialogModel dialog)
{
return Task.CompletedTask;
}

public virtual Task OnDialogsLoaded(List<RoleDialogModel> dialogs)
{
_dialogs = dialogs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public interface IConversationHook
/// <returns></returns>
Task OnDialogsLoaded(List<RoleDialogModel> dialogs);

/// <summary>
/// Triggered when every dialog record is loaded
/// It can be used to populate extra data point before presenting to user.
/// </summary>
/// <param name="dialog"></param>
/// <returns></returns>
Task OnDialogRecordLoaded(RoleDialogModel dialog);

Task OnStateLoaded(ConversationState state);
Task OnStateChanged(string name, string preValue, string currentValue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class FunctionCallFromLlm : RoutingArgs
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public bool ExecutingDirectly { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public bool HideDialogContext { get; set; }

/// <summary>
/// Router routed to a wrong agent.
/// Set this flag as True will force router to re-route current request to a new agent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public interface ILlmProviderService
{
LlmModelSetting GetSetting(string provider, string model);
List<string> GetProviders();
LlmModelSetting GetProviderModel(string provider, string id);
List<LlmModelSetting> GetProviderModels(string provider);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace BotSharp.Abstraction.Repositories.Filters;

public class AgentTaskFilter
{
public Pagination Pager { get; set; } = new Pagination();
public string? AgentId { get; set; }
public bool? Enabled { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BotSharp.Abstraction.Plugins.Models;
using BotSharp.Abstraction.Repositories.Filters;
using BotSharp.Abstraction.Repositories.Models;
using BotSharp.Abstraction.Tasks.Models;
using BotSharp.Abstraction.Users.Models;

namespace BotSharp.Abstraction.Repositories;
Expand Down Expand Up @@ -34,6 +35,16 @@ public interface IBotSharpRepository
string GetAgentTemplate(string agentId, string templateName);
#endregion

#region Agent Task
PagedItems<AgentTask> GetAgentTasks(AgentTaskFilter filter);
AgentTask? GetAgentTask(string agentId, string taskId);
void InsertAgentTask(AgentTask task);
void BulkInsertAgentTasks(List<AgentTask> tasks);
void UpdateAgentTask(AgentTask task, AgentTaskField field);
bool DeleteAgentTask(string agentId, string taskId);
bool DeleteAgentTasks();
#endregion

#region Conversation
void CreateNewConversation(Conversation conversation);
bool DeleteConversation(string conversationId);
Expand All @@ -49,9 +60,7 @@ public interface IBotSharpRepository
List<Conversation> GetLastConversations();
bool TruncateConversation(string conversationId, string messageId);
#endregion
#region Statistics
void IncrementConversationCount();
#endregion

#region Execution Log
void AddExecutionLogs(string conversationId, List<string> logs);
List<string> GetExecutionLogs(string conversationId);
Expand All @@ -60,4 +69,8 @@ public interface IBotSharpRepository
#region LLM Completion Log
void SaveLlmCompletionLog(LlmCompletionLog log);
#endregion

#region Statistics
void IncrementConversationCount();
#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ public interface IRoutingService
/// <param name="message"></param>
/// <returns></returns>
Task<RoleDialogModel> InstructDirect(Agent agent, RoleDialogModel message);

Task<string> GetConversationContent(List<RoleDialogModel> dialogs, int maxDialogCount = 50);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace BotSharp.Abstraction.Routing.Models;

public class DecomposedStep
{
public string Description { get; set; }

[JsonPropertyName("total_remaining_steps")]
public int TotalRemainingSteps { get; set; }

[JsonPropertyName("should_stop")]
public bool ShouldStop { get; set; }

[JsonPropertyName("stop_reason")]
public string? StopReason { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BotSharp.Abstraction.Functions.Models;
using BotSharp.Abstraction.Routing.Models;

namespace BotSharp.Abstraction.Routing.Planning;

Expand All @@ -8,7 +9,8 @@ namespace BotSharp.Abstraction.Routing.Planning;
/// </summary>
public interface IPlaner
{
Task<FunctionCallFromLlm> GetNextInstruction(Agent router, string messageId);
Task<FunctionCallFromLlm> GetNextInstruction(Agent router, string messageId, List<RoleDialogModel> dialogs);
Task<bool> AgentExecuting(Agent router, FunctionCallFromLlm inst, RoleDialogModel message);
Task<bool> AgentExecuted(Agent router, FunctionCallFromLlm inst, RoleDialogModel message);
int MaxLoopCount => 5;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class TaskExecutionStatus
{
public const string New = "new";
public const string Running = "running";
public const string Success = "success";
public const string Failed = "failed";
}
17 changes: 17 additions & 0 deletions src/Infrastructure/BotSharp.Abstraction/Tasks/IAgentTaskService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using BotSharp.Abstraction.Repositories.Filters;
using BotSharp.Abstraction.Tasks.Models;

namespace BotSharp.Abstraction.Tasks;

public interface IAgentTaskService
{
Task<PagedItems<AgentTask>> GetTasks(AgentTaskFilter filter);

Task<AgentTask?> GetTask(string agentId, string taskId);

Task CreateTask(AgentTask task);

Task UpdateTask(AgentTask task, AgentTaskField field);

Task<bool> DeleteTask(string agentId, string taskId);
}
35 changes: 35 additions & 0 deletions src/Infrastructure/BotSharp.Abstraction/Tasks/Models/AgentTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace BotSharp.Abstraction.Tasks.Models;

public class AgentTask : AgentTaskMetaData
{
public string Id { get; set; }
public string Content { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public string AgentId { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public Agent Agent { get; set; }

public AgentTask()
{

}

public AgentTask(string id, string name, string? description = null)
{
Id = id;
Name = name;
Description = description;
}
}

public class AgentTaskMetaData
{
public string Name { get; set; }
public string? Description { get; set; }
public bool Enabled { get; set; }
public string? DirectAgentId { get; set; }
public DateTime CreatedDateTime { get; set; }
public DateTime UpdatedDateTime { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public interface IAuthenticationHook
{
Task<User> Authenticate(string id, string password);
void AddClaims(List<Claim> claims);
void BeforeSending(Token token);
}
36 changes: 29 additions & 7 deletions src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,38 @@ namespace BotSharp.Abstraction.Utilities;

public class Pagination
{
public int Page { get; set; } = 1;
/// <summary>
/// Use -1 for all records
/// </summary>
public int Size { get; set; } = 20;
public int Offset => (Page - 1) * Size;
private int _page;
private int _size;

public int Page
{
get { return _page > 0 ? _page : 1; }
set { _page = value; }
}

public int Size
{
get
{
if (_size <= 0) return 20;
if (_size > 100) return 100;

return _size;
}
set
{
_size = value;
}
}

public int Offset
{
get { return (Page - 1) * Size; }
}
}

public class PagedItems<T>
{
public int Count { get; set; }
public IEnumerable<T> Items { get; set; }
public IEnumerable<T> Items { get; set; } = new List<T>();
}
Loading