Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ jobs:
--exclude='docs/' \
--exclude='*.csproj' \
--exclude='*.sln' \
--exclude='.coderabbit.yaml' \
--exclude='.pre-commit-config.yaml' \
--exclude='INTRODUCTION.txt' \
--exclude='.gitignore' \
--exclude='.gitattributes' \
--exclude='*.md' \
Expand Down
70 changes: 69 additions & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,75 @@
<li>1.6</li>
<li>1.7</li>
</supportedVersions>
<description>Composite ToolCall orchestration layer. Combines atomic ToolCalls from Core into high-level actions (e.g., stabilize_rest: undraft then force_rest). Registered via reflection. [v2.0]</description>
<description>[h1]RimMind - Actions (v2.0)[/h1]
Composite ToolCall orchestration and tactical emergency execution engine for RimWorld colonists. Translates high-level AI intentions into safe, multi-step in-game operations—covering battlefield triage, autonomous blueprint construction, agricultural cycles, social interactions, and survival responses.

[b]v2.0 Clean Architecture &amp; RimWorld 1.6 / 1.7 Dual-Version Support:[/b]
[list]
[*][b]RimWorld 1.6 &amp; 1.7 (Waylith / .NET 10) Ready[/b]: Native multi-target compilation supporting both RimWorld 1.6 (.NET Framework 4.8) and RimWorld 1.7 (.NET 10 / Harmony 2.x &amp; 3.x).
[*][b]v2.0 Composite ToolCall Architecture[/b]: Combines atomic Core mechanisms into stateful, multi-stage workflows registered purely through [code]RimMind-Core[/code] public ToolCall contracts.
[*][b]Multi-Stage Job Polling &amp; Safety Gates[/b]: Continuously tracks complex jobs (such as [code]Blueprint_Build[/code] to [code]Frame[/code] delivery and construction) while enforcing strict material reserve and danger-proximity guards.
[/list]

[h2]What Is RimMind[/h2]
RimMind is an enterprise-grade, AI-powered RimWorld mod suite. Integrated with Large Language Models (LLM), it transforms colonists into self-reflecting agents with distinct personalities, three-tier memories, natural spoken dialogues, autonomous mechanisms, and dynamic storytelling.

[h2]Sub-mod List &amp; Dependency Relationships[/h2]
[table]
[tr][th]Mod[/th][th]Responsibility[/th][th]Dependencies[/th][th]GitHub[/th][/tr]
[tr][td]RimMind-Core[/td][td]LLM runtime, 4-Zone context engine, async queue, ToolCall registry &amp; F8 Hub[/td][td]Harmony[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Core]Link[/url][/td][/tr]
[tr][td][b]RimMind-Actions[/b][/td][td]Composite ToolCall mechanisms, battlefield triage &amp; autonomous construction[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Actions]Link[/url][/td][/tr]
[tr][td]RimMind-Advisor[/td][td]Colonist self-reflective advice cards, 5-domain autonomy &amp; player approval[/td][td]Core, Actions[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Advisor]Link[/url][/td][/tr]
[tr][td]RimMind-Dialogue[/td][td]Contextual spoken dialogue via express_dialogue ToolCall &amp; speech bubbles[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Dialogue]Link[/url][/td][/tr]
[tr][td]RimMind-Memory[/td][td]3-Tier cognitive memory hierarchy, work aggregation &amp; temporal decay[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Memory]Link[/url][/td][/tr]
[tr][td]RimMind-Personality[/td][td]Big-Five psychological profiles, dawn monologues &amp; dynamic mood thoughts[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Personality]Link[/url][/td][/tr]
[tr][td]RimMind-Storyteller[/td][td]AI Story Director, dramatic tension curve, chained arcs &amp; Storyteller Altar[/td][td]Core, Memory[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Storyteller]Link[/url][/td][/tr]
[tr][td]RimMind-Extension-ModelService[/td][td]Multi-provider routing, Anthropic KV cache, local gateways &amp; load balancing[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Extension-ModelService]Link[/url][/td][/tr]
[tr][td]RimMind-Bridge-RimChat[/td][td]RimChat compatibility bridge: dialogue/action mutual exclusion &amp; context sync[/td][td]Core, RimChat[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Bridge-RimChat]Link[/url][/td][/tr]
[tr][td]RimMind-Bridge-RimTalk[/td][td]RimTalk compatibility bridge: bubble harmonization &amp; bidirectional context[/td][td]Core, RimTalk[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Bridge-RimTalk]Link[/url][/td][/tr]
[/table]
[code]Core ──┬── Actions ── Advisor
├── Dialogue
├── Memory ── Storyteller
├── Personality
├── Extension-ModelService
├── Bridge-RimChat
└── Bridge-RimTalk[/code]

