Add ConversationEnding to IConversationHook
This commit is contained in:
parent
54255b4b13
commit
8ea6b0f814
|
|
@ -21,6 +21,9 @@ Task BeforeCompletion();
|
|||
Task OnFunctionExecuting(RoleDialogModel message);
|
||||
Task OnFunctionExecuted(RoleDialogModel message);
|
||||
Task AfterCompletion(RoleDialogModel message);
|
||||
|
||||
// LLM detected the user's intention to end the conversation
|
||||
Task ConversationEnding(RoleDialogModel conversation);
|
||||
```
|
||||
More information about conversation hook please go to [Conversation Hook](../conversation/hook.md).
|
||||
|
||||
|
|
|
|||
|
|
@ -61,4 +61,9 @@ public abstract class ConversationHookBase : IConversationHook
|
|||
_dialogs = dialogs;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual Task ConversationEnding(RoleDialogModel message)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,4 +24,6 @@ public interface IConversationHook
|
|||
Task OnFunctionExecuting(RoleDialogModel message);
|
||||
Task OnFunctionExecuted(RoleDialogModel message);
|
||||
Task AfterCompletion(RoleDialogModel message);
|
||||
|
||||
Task ConversationEnding(RoleDialogModel conversation);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,6 @@ public partial class ConversationService
|
|||
{
|
||||
public async Task CallFunctions(RoleDialogModel msg)
|
||||
{
|
||||
var hooks = _services.GetServices<IConversationHook>()
|
||||
.OrderBy(x => x.Priority)
|
||||
.ToList();
|
||||
|
||||
// Invoke functions
|
||||
var functions = _services.GetServices<IFunctionCallback>()
|
||||
.Where(x => x.Name == msg.FunctionName)
|
||||
|
|
@ -22,6 +18,10 @@ public partial class ConversationService
|
|||
return;
|
||||
}
|
||||
|
||||
var hooks = _services.GetServices<IConversationHook>()
|
||||
.OrderBy(x => x.Priority)
|
||||
.ToList();
|
||||
|
||||
foreach (var fn in functions)
|
||||
{
|
||||
// Before executing functions
|
||||
|
|
|
|||
|
|
@ -25,6 +25,16 @@ public class ConversationEndRoutingHandler : RoutingHandlerBase, IRoutingHandler
|
|||
FunctionName = inst.Function,
|
||||
ExecutionData = inst
|
||||
};
|
||||
|
||||
var hooks = _services.GetServices<IConversationHook>()
|
||||
.OrderBy(x => x.Priority)
|
||||
.ToList();
|
||||
|
||||
foreach (var hook in hooks)
|
||||
{
|
||||
await hook.OnFunctionExecuting(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,12 +29,7 @@ public class AgentController : ControllerBase, IApiAdapter
|
|||
public async Task<List<AgentViewModel>> GetAgents()
|
||||
{
|
||||
var agents = await _agentService.GetAgents();
|
||||
|
||||
// Add the router as agent
|
||||
var routing = _services.GetRequiredService<IRouterInstance>();
|
||||
agents.Insert(0, routing.Load().Router);
|
||||
|
||||
return agents.Select(x => AgentViewModel.FromAgent(x)).ToList();
|
||||
return agents.Select(x => AgentViewModel.FromAgent(x)).ToList();
|
||||
}
|
||||
|
||||
[HttpPost("/agent")]
|
||||
|
|
|
|||
Loading…
Reference in a new issue