Skip to content

Commit 2b1fc99

Browse files
authored
Merge pull request #765 from hchen2020/master
Refactor reasoner and planner
2 parents c7a94b1 + 72821b2 commit 2b1fc99

File tree

34 files changed

+426
-247
lines changed

34 files changed

+426
-247
lines changed

src/Infrastructure/BotSharp.Abstraction/Routing/Planning/IExecutor.cs renamed to src/Infrastructure/BotSharp.Abstraction/Planning/IExecutor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BotSharp.Abstraction.Functions.Models;
2+
using BotSharp.Abstraction.Routing;
23

3-
namespace BotSharp.Abstraction.Routing.Planning;
4+
namespace BotSharp.Abstraction.Planning;
45

56
public interface IExecutor
67
{
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
using BotSharp.Abstraction.Functions.Models;
2+
13
namespace BotSharp.Abstraction.Planning;
24

35
/// <summary>
46
/// Planning process for Task Agent
7+
/// https://www.promptingguide.ai/techniques/cot
58
/// </summary>
6-
public class ITaskPlanner
9+
public interface ITaskPlanner
710
{
8-
11+
Task<FunctionCallFromLlm> GetNextInstruction(Agent router, string messageId, List<RoleDialogModel> dialogs);
12+
Task<bool> AgentExecuting(Agent router, FunctionCallFromLlm inst, RoleDialogModel message, List<RoleDialogModel> dialogs);
13+
Task<bool> AgentExecuted(Agent router, FunctionCallFromLlm inst, RoleDialogModel message, List<RoleDialogModel> dialogs);
14+
List<RoleDialogModel> BeforeHandleContext(FunctionCallFromLlm inst, RoleDialogModel message, List<RoleDialogModel> dialogs)
15+
=> dialogs;
16+
bool AfterHandleContext(List<RoleDialogModel> dialogs, List<RoleDialogModel> taskAgentDialogs)
17+
=> true;
18+
int MaxLoopCount => 5;
919
}

src/Infrastructure/BotSharp.Abstraction/Routing/Enums/RuleType.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public class RuleType
1212
/// </summary>
1313
public const string DataValidation = "data-validation";
1414

15+
/// <summary>
16+
/// The reasoning approach name for next step
17+
/// </summary>
18+
public const string Reasoner = "reasoner";
19+
1520
/// <summary>
1621
/// The planning approach name for next step
1722
/// </summary>

src/Infrastructure/BotSharp.Abstraction/Routing/Planning/IRoutingPlaner.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using BotSharp.Abstraction.Functions.Models;
2+
3+
namespace BotSharp.Abstraction.Routing.Reasoning;
4+
5+
/// <summary>
6+
/// Reasoning approaches for large language models (LLMs) help enhance their ability to solve complex problems,
7+
/// handle tasks requiring logic, and provide accurate and contextually appropriate responses.
8+
/// </summary>
9+
public interface IRoutingReasoner
10+
{
11+
string Name => "Unnamed Reasoner";
12+
string Description => "Each of these approaches leverages the capabilities of LLMs to reason more effectively, " +
13+
"ensuring better performance and more coherent outputs across various types of complex tasks.";
14+
15+
int MaxLoopCount => 5;
16+
17+
Task<FunctionCallFromLlm> GetNextInstruction(Agent router, string messageId, List<RoleDialogModel> dialogs);
18+
19+
Task<bool> AgentExecuting(Agent router, FunctionCallFromLlm inst, RoleDialogModel message, List<RoleDialogModel> dialogs)
20+
=> Task.FromResult(true);
21+
22+
Task<bool> AgentExecuted(Agent router, FunctionCallFromLlm inst, RoleDialogModel message, List<RoleDialogModel> dialogs)
23+
=> Task.FromResult(true);
24+
25+
List<RoleDialogModel> BeforeHandleContext(FunctionCallFromLlm inst, RoleDialogModel message, List<RoleDialogModel> dialogs)
26+
=> dialogs;
27+
28+
bool AfterHandleContext(List<RoleDialogModel> dialogs, List<RoleDialogModel> taskAgentDialogs)
29+
=> true;
30+
}

src/Infrastructure/BotSharp.Abstraction/Using.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
global using BotSharp.Abstraction.Infrastructures.Enums;
1313
global using BotSharp.Abstraction.Models;
1414
global using BotSharp.Abstraction.Routing.Models;
15-
global using BotSharp.Abstraction.Routing.Planning;
1615
global using BotSharp.Abstraction.Templating;
1716
global using BotSharp.Abstraction.Translation.Attributes;
1817
global using BotSharp.Abstraction.Messaging.Enums;

src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959

6060
<ItemGroup>
6161
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\database_knowledge.liquid" />
62+
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\reasoner.hf.liquid" />
63+
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\reasoner.naive.liquid" />
64+
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\reasoner.one-step-forward.liquid" />
65+
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\reasoner.sequential.get_remaining_task.liquid" />
66+
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\reasoner.sequential.liquid" />
6267
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\agent.json" />
6368
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\instructions\instruction.liquid" />
6469
<None Remove="data\agents\01dcc3e5-0af7-49e6-ad7a-a760bd12dc4b\agent.json" />
@@ -73,10 +78,6 @@
7378
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\instructions\instruction.liquid" />
7479
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\.welcome.liquid" />
7580
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\conversation.summary.liquid" />
76-
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\planner_prompt.hf.liquid" />
77-
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\planner_prompt.naive.liquid" />
78-
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\planner_prompt.sequential.get_remaining_task.liquid" />
79-
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\planner_prompt.sequential.liquid" />
8081
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\response_with_function.liquid" />
8182
<None Remove="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\translation_prompt.liquid" />
8283
<None Remove="data\agents\6745151e-6d46-4a02-8de4-1c4f21c7da95\templates\select_file_prompt.liquid" />
@@ -120,16 +121,19 @@
120121
<Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\database_knowledge.liquid">
121122
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
122123
</Content>
123-
<Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\planner_prompt.sequential.get_remaining_task.liquid">
124+
<Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\reasoner.sequential.get_remaining_task.liquid">
124125
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
125126
</Content>
126-
<Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\planner_prompt.sequential.liquid">
127+
<Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\reasoner.sequential.liquid">
127128
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
128129
</Content>
129-
<Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\planner_prompt.hf.liquid">
130+
<Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\reasoner.hf.liquid">
130131
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
131132
</Content>
132-
<Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\planner_prompt.naive.liquid">
133+
<Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\reasoner.naive.liquid">
134+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
135+
</Content>
136+
<Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\reasoner.one-step-forward.liquid">
133137
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
134138
</Content>
135139
<Content Include="data\agents\01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a\templates\response_with_function.liquid">

src/Infrastructure/BotSharp.Core/Conversations/ConversationPlugin.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using BotSharp.Abstraction.Google.Settings;
22
using BotSharp.Abstraction.Instructs;
33
using BotSharp.Abstraction.Messaging;
4+
using BotSharp.Abstraction.Planning;
45
using BotSharp.Abstraction.Plugins.Models;
5-
using BotSharp.Abstraction.Routing.Planning;
66
using BotSharp.Abstraction.Settings;
77
using BotSharp.Abstraction.Templating;
88
using BotSharp.Core.Instructs;
99
using BotSharp.Core.Messaging;
10-
using BotSharp.Core.Routing.Planning;
10+
using BotSharp.Core.Routing.Reasoning;
1111
using BotSharp.Core.Templating;
1212
using BotSharp.Core.Translation;
1313
using Microsoft.Extensions.Configuration;

src/Infrastructure/BotSharp.Core/Routing/Handlers/ContinueExecuteTaskRoutingHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using BotSharp.Abstraction.Repositories.Filters;
55
using BotSharp.Abstraction.Routing;
66
using BotSharp.Abstraction.Routing.Settings;
7-
using BotSharp.Core.Routing.Planning;
7+
using BotSharp.Core.Routing.Reasoning;
88

99
namespace BotSharp.Core.Routing.Handlers;
1010

@@ -27,7 +27,7 @@ public class ContinueExecuteTaskRoutingHandler : RoutingHandlerBase//, IRoutingH
2727

2828
public List<string> Planers => new List<string>
2929
{
30-
nameof(HFPlanner)
30+
nameof(HFReasoner)
3131
};
3232

3333
public ContinueExecuteTaskRoutingHandler(IServiceProvider services, ILogger<ContinueExecuteTaskRoutingHandler> logger, RoutingSettings settings)

src/Infrastructure/BotSharp.Core/Routing/Handlers/InterruptTaskExecutionRoutingHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using BotSharp.Abstraction.Functions.Models;
22
using BotSharp.Abstraction.Routing;
33
using BotSharp.Abstraction.Routing.Settings;
4-
using BotSharp.Core.Routing.Planning;
4+
using BotSharp.Core.Routing.Reasoning;
55

66
namespace BotSharp.Core.Routing.Handlers;
77

@@ -19,7 +19,7 @@ public class InterruptTaskExecutionRoutingHandler : RoutingHandlerBase//, IRouti
1919

2020
public List<string> Planers => new List<string>
2121
{
22-
nameof(HFPlanner)
22+
nameof(HFReasoner)
2323
};
2424

2525
public InterruptTaskExecutionRoutingHandler(IServiceProvider services, ILogger<InterruptTaskExecutionRoutingHandler> logger, RoutingSettings settings)

0 commit comments

Comments
 (0)