Skip to content

Commit 3caa7a5

Browse files
committed
HFPlanner
1 parent 8bf61cb commit 3caa7a5

File tree

39 files changed

+338
-213
lines changed

39 files changed

+338
-213
lines changed

docs/architecture/hooks.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,16 @@ More information about conversation hook please go to [Conversation Hook](../con
4747
```csharp
4848
Task OnStateLoaded(ConversationState state);
4949
Task OnStateChanged(string name, string preValue, string currentValue);
50+
```
51+
52+
### Content Generating Hook
53+
`IContentGeneratingHook`
54+
55+
Model content generating hook, it can be used for logging, metrics and tracing.
56+
```csharp
57+
// Before content generating.
58+
Task BeforeGenerating(Agent agent, List<RoleDialogModel> conversations);
59+
60+
// After content generated.
61+
Task AfterGenerated(RoleDialogModel message, TokenStatsModel tokenStats);
5062
```

src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace BotSharp.Abstraction.Conversations;
33
public interface IConversationService
44
{
55
IConversationStateService States { get; }
6+
string ConversationId { get; }
67
Task<Conversation> NewConversation(Conversation conversation);
78
void SetConversationId(string conversationId, List<string> states);
89
Task<Conversation> GetConversation(string id);

src/Infrastructure/BotSharp.Abstraction/Conversations/Models/RoleDialogModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using BotSharp.Abstraction.Functions.Models;
2-
using BotSharp.Abstraction.Models;
32

43
namespace BotSharp.Abstraction.Conversations.Models;
54

65
public class RoleDialogModel : ITrackableMessage
76
{
7+
/// <summary>
8+
/// If Role is Assistant, it is same as user's message id.
9+
/// </summary>
810
public string MessageId { get; set; }
911

1012
/// <summary>

src/Infrastructure/BotSharp.Abstraction/Conversations/Models/TokenStatsModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace BotSharp.Abstraction.Conversations.Models;
33
public class TokenStatsModel
44
{
55
public string Model { get; set; }
6+
public string Prompt { get; set; }
67
public int PromptCount { get; set; }
78
public int CompletionCount { get; set; }
89

src/Infrastructure/BotSharp.Abstraction/MLTasks/ITextCompletion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ public interface ITextCompletion
1313
/// <param name="model"></param>
1414
void SetModelName(string model);
1515

16-
Task<string> GetCompletion(string text);
16+
Task<string> GetCompletion(string text, string agentId, string messageId);
1717
}

src/Infrastructure/BotSharp.Abstraction/Planning/IExecutor.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ namespace BotSharp.Abstraction.Planning;
55

66
public interface IExecutor
77
{
8-
Task<bool> Execute(IRoutingService routing,
9-
Agent router,
8+
Task<RoleDialogModel> Execute(IRoutingService routing,
109
FunctionCallFromLlm inst,
11-
List<RoleDialogModel> dialogs,
12-
RoleDialogModel message);
10+
RoleDialogModel message,
11+
List<RoleDialogModel> dialogs);
1312
}

src/Infrastructure/BotSharp.Abstraction/Planning/IPlaner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace BotSharp.Abstraction.Planning;
77
/// </summary>
88
public interface IPlaner
99
{
10-
Task<FunctionCallFromLlm> GetNextInstruction(Agent router);
10+
Task<FunctionCallFromLlm> GetNextInstruction(Agent router, string messageId);
1111
Task<bool> AgentExecuting(FunctionCallFromLlm inst, RoleDialogModel message);
1212
Task<bool> AgentExecuted(FunctionCallFromLlm inst, RoleDialogModel message);
1313
}

src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingHandler.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BotSharp.Abstraction.Functions.Models;
2-
using BotSharp.Abstraction.Planning;
32

43
namespace BotSharp.Abstraction.Routing;
54

@@ -15,9 +14,7 @@ public interface IRoutingHandler
1514
bool Enabled => true;
1615
List<ParameterPropertyDef> Parameters => new List<ParameterPropertyDef>();
1716

18-
void SetRouter(Agent router) { }
19-
20-
void SetDialogs(List<RoleDialogModel> dialogs) { }
17+
void SetDialogs(List<RoleDialogModel> dialogs);
2118

2219
Task<bool> Handle(IRoutingService routing, FunctionCallFromLlm inst, RoleDialogModel message);
2320
}

src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ namespace BotSharp.Abstraction.Routing;
22

33
public interface IRoutingService
44
{
5-
List<RoleDialogModel> Dialogs { get; }
5+
Agent Router { get; }
66
void ResetRecursiveCounter();
7-
void RefreshDialogs();
8-
Task<bool> InvokeAgent(string agentId, RoleDialogModel message);
9-
Task<bool> InstructLoop(RoleDialogModel message);
10-
Task<bool> ExecuteOnce(Agent agent, RoleDialogModel message);
7+
Task<bool> InvokeAgent(string agentId, List<RoleDialogModel> dialogs);
8+
Task<RoleDialogModel> InstructLoop(RoleDialogModel message);
9+
Task<RoleDialogModel> ExecuteOnce(Agent agent, RoleDialogModel message);
1110
}

src/Infrastructure/BotSharp.Abstraction/Routing/RoutingHandlerBase.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace BotSharp.Abstraction.Routing;
55

66
public abstract class RoutingHandlerBase
77
{
8-
protected Agent _router;
98
protected readonly IServiceProvider _services;
109
protected readonly ILogger _logger;
1110
protected RoutingSettings _settings;
@@ -20,11 +19,6 @@ public RoutingHandlerBase(IServiceProvider services,
2019
_settings = settings;
2120
}
2221

23-
public void SetRouter(Agent router)
24-
{
25-
_router = router;
26-
}
27-
2822
public void SetDialogs(List<RoleDialogModel> dialogs)
2923
{
3024
_dialogs = dialogs;

0 commit comments

Comments
 (0)