[h2]Core Features[/h2]
[list]
[*][b]10 Built-In Composite Mechanisms[/b] - High-level orchestrated tools covering emergency survival, construction engineering, and agricultural production.
[*][b]ContinuousJobPoller Multi-Stage Lifecycle[/b] - Tracks multi-step Verse job execution across ticks, seamlessly advancing from blueprint placement to material hauling and frame completion.
[*][b]ActionPermissionGuard &amp; ResourceSafetyGuard[/b] - Validates active spawned colonist eligibility, work-type capabilities, hostile threat proximity, and colony resource reserve thresholds before executing any job.
[*][b]Graded Risk Control[/b] - Every action carries an explicit risk classification ([i]Low / Medium / High / Critical[/i]) that integrates directly with Core's 3-Tier Autonomy and Advisor's player approval workflow.
[*][b]Main-Thread Safe Execution[/b] - Dispatches all Verse and Unity side effects safely on the main game thread.
[/list]

[h2]Composite &amp; Atomic Action Catalog[/h2]
[table]
[tr][th]Category[/th][th]Actions &amp; Mechanisms[/th][/tr]
[tr][td]Emergency &amp; Survival[/td][td]actions.stabilize_rest, actions.emergency_flee, actions.eat_and_recreation, actions.triage_patient, force_rest, eat_food, tend_pawn, rescue_pawn[/td][/tr]
[tr][td]Construction &amp; Engineering[/td][td]actions.place_blueprint, actions.plan_room_project, actions.clear_area_for_build[/td][/tr]
[tr][td]Production &amp; Agriculture[/td][td]actions.designated_harvest, actions.set_work_bill, actions.schedule_farming_cycle, assign_work, set_work_priority[/td][/tr]
[tr][td]Social &amp; Mood[/td][td]social_dining, social_relax, give_item, romance_accept, romance_breakup, inspire_work, add_thought[/td][/tr]
[tr][td]Combat &amp; Tactical[/td][td]draft, undraft, move_to, drop_weapon, cancel_job[/td][/tr]
[/table]

[h2]Risk Grading System[/h2]
[table]
[tr][th]Risk Level[/th][th]Description[/th][th]Examples[/th][/tr]
[tr][td]Low[/td][td]Easily reversible routine operations[/td][td]move_to, assign_work, cancel_job, undraft[/td][/tr]
[tr][td]Medium[/td][td]Moderate impact on survival, work, or social state[/td][td]stabilize_rest, eat_and_recreation, designated_harvest, social_dining, set_work_bill[/td][/tr]
[tr][td]High[/td][td]Resource-consuming or structural colony changes[/td][td]place_blueprint, plan_room_project, triage_patient, draft, drop_weapon[/td][/tr]
[tr][td]Critical[/td][td]Major colony-wide or irreversible impacts[/td][td]trigger_mental_state, trigger_incident[/td][/tr]
[/table]

[h2]Frequently Asked Questions[/h2]
[b]Q: Can RimMind-Actions be used standalone?[/b]
A: Actions registers composite tools into [code]RimMind-Core[/code]. Pair it with [code]RimMind-Advisor[/code] so AI colonists can autonomously propose and execute these mechanisms.

[b]Q: Will AI colonists waste scarce resources on blueprints?[/b]
A: No. [code]ResourceSafetyGuard[/code] verifies colony material reserves before placing blueprints, and high-impact actions respect your approval settings.</description>
<modDependencies>
<li>
<packageId>brrainz.harmony</packageId>
Expand Down
7 changes: 6 additions & 1 deletion Source/Actions/ActionsToolArgumentAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ private static void AdaptResourceDesignationArguments(JObject obj)
}
else if (!obj.ContainsKey("designation_type"))
{
obj["designation_type"] = isFoodOrCropTarget ? "Harvest" : "ChopWood";
obj["designation_type"] = IsHuntTarget(targetStr) ? "Hunt" : (isFoodOrCropTarget ? "Harvest" : "ChopWood");
}
}

private static bool IsHuntTarget(string target)
=> target.IndexOf("hunt", StringComparison.OrdinalIgnoreCase) >= 0
|| target.IndexOf("meat", StringComparison.OrdinalIgnoreCase) >= 0
|| target.IndexOf("animal", StringComparison.OrdinalIgnoreCase) >= 0;
}
}
46 changes: 34 additions & 12 deletions Source/Actions/AddWorktableBillCompositeTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public sealed class AddWorktableBillCompositeTool : CompositeToolCallBase
Id = Id,
Category = "action",
Description = "Adds a production bill (e.g. CookMealSimple, ButcherCorpseFlesh, Make_Apparel_Parka) to an available worktable in the colony with target count safety limits and duplicate prevention.",
ParametersSchema = "{\"type\":\"object\",\"properties\":{\"recipe_def\":{\"type\":\"string\",\"description\":\"DefName of the recipe to add (e.g. 'CookMealSimple', 'CookMealFine', 'Make_Apparel_Parka', 'ButcherCorpseFlesh').\"},\"worktable_def\":{\"type\":\"string\",\"description\":\"Optional DefName of the target worktable (e.g. 'TableStoveElectric', 'TableStoveFueled', 'HandTailoringBench', 'TableButcher'). If omitted, searches for any capable player worktable.\"},\"target_count\":{\"type\":\"integer\",\"description\":\"Target inventory stock count or repeat count (default: 10).\"},\"repeat_mode\":{\"type\":\"string\",\"description\":\"Production mode: 'TargetCount' (make until you have X, default) or 'RepeatCount' (make X times).\"},\"pawn_id\":{\"type\":\"integer\",\"description\":\"Optional colonist pawn ID to assign exclusively or anchor permission check.\"}},\"required\":[\"recipe_def\"]}"
ParametersSchema = "{\"type\":\"object\",\"properties\":{\"recipe_def\":{\"type\":\"string\",\"description\":\"DefName of the recipe to add (e.g. 'CookMealSimple', 'CookMealFine', 'Make_Apparel_Parka', 'ButcherCorpseFlesh').\"},\"worktable_def\":{\"type\":\"string\",\"description\":\"Optional DefName of the target worktable (e.g. 'FueledStove', 'ElectricStove', 'Campfire', 'HandTailoringBench', 'TableButcher'). If omitted or not present, searches for any capable player worktable.\"},\"target_count\":{\"type\":\"integer\",\"description\":\"Target inventory stock count or repeat count (default: 10).\"},\"repeat_mode\":{\"type\":\"string\",\"description\":\"Production mode: 'TargetCount' (make until you have X, default) or 'RepeatCount' (make X times).\"},\"pawn_id\":{\"type\":\"integer\",\"description\":\"Optional colonist pawn ID to assign exclusively or anchor permission check.\"}},\"required\":[\"recipe_def\"]}"
};

