add routing dialogs
This commit is contained in:
parent
377c4e42c8
commit
16bea297fc
|
|
@ -4,6 +4,7 @@ public class ConversationContext
|
|||
{
|
||||
public ConversationState State { get; set; }
|
||||
public List<DialogElement> Dialogs { get; set; } = new();
|
||||
public List<RoleDialogModel> RoutingDialogs { get; set; } = new();
|
||||
public List<ConversationBreakpoint> Breakpoints { get; set; } = new();
|
||||
public int RecursiveCounter { get; set; }
|
||||
public Stack<string> RoutingStack { get; set; } = new();
|
||||
|
|
|
|||
|
|
@ -29,4 +29,8 @@ public interface IRoutingContext
|
|||
Stack<string> GetAgentStack();
|
||||
void SetAgentStack(Stack<string> stack);
|
||||
void ResetAgentStack();
|
||||
|
||||
void SetDialogs(List<RoleDialogModel> dialogs);
|
||||
List<RoleDialogModel> GetDialogs();
|
||||
void ResetDialogs();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ public class BotSharpConversationSideCar : IConversationSideCar
|
|||
{
|
||||
State = state.GetCurrentState(),
|
||||
Dialogs = dialogs ?? [],
|
||||
RoutingDialogs = routing.Context.GetDialogs(),
|
||||
Breakpoints = [],
|
||||
RecursiveCounter = routing.Context.GetRecursiveCounter(),
|
||||
RoutingStack = routing.Context.GetAgentStack()
|
||||
|
|
@ -134,6 +135,7 @@ public class BotSharpConversationSideCar : IConversationSideCar
|
|||
state.ResetCurrentState();
|
||||
routing.Context.ResetRecursiveCounter();
|
||||
routing.Context.ResetAgentStack();
|
||||
routing.Context.ResetDialogs();
|
||||
Utilities.ClearCache();
|
||||
}
|
||||
|
||||
|
|
@ -148,6 +150,7 @@ public class BotSharpConversationSideCar : IConversationSideCar
|
|||
state.SetCurrentState(node.State);
|
||||
routing.Context.SetRecursiveCounter(node.RecursiveCounter);
|
||||
routing.Context.SetAgentStack(node.RoutingStack);
|
||||
routing.Context.SetDialogs(node.RoutingDialogs);
|
||||
Utilities.ClearCache();
|
||||
enabled = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ public class RoutingContext : IRoutingContext
|
|||
private string _conversationId;
|
||||
private string _messageId;
|
||||
private int _currentRecursionDepth = 0;
|
||||
private List<RoleDialogModel> _dialogs = [];
|
||||
|
||||
public RoutingContext(IServiceProvider services, RoutingSettings setting)
|
||||
{
|
||||
|
|
@ -259,4 +260,19 @@ public class RoutingContext : IRoutingContext
|
|||
{
|
||||
_stack.Clear();
|
||||
}
|
||||
|
||||
public void SetDialogs(List<RoleDialogModel> dialogs)
|
||||
{
|
||||
_dialogs = dialogs ?? [];
|
||||
}
|
||||
|
||||
public List<RoleDialogModel> GetDialogs()
|
||||
{
|
||||
return _dialogs ?? [];
|
||||
}
|
||||
|
||||
public void ResetDialogs()
|
||||
{
|
||||
_dialogs = [];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ public partial class RoutingService
|
|||
}
|
||||
|
||||
dialogs.Add(message);
|
||||
Context.SetDialogs(dialogs);
|
||||
storage.Append(convService.ConversationId, message);
|
||||
|
||||
// Get first instruction
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ public partial class RoutingService
|
|||
message = RoleDialogModel.From(message, role: AgentRole.Assistant, content: response.Content);
|
||||
message.CurrentAgentId = agent.Id;
|
||||
dialogs.Add(message);
|
||||
Context.SetDialogs(dialogs);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -86,6 +87,7 @@ public partial class RoutingService
|
|||
dialogs.Add(RoleDialogModel.From(message,
|
||||
role: AgentRole.Assistant,
|
||||
content: responseTemplate));
|
||||
Context.SetDialogs(dialogs);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -95,6 +97,7 @@ public partial class RoutingService
|
|||
content: message.Content);
|
||||
|
||||
dialogs.Add(msg);
|
||||
Context.SetDialogs(dialogs);
|
||||
|
||||
// Send to Next LLM
|
||||
var agentId = routing.Context.GetCurrentAgentId();
|
||||
|
|
@ -106,6 +109,7 @@ public partial class RoutingService
|
|||
dialogs.Add(RoleDialogModel.From(message,
|
||||
role: AgentRole.Assistant,
|
||||
content: message.Content));
|
||||
Context.SetDialogs(dialogs);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using BotSharp.Abstraction.Routing.Models;
|
||||
using BotSharp.Abstraction.Routing.Settings;
|
||||
using BotSharp.Core.Infrastructures;
|
||||
|
||||
namespace BotSharp.Core.Routing;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
using BotSharp.Abstraction.Routing;
|
||||
|
||||
namespace BotSharp.Plugin.FileHandler.Functions;
|
||||
|
||||
public class ReadImageFn : IFunctionCallback
|
||||
|
|
@ -20,6 +22,7 @@ public class ReadImageFn : IFunctionCallback
|
|||
{
|
||||
var args = JsonSerializer.Deserialize<LlmContextIn>(message.FunctionArgs);
|
||||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
var routingCtx = _services.GetRequiredService<IRoutingContext>();
|
||||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
|
||||
Agent? fromAgent = null;
|
||||
|
|
@ -28,7 +31,7 @@ public class ReadImageFn : IFunctionCallback
|
|||
fromAgent = await agentService.LoadAgent(message.CurrentAgentId);
|
||||
}
|
||||
|
||||
var wholeDialogs = conv.GetDialogHistory();
|
||||
var wholeDialogs = routingCtx.GetDialogs();
|
||||
var dialogs = AssembleFiles(conv.ConversationId, args?.ImageUrls, wholeDialogs);
|
||||
var agent = new Agent
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue