新增 JSON tool_calls 解析/序列化并替换核心执行与提示词为 JSON-only:JsonToolCallParser.cs、AIIntelligenceCore.cs 工具基类移除 XML 解析,统一 JSON 参数读取与类型转换辅助:AITool.cs 工具实现统一 JSON args/UsageSchema(含重写/修复):Tool_ModifyGoodwill.cs、Tool_SendReinforcement.cs、Tool_GetMapPawns.cs、Tool_GetMapResources.cs、Tool_GetAvailablePrefabs.cs、Tool_CallPrefabAirdrop.cs、Tool_CallBombardment.cs、Tool_GetAvailableBombardments.cs、Tool_GetPawnStatus.cs、Tool_GetRecentNotifications.cs、Tool_SearchThingDef.cs、Tool_SearchPawnKind.cs、Tool_ChangeExpression.cs、Tool_SetOverwatchMode.cs、Tool_RememberFact.cs、Tool_RecallMemories.cs、Tool_SpawnResources.cs、Tool_AnalyzeScreen.cs 轰炸相关解析统一到 JSON 字典并增强数值解析:BombardmentUtility.cs UI 对话展示改为剥离 JSON tool_calls:Overlay_WulaLink.cs、Dialog_AIConversation.cs
56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using RimWorld;
|
|
using Verse;
|
|
|
|
namespace WulaFallenEmpire.EventSystem.AI.Tools
|
|
{
|
|
public class Tool_RecallMemories : AITool
|
|
{
|
|
public override string Name => "recall_memories";
|
|
public override string Description => "Searches the AI's long-term memory for facts matching a specific query or keyword.";
|
|
public override string UsageSchema => "{\"query\":\"keywords\",\"limit\":5}";
|
|
|
|
public override string Execute(string args)
|
|
{
|
|
var argsDict = ParseJsonArgs(args);
|
|
string query = TryGetString(argsDict, "query", out string q) ? q : "";
|
|
int limit = TryGetInt(argsDict, "limit", out int parsedLimit) ? parsedLimit : 5;
|
|
|
|
var memoryManager = Find.World?.GetComponent<AIMemoryManager>();
|
|
if (memoryManager == null)
|
|
{
|
|
return "Error: AIMemoryManager world component not found.";
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(query))
|
|
{
|
|
var recent = memoryManager.GetRecentMemories(limit);
|
|
if (recent.Count == 0) return "No recent memories found.";
|
|
return FormatMemories(recent);
|
|
}
|
|
|
|
var results = memoryManager.SearchMemories(query, limit);
|
|
if (results.Count == 0)
|
|
{
|
|
return "No memories found matching the query.";
|
|
}
|
|
|
|
return FormatMemories(results);
|
|
}
|
|
|
|
private string FormatMemories(List<AIMemoryEntry> memories)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine("Found Memories:");
|
|
foreach (var m in memories)
|
|
{
|
|
sb.AppendLine($"- [{m.Category}] {m.Fact} (ID: {m.Id})");
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}
|