2023-08-19 13:25:47 +00:00
|
|
|
# Hooks
|
|
|
|
|
|
|
|
|
|
`Hook` is a place in `BotSharp` that allows you to tap in to a module to either provide different behavior or to react.
|
|
|
|
|
|
|
|
|
|
## Agent Hook
|
|
|
|
|
`IAgentHook`
|
|
|
|
|
```csharp
|
2023-10-16 20:07:07 +00:00
|
|
|
// Triggered when agent is loading.
|
2023-08-19 13:25:47 +00:00
|
|
|
bool OnAgentLoading(ref string id);
|
2023-09-29 18:08:42 +00:00
|
|
|
bool OnInstructionLoaded(string template, Dictionary<string, object> dict);
|
|
|
|
|
bool OnFunctionsLoaded(List<FunctionDef> functions);
|
2023-08-19 13:25:47 +00:00
|
|
|
bool OnSamplesLoaded(ref string samples);
|
2023-10-16 20:07:07 +00:00
|
|
|
|
|
|
|
|
// Triggered when agent is loaded completely.
|
|
|
|
|
void OnAgentLoaded(Agent agent);
|
2023-08-19 13:25:47 +00:00
|
|
|
```
|
2023-09-29 18:08:42 +00:00
|
|
|
More information about agent hook please go to [Agent Hook](../agent/hook.md).
|
2023-08-19 13:25:47 +00:00
|
|
|
|
|
|
|
|
## Conversation Hook
|
|
|
|
|
`IConversationHook`
|
|
|
|
|
```csharp
|
2023-10-16 20:07:07 +00:00
|
|
|
// Triggered once for every new conversation.
|
|
|
|
|
Task OnConversationInitialized(Conversation conversation);
|
2023-08-19 13:25:47 +00:00
|
|
|
Task OnDialogsLoaded(List<RoleDialogModel> dialogs);
|
2023-10-16 20:07:07 +00:00
|
|
|
Task OnMessageReceived(RoleDialogModel message);
|
|
|
|
|
|
|
|
|
|
// Triggered before LLM calls function.
|
2023-08-19 13:25:47 +00:00
|
|
|
Task OnFunctionExecuting(RoleDialogModel message);
|
2023-10-16 20:07:07 +00:00
|
|
|
|
|
|
|
|
// Triggered when the function calling completed.
|
2023-08-19 13:25:47 +00:00
|
|
|
Task OnFunctionExecuted(RoleDialogModel message);
|
2023-10-16 20:07:07 +00:00
|
|
|
Task OnResponseGenerated(RoleDialogModel message);
|
|
|
|
|
|
|
|
|
|
// LLM detected the current task is completed.
|
2023-10-23 00:31:49 +00:00
|
|
|
Task OnCurrentTaskEnding(RoleDialogModel message);
|
2023-10-16 00:08:24 +00:00
|
|
|
|
|
|
|
|
// LLM detected the user's intention to end the conversation
|
2023-10-23 00:31:49 +00:00
|
|
|
Task OnConversationEnding(RoleDialogModel message);
|
2023-10-16 20:07:07 +00:00
|
|
|
|
|
|
|
|
// LLM can't handle user's request or user requests human being to involve.
|
2023-10-23 00:31:49 +00:00
|
|
|
Task OnHumanInterventionNeeded(RoleDialogModel message);
|
2023-08-19 13:25:47 +00:00
|
|
|
```
|
2023-09-29 18:08:42 +00:00
|
|
|
More information about conversation hook please go to [Conversation Hook](../conversation/hook.md).
|
2023-08-19 13:25:47 +00:00
|
|
|
|
|
|
|
|
### Conversation State Hook
|
|
|
|
|
`IConversationHook`
|
|
|
|
|
```csharp
|
|
|
|
|
Task OnStateLoaded(ConversationState state);
|
|
|
|
|
Task OnStateChanged(string name, string preValue, string currentValue);
|
2023-10-30 16:48:18 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Content Generating Hook
|
|
|
|
|
`IContentGeneratingHook`
|
|
|
|
|
|
|
|
|
|
Model content generating hook, it can be used for logging, metrics and tracing.
|
|
|
|
|
```csharp
|
|
|
|
|
// Before content generating.
|
|
|
|
|
Task BeforeGenerating(Agent agent, List<RoleDialogModel> conversations);
|
|
|
|
|
|
|
|
|
|
// After content generated.
|
|
|
|
|
Task AfterGenerated(RoleDialogModel message, TokenStatsModel tokenStats);
|
2023-08-19 13:25:47 +00:00
|
|
|
```
|