Skip to content

Commit 8ea6b0f

Browse files
committed
Add ConversationEnding to IConversationHook
1 parent 54255b4 commit 8ea6b0f

6 files changed

Lines changed: 25 additions & 10 deletions

File tree

‎docs/architecture/hooks.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Task BeforeCompletion();
2121
Task OnFunctionExecuting(RoleDialogModel message);
2222
Task OnFunctionExecuted(RoleDialogModel message);
2323
Task AfterCompletion(RoleDialogModel message);
24+
25+
// LLM detected the user's intention to end the conversation
26+
Task ConversationEnding(RoleDialogModel conversation);
2427
```
2528
More information about conversation hook please go to [Conversation Hook](../conversation/hook.md).
2629

‎src/Infrastructure/BotSharp.Abstraction/Conversations/ConversationHookBase.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ public virtual Task OnDialogsLoaded(List<RoleDialogModel> dialogs)
6161
_dialogs = dialogs;
6262
return Task.CompletedTask;
6363
}
64+
65+
public virtual Task ConversationEnding(RoleDialogModel message)
66+
{
67+
return Task.CompletedTask;
68+
}
6469
}

‎src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationHook.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ public interface IConversationHook
2424
Task OnFunctionExecuting(RoleDialogModel message);
2525
Task OnFunctionExecuted(RoleDialogModel message);
2626
Task AfterCompletion(RoleDialogModel message);
27+
28+
Task ConversationEnding(RoleDialogModel conversation);
2729
}

‎src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.CallFunctions.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ public partial class ConversationService
66
{
77
public async Task CallFunctions(RoleDialogModel msg)
88
{
9-
var hooks = _services.GetServices<IConversationHook>()
10-
.OrderBy(x => x.Priority)
11-
.ToList();
12-
139
// Invoke functions
1410
var functions = _services.GetServices<IFunctionCallback>()
1511
.Where(x => x.Name == msg.FunctionName)
@@ -22,6 +18,10 @@ public async Task CallFunctions(RoleDialogModel msg)
2218
return;
2319
}
2420

21+
var hooks = _services.GetServices<IConversationHook>()
22+
.OrderBy(x => x.Priority)
23+
.ToList();
24+
2525
foreach (var fn in functions)
2626
{
2727
// Before executing functions

‎src/Infrastructure/BotSharp.Core/Routing/Handlers/ConversationEndRoutingHandler.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ public async Task<RoleDialogModel> Handle(IRoutingService routing, FunctionCallF
2525
FunctionName = inst.Function,
2626
ExecutionData = inst
2727
};
28+
29+
var hooks = _services.GetServices<IConversationHook>()
30+
.OrderBy(x => x.Priority)
31+
.ToList();
32+
33+
foreach (var hook in hooks)
34+
{
35+
await hook.OnFunctionExecuting(result);
36+
}
37+
2838
return result;
2939
}
3040
}

‎src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ public async Task<AgentViewModel> GetAgent([FromRoute] string id)
2929
public async Task<List<AgentViewModel>> GetAgents()
3030
{
3131
var agents = await _agentService.GetAgents();
32-
33-
// Add the router as agent
34-
var routing = _services.GetRequiredService<IRouterInstance>();
35-
agents.Insert(0, routing.Load().Router);
36-
37-
return agents.Select(x => AgentViewModel.FromAgent(x)).ToList();
32+
return agents.Select(x => AgentViewModel.FromAgent(x)).ToList();
3833
}
3934

4035
[HttpPost("/agent")]

0 commit comments

Comments
 (0)