Skip to content

Commit c47bd4e

Browse files
committed
fix(prompts): memory instruction now reaches native tool-calling roles (4.12.1)
AiToolContractPromptFormatter appended the positive memory-usage guidance AFTER the supportsNativeToolCalling early-return, so native tool-calling roles whose base prompt never mentions memory (e.g. Creator) received no memory instruction at all and ignored "remember the ..." tasks — leaving persistence to whether the model happened to infer it. Move the memory-tool detection and a strengthened imperative ahead of the early-return so both native and text-shaped paths get it (gated on the role actually having the memory tool). Validated by the live MultiAgentCraftingWorkflowPlayModeTests run: Creator now reliably persists the design summary (previously empty -> test failed). Adds DeterministicToolContractEditModeTests coverage (native+memory includes the imperative; native without memory omits it). Lockstep bump coreai + coreaiunity to 4.12.1.
1 parent 494531a commit c47bd4e

6 files changed

Lines changed: 75 additions & 10 deletions

File tree

Assets/CoreAI/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
## [Unreleased]
44

5+
## 4.12.1 - 2026-06-28
6+
7+
- **fix(prompts): memory-usage instruction now reaches native tool-calling roles.** In
8+
`AiToolContractPromptFormatter`, the positive memory guidance ("when asked to remember/save/record,
9+
call the memory tool") lived *after* the `supportsNativeToolCalling` early-return, so native
10+
tool-calling roles whose base prompt never mentions memory (e.g. Creator) received **no** memory
11+
instruction at all and silently ignored "remember the …" tasks — leaving it to the model to infer.
12+
The detection + a strengthened imperative now run ahead of the early-return, so both the native and
13+
text-shaped paths get it (gated on the role actually having the `memory` tool). Tests:
14+
`DeterministicToolContractEditModeTests` (native+memory includes the imperative; native without memory
15+
omits it).
16+
517
## 4.12.0 - 2026-06-28
618

719
- **Lua mod versioning (`manage_mods versions` / `revert`).** Mod load/reload now records a revision per

Assets/CoreAI/Runtime/Core/Features/Orchestration/AiToolContractPromptFormatter.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,8 @@ public static string AppendToolContract(
4444
sb.AppendLine(extra);
4545
}
4646

47-
if (supportsNativeToolCalling)
48-
{
49-
AppendForcedToolInstruction(sb, task);
50-
return sb.ToString();
51-
}
52-
53-
bool hasMemoryTool = false;
5447
IReadOnlyList<ILlmTool> canonicalTools = AiToolOrder.Canonical(tools);
48+
bool hasMemoryTool = false;
5549
foreach (ILlmTool tool in canonicalTools)
5650
{
5751
if (tool != null &&
@@ -62,6 +56,24 @@ public static string AppendToolContract(
6256
}
6357
}
6458

59+
// Positive memory trigger — applies to BOTH native and text-shaped tool-calling. Without it a role
60+
// whose base prompt never mentions memory (e.g. Creator) silently ignores "remember the ..." because
61+
// nothing maps that soft verb to the memory tool. This guidance previously lived only AFTER the
62+
// native early-return below, so native tool-calling roles received no memory instruction at all.
63+
if (hasMemoryTool)
64+
{
65+
sb.AppendLine(
66+
"Memory: when the task asks you to remember, save, note, record, or persist something, you MUST " +
67+
"call the memory tool (action \"append\" or \"store\") to persist it before answering — prose or " +
68+
"reasoning alone never saves anything.");
69+
}
70+
71+
if (supportsNativeToolCalling)
72+
{
73+
AppendForcedToolInstruction(sb, task);
74+
return sb.ToString();
75+
}
76+
6577
if (hasMemoryTool)
6678
{
6779
sb.AppendLine(

Assets/CoreAI/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.neoxider.coreai",
3-
"version": "4.12.0",
3+
"version": "4.12.1",
44
"displayName": "CoreAI",
55
"unity": "6000.0",
66
"description": "Portable C# core for CoreAI — LLM agents that call your game code. Orchestration, function-calling tools, agent memory, AgentBuilder, SkillSet, and production resilience (retries, timeouts, rate limits), with no UnityEngine dependency. LLM and Lua are optional modules (COREAI_NO_LLM / COREAI_NO_LUA), so the core compiles without them — install only what your game uses. Unity integration ships in com.neoxider.coreaiunity.",

Assets/CoreAiUnity/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ Unity host: **CoreAI.Source** build, EditMode / PlayMode tests, Editor menus, do
44

55
## [Unreleased]
66

7+
## 4.12.1 - 2026-06-28
8+
9+
Depends on **`com.neoxider.coreai` 4.12.1** (native-role memory-instruction fix).
10+
11+
- **fix(prompts): native tool-calling roles with the memory tool now get the memory instruction.**
12+
See the Core 4.12.1 entry — the guidance was gated behind the native early-return in
13+
`AiToolContractPromptFormatter`, so a role like Creator ignored "remember the …" tasks. Validated by the
14+
live multi-agent crafting workflow (`MultiAgentCraftingWorkflowPlayModeTests`): Creator now reliably
15+
persists the design summary. Lockstep version bump.
16+
717
## 4.12.0 - 2026-06-28
818

919
Depends on **`com.neoxider.coreai` 4.12.0** (Lua mod versioning + runtime handler-error diagnostics).

Assets/CoreAiUnity/Tests/EditMode/DeterministicToolContractEditModeTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,37 @@ public async Task BuildRequest_FixedInputs_ProduceIdenticalSystemPrefixWithoutGe
8686
AssertNoGuidOrTimestamp(first);
8787
}
8888

89+
[Test]
90+
public void AppendToolContract_NativeToolCallingWithMemoryTool_IncludesMemoryImperative()
91+
{
92+
// Regression: the memory instruction used to live only on the text-shaped path, after the
93+
// native early-return, so native tool-calling roles (e.g. Creator) got no memory guidance and
94+
// ignored "remember the ..." tasks.
95+
string native = AiToolContractPromptFormatter.AppendToolContract(
96+
"sys",
97+
new[] { new StubTool("memory") },
98+
new AiTaskRequest { RoleId = "Creator" },
99+
new TestSettings(),
100+
supportsNativeToolCalling: true);
101+
102+
StringAssert.Contains("call the memory tool", native,
103+
"Native tool-calling roles with the memory tool must receive the positive memory instruction.");
104+
}
105+
106+
[Test]
107+
public void AppendToolContract_NativeToolCallingWithoutMemoryTool_OmitsMemoryImperative()
108+
{
109+
string native = AiToolContractPromptFormatter.AppendToolContract(
110+
"sys",
111+
new[] { new StubTool("world_command") },
112+
new AiTaskRequest { RoleId = "Creator" },
113+
new TestSettings(),
114+
supportsNativeToolCalling: true);
115+
116+
StringAssert.DoesNotContain("call the memory tool", native,
117+
"Roles without the memory tool must not receive memory guidance.");
118+
}
119+
89120
private static AgentMemoryPolicy BuildPolicy(params ILlmTool[] tools)
90121
{
91122
AgentMemoryPolicy policy = new();

Assets/CoreAiUnity/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.neoxider.coreaiunity",
3-
"version": "4.12.0",
3+
"version": "4.12.1",
44
"displayName": "CoreAI Unity",
55
"unity": "6000.0",
66
"description": "Unity framework for LLM-powered NPCs and agents that call your game code — drop-in chat UI, function-calling tools, persistent memory, token-by-token streaming, and per-role LLM routing. Runs on a local GGUF model (via LLMUnity) or any OpenAI-compatible API; proven on a 4 GB local model. Unity layer for com.neoxider.coreai.",
@@ -9,6 +9,6 @@
99
"url": "https://github.com/NeoXider/CoreAI"
1010
},
1111
"dependencies": {
12-
"com.neoxider.coreai": "4.12.0"
12+
"com.neoxider.coreai": "4.12.1"
1313
}
1414
}

0 commit comments

Comments
 (0)