public override IReadOnlyList<string> RequiredToolIds => Array.Empty<string>();
Expand Down Expand Up @@ -108,12 +108,14 @@ public override Task<Result<ToolResult, RimMindError>> ExecuteAsync(
Pawn? pawn = actorResolution.Pawn;

// 2. Resolve RecipeDef
var recipeDef = DefDatabase<RecipeDef>.GetNamedSilentFail(recipeDefName.Trim());
var trimmedRecipeName = recipeDefName.Trim();
var recipeDef = DefDatabase<RecipeDef>.GetNamedSilentFail(trimmedRecipeName);
if (recipeDef == null)
{
recipeDef = DefDatabase<RecipeDef>.AllDefsListForReading
.FirstOrDefault(r => r.defName.Equals(recipeDefName.Trim(), StringComparison.OrdinalIgnoreCase)
|| r.label.Equals(recipeDefName.Trim(), StringComparison.OrdinalIgnoreCase));
.FirstOrDefault(r => r != null
&& (string.Equals(r.defName, trimmedRecipeName, StringComparison.OrdinalIgnoreCase)
|| string.Equals(r.label, trimmedRecipeName, StringComparison.OrdinalIgnoreCase)));
}

if (recipeDef == null)
Expand Down Expand Up @@ -143,21 +145,31 @@ public override Task<Result<ToolResult, RimMindError>> ExecuteAsync(

if (!string.IsNullOrWhiteSpace(worktableDefName))
{
var trimmedTableName = worktableDefName.Trim();
targetWorktable = playerWorktables.FirstOrDefault(w =>
w.def.defName.Equals(worktableDefName.Trim(), StringComparison.OrdinalIgnoreCase));
w?.def != null
&& (string.Equals(w.def.defName, trimmedTableName, StringComparison.OrdinalIgnoreCase)
|| string.Equals(w.def.label, trimmedTableName, StringComparison.OrdinalIgnoreCase)));

if (targetWorktable == null)
{
return Task.FromResult(Result<ToolResult, RimMindError>.Err(
RimMindErrors.InvalidAction(Id, $"Specified worktable '{worktableDefName}' not found or destroyed in player colony.")));
// LLMs often guess a def name that does not exist (e.g. 'TableStoveFueled').
// Prefer any capable worktable over failing outright.
targetWorktable = FindCapableWorktable(playerWorktables, recipeDef);
if (targetWorktable == null)
{
string available = playerWorktables.Count > 0
? string.Join(", ", playerWorktables.Select(w => w.def.defName).Distinct())
: "none";
return Task.FromResult(Result<ToolResult, RimMindError>.Err(
RimMindErrors.InvalidAction(Id, $"Specified worktable '{worktableDefName}' not found in player colony and no other worktable can run '{recipeDef.defName}'. Available worktables: {available}.")));
}
}
}
else
{
// Find any table that can execute this recipe
targetWorktable = playerWorktables.FirstOrDefault(w =>
(w.def.recipes != null && w.def.recipes.Contains(recipeDef))
|| (w.def.AllRecipes != null && w.def.AllRecipes.Contains(recipeDef)));
targetWorktable = FindCapableWorktable(playerWorktables, recipeDef);
}

if (targetWorktable == null)
Expand All @@ -167,7 +179,8 @@ public override Task<Result<ToolResult, RimMindError>> ExecuteAsync(
}

// 4. Ingredient & Duplicate Check
bool isCookingRecipe = recipeDef.defName.Contains("Meal") || recipeDef.defName.Contains("Cook");
bool isCookingRecipe = (recipeDef.defName?.IndexOf("Meal", StringComparison.OrdinalIgnoreCase) >= 0)
|| (recipeDef.defName?.IndexOf("Cook", StringComparison.OrdinalIgnoreCase) >= 0);
int rawNutrition = -1;
if (isCookingRecipe && targetWorktable.Map != null)
{
Expand All @@ -190,7 +203,7 @@ public override Task<Result<ToolResult, RimMindError>> ExecuteAsync(
return Task.FromResult(Result<ToolResult, RimMindError>.Err(
RimMindErrors.InvalidAction(
Id,
$"Missing raw food ingredients (0 raw food on map) for '{recipeDef.defName}' on '{targetWorktable.LabelCap}'. Call actions_designate_resources (Harvest) to gather wild food first.")));
$"Missing raw food ingredients (0 raw food on map) for '{recipeDef.defName}' on '{targetWorktable.LabelCap}'. Call actions_designate_resources with designation_type 'Hunt' (wild animals) or 'Harvest' (wild plants/crops) to gather food first.")));
}
}

Expand Down Expand Up @@ -261,6 +274,15 @@ public override Task<Result<ToolResult, RimMindError>> ExecuteAsync(
#endif
}

#if !RIMMIND_ACTIONS_TESTS
private static Building_WorkTable? FindCapableWorktable(List<Building_WorkTable> tables, RecipeDef recipeDef)
{
return tables.FirstOrDefault(w =>
(w.def.recipes != null && w.def.recipes.Contains(recipeDef))
|| (w.def.AllRecipes != null && w.def.AllRecipes.Contains(recipeDef)));
}
#endif

private static bool IsEssentialSurvivalRecipe(string? recipeDefName)
{
if (string.IsNullOrWhiteSpace(recipeDefName)) return false;
Expand Down
1 change: 1 addition & 0 deletions Source/Actions/CompositeToolCallBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private static RiskLevel MapDomainToRisk(AutonomyDomain? domain, ToolKind kind)
AutonomyDomain.ResourceMarking => RiskLevel.Low,
AutonomyDomain.WorktableBills => RiskLevel.Medium,
AutonomyDomain.BlueprintPlacement => RiskLevel.Medium,
AutonomyDomain.WorkPriorityModification => RiskLevel.Medium,
AutonomyDomain.HighRiskOperations => RiskLevel.High,
_ => RiskLevel.Medium
};
Expand Down
Loading
Loading