Ship Assistent 0.11.8: remember session params, slim /debug ask, generate only for real frames.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+42
-22
@@ -18,6 +18,9 @@ public partial class SwarmAssistentExtension
|
||||
const int MaxCivitaiHopsFallback = 2;
|
||||
const int MaxToolHopsFallback = 4;
|
||||
|
||||
static bool IsSlimDebugPack(string packName) =>
|
||||
string.Equals(packName, "debug_explain", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
(List<JObject> messages, JObject systemLayers) BuildOllamaMessages(string packName, bool includeBase, string contextJson, JArray userMessages, string extraSystem = null, string personaId = null, IEnumerable<string> skillIds = null)
|
||||
{
|
||||
List<JObject> ollamaMessages = [];
|
||||
@@ -45,7 +48,9 @@ public partial class SwarmAssistentExtension
|
||||
AddLayer("core", Config.LoadCorePrompt(pid));
|
||||
}
|
||||
|
||||
if (Memory is not null)
|
||||
bool slimDebug = IsSlimDebugPack(packName);
|
||||
|
||||
if (Memory is not null && !slimDebug)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -72,23 +77,25 @@ public partial class SwarmAssistentExtension
|
||||
+ exact.ToString(Newtonsoft.Json.Formatting.None) + "\n```");
|
||||
}
|
||||
|
||||
StringBuilder skillsBlock = new();
|
||||
foreach (string skillId in skillIds ?? Config.ResolveEnabledSkills(pid, null))
|
||||
if (!slimDebug)
|
||||
{
|
||||
string skillText = Config.LoadSkillPrompt(pid, skillId);
|
||||
if (!string.IsNullOrWhiteSpace(skillText))
|
||||
StringBuilder skillsBlock = new();
|
||||
foreach (string skillId in skillIds ?? Config.ResolveEnabledSkills(pid, null))
|
||||
{
|
||||
if (skillsBlock.Length > 0)
|
||||
string skillText = Config.LoadSkillPrompt(pid, skillId);
|
||||
if (!string.IsNullOrWhiteSpace(skillText))
|
||||
{
|
||||
skillsBlock.AppendLine();
|
||||
if (skillsBlock.Length > 0)
|
||||
{
|
||||
skillsBlock.AppendLine();
|
||||
}
|
||||
skillsBlock.AppendLine($"## Skill: {skillId}");
|
||||
skillsBlock.AppendLine(skillText.TrimEnd());
|
||||
}
|
||||
skillsBlock.AppendLine($"## Skill: {skillId}");
|
||||
skillsBlock.AppendLine(skillText.TrimEnd());
|
||||
}
|
||||
AddLayer("skills", skillsBlock.ToString());
|
||||
AddLayer("identity", Config.RenderIdentityBlock(pid));
|
||||
}
|
||||
AddLayer("skills", skillsBlock.ToString());
|
||||
|
||||
AddLayer("identity", Config.RenderIdentityBlock(pid));
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(packName))
|
||||
{
|
||||
@@ -169,20 +176,27 @@ public partial class SwarmAssistentExtension
|
||||
Logs.Debug($"Assistent memory seed: {ex.Message}");
|
||||
}
|
||||
|
||||
string retrieveQuery = BuildRetrieveQuery(userMessages, contextJson, packName);
|
||||
bool slimDebug = IsSlimDebugPack(packName);
|
||||
JArray hits = [];
|
||||
try
|
||||
if (!slimDebug)
|
||||
{
|
||||
AssistentMemory.RetrieveOptions opt = MemoryRetrieveOptions(pid);
|
||||
hits = await Memory.RetrieveAsync(root, retrieveQuery, opt.TopK, embed, Config.PersonaExtendsChain(pid), opt);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Debug($"Assistent memory retrieve: {ex.Message}");
|
||||
string retrieveQuery = BuildRetrieveQuery(userMessages, contextJson, packName);
|
||||
try
|
||||
{
|
||||
AssistentMemory.RetrieveOptions opt = MemoryRetrieveOptions(pid);
|
||||
hits = await Memory.RetrieveAsync(root, retrieveQuery, opt.TopK, embed, Config.PersonaExtendsChain(pid), opt);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.Debug($"Assistent memory retrieve: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
string enrichedContext = InjectMemoryHits(contextJson, hits);
|
||||
enrichedContext = EnrichPersonaContext(enrichedContext, pid, packName);
|
||||
if (!slimDebug)
|
||||
{
|
||||
enrichedContext = EnrichPersonaContext(enrichedContext, pid, packName);
|
||||
}
|
||||
(List<JObject> messages, JObject systemLayers) = BuildOllamaMessages(packName, includeBase, enrichedContext, userMessages, personaId: pid, skillIds: skills);
|
||||
int systemChars = systemLayers["total"]?.Value<int?>()
|
||||
?? messages.FirstOrDefault(m => string.Equals(m["role"]?.ToString(), "system", StringComparison.OrdinalIgnoreCase))?["content"]?.ToString()?.Length
|
||||
@@ -190,7 +204,9 @@ public partial class SwarmAssistentExtension
|
||||
JArray civitaiResults = [];
|
||||
string reply = "";
|
||||
JObject lastRaw = null;
|
||||
int maxHops = Math.Max(CfgInt("max_civitai_hops", MaxCivitaiHopsFallback), CfgInt("max_tool_hops", MaxToolHopsFallback));
|
||||
int maxHops = slimDebug
|
||||
? 1
|
||||
: Math.Max(CfgInt("max_civitai_hops", MaxCivitaiHopsFallback), CfgInt("max_tool_hops", MaxToolHopsFallback));
|
||||
HashSet<string> hopDone = new(StringComparer.OrdinalIgnoreCase);
|
||||
var chain = Config.PersonaExtendsChain(pid);
|
||||
for (int hop = 0; hop < maxHops; hop++)
|
||||
@@ -200,6 +216,10 @@ public partial class SwarmAssistentExtension
|
||||
await onHopStart(hop);
|
||||
}
|
||||
(reply, lastRaw) = await CallOllamaChat(root, modelName, messages, stream: onDelta is not null, onDelta, pid);
|
||||
if (slimDebug)
|
||||
{
|
||||
break;
|
||||
}
|
||||
JObject patch = TryParsePatch(reply);
|
||||
await ApplyMemoryActions(root, patch, embed, pid);
|
||||
ApplyUserPrefActions(patch, pid);
|
||||
|
||||
Reference in New Issue
Block a user