Merge pull request #96 from hchen2020/master

Support agent switch based on state.
This commit is contained in:
Haiping 2023-08-10 13:53:46 -05:00 committed by GitHub
commit 692f6b76fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

View file

@ -41,7 +41,7 @@ public abstract class ConversationCompletionHookBase : IConversationCompletionHo
return this;
}
public virtual Task OnStateLoaded(ConversationState state)
public virtual Task OnStateLoaded(ConversationState state, Action<Agent, string>? onAgentSwitched = null)
{
return Task.CompletedTask;
}

View file

@ -17,7 +17,7 @@ public interface IConversationCompletionHook
IChatCompletion ChatCompletion { get; }
IConversationCompletionHook SetChatCompletion(IChatCompletion chatCompletion);
Task OnStateLoaded(ConversationState state);
Task OnStateLoaded(ConversationState state, Action<Agent, string>? onAgentSwitched = null);
Task BeforeCompletion();
Task OnFunctionExecuting(string name, string args);
Task AfterCompletion(RoleDialogModel message);

View file

@ -149,7 +149,11 @@ public class ConversationService : IConversationService
.SetDialogs(wholeDialogs)
.SetChatCompletion(chatCompletion);
await hook.OnStateLoaded(state);
await hook.OnStateLoaded(state, onAgentSwitched: (x, prompt) =>
{
agent = x;
wholeDialogs.Add(new RoleDialogModel("user", prompt));
});
await hook.BeforeCompletion();
}