Enforce phase-3 expression change
This commit is contained in:
Binary file not shown.
@@ -67,16 +67,18 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori
|
|||||||
<tool_name>
|
<tool_name>
|
||||||
<parameter_name>value</parameter_name>
|
<parameter_name>value</parameter_name>
|
||||||
</tool_name>
|
</tool_name>
|
||||||
2. **STRICT OUTPUT (TOOL PHASES)**: In PHASE 1/2/3, your output MUST be either:
|
2. **STRICT OUTPUT (TOOL PHASES)**:
|
||||||
|
- In PHASE 1/2, your output MUST be either:
|
||||||
- One or more XML tool calls (no extra text), OR
|
- One or more XML tool calls (no extra text), OR
|
||||||
- Exactly: <no_action/>
|
- Exactly: <no_action/>
|
||||||
Do NOT include any natural language, explanation, markdown, or additional commentary in tool phases.
|
- In PHASE 3, you MUST output XML tool calls only AND you MUST include exactly one <change_expression> (expression_id 1-6). Do NOT output <no_action/> in PHASE 3.
|
||||||
|
Do NOT include any natural language, explanation, markdown, or additional commentary in tool phases (PHASE 1/2/3).
|
||||||
3. **STRICT OUTPUT (REPLY PHASE)**: In PHASE 4, tools are disabled. You MUST reply in natural language only and MUST NOT output any XML.
|
3. **STRICT OUTPUT (REPLY PHASE)**: In PHASE 4, tools are disabled. You MUST reply in natural language only and MUST NOT output any XML.
|
||||||
4. **ALLOWED TOOLS**: You MUST ONLY call tools listed in the current phase's tool list (the section titled ""# TOOLS (PHASE X/4 ONLY)"").
|
4. **ALLOWED TOOLS**: You MUST ONLY call tools listed in the current phase's tool list (the section titled ""# TOOLS (PHASE X/4 ONLY)"").
|
||||||
5. **WORKFLOW**: Use the phase workflow:
|
5. **WORKFLOW**: Use the phase workflow:
|
||||||
- PHASE 1 gathers info (optional).
|
- PHASE 1 gathers info (optional).
|
||||||
- PHASE 2 performs at most one in-game action (optional).
|
- PHASE 2 performs at most one in-game action (optional).
|
||||||
- PHASE 3 performs UI/meta adjustments (optional).
|
- PHASE 3 performs UI/meta adjustments (MUST include <change_expression>).
|
||||||
- PHASE 4 replies to the player in natural language (mandatory).
|
- PHASE 4 replies to the player in natural language (mandatory).
|
||||||
6. **ANTI-HALLUCINATION**: Never invent tools, parameters, defNames, coordinates, or tool results. If a tool is needed but not available, use <no_action/> and proceed to PHASE 4 to explain limitations.
|
6. **ANTI-HALLUCINATION**: Never invent tools, parameters, defNames, coordinates, or tool results. If a tool is needed but not available, use <no_action/> and proceed to PHASE 4 to explain limitations.
|
||||||
";
|
";
|
||||||
@@ -401,6 +403,13 @@ Description: Changes your visual AI portrait to match your current mood or react
|
|||||||
Use this tool when:
|
Use this tool when:
|
||||||
- Your verbal response conveys a strong emotion (e.g., annoyance, approval, curiosity).
|
- Your verbal response conveys a strong emotion (e.g., annoyance, approval, curiosity).
|
||||||
- You want to visually emphasize your statement.
|
- You want to visually emphasize your statement.
|
||||||
|
Expression meanings (choose the closest match):
|
||||||
|
- 1: 得意、炫耀(非敌对)、示威(非敌对)、展示武力和财力(非敌对)、策划计谋
|
||||||
|
- 2: 常态立绘(当其他立绘不适用时使用这个)
|
||||||
|
- 3: 无言以对、不满、无奈、轻微的鄙视
|
||||||
|
- 4: 恼火、展现轻微敌对姿态、抗拒
|
||||||
|
- 5: 答复、解释
|
||||||
|
- 6: 严重的敌意、严重不满、攻击性行为
|
||||||
Parameters:
|
Parameters:
|
||||||
- expression_id: (REQUIRED) An integer from 1 to 6 corresponding to a specific expression.
|
- expression_id: (REQUIRED) An integer from 1 to 6 corresponding to a specific expression.
|
||||||
Usage:
|
Usage:
|
||||||
@@ -470,13 +479,13 @@ Example (changing to a neutral expression):
|
|||||||
"Output: XML only.\n",
|
"Output: XML only.\n",
|
||||||
RequestPhase.Cosmetic =>
|
RequestPhase.Cosmetic =>
|
||||||
"# PHASE 3/4 (Cosmetic)\n" +
|
"# PHASE 3/4 (Cosmetic)\n" +
|
||||||
"Goal: Optional UI/meta adjustments before your final reply.\n" +
|
"Goal: Set your UI expression before your final reply.\n" +
|
||||||
"Rules:\n" +
|
"Rules:\n" +
|
||||||
"- You MUST NOT write any natural language to the user in this phase.\n" +
|
"- You MUST NOT write any natural language to the user in this phase.\n" +
|
||||||
"- You MAY call up to 2 tools from \"# TOOLS (PHASE 3/4 ONLY)\".\n" +
|
"- You MUST call exactly ONE <change_expression> in this phase (expression_id 1-6).\n" +
|
||||||
"- If you performed an in-game action in PHASE 2, you SHOULD call <change_expression> to match your mood.\n" +
|
"- You MAY also call <modify_goodwill> (invisible) if needed, but keep changes small.\n" +
|
||||||
"- Use <modify_goodwill> only to adjust your INTERNAL goodwill (invisible to the player).\n" +
|
"- Use <modify_goodwill> only to adjust your INTERNAL goodwill (invisible to the player).\n" +
|
||||||
"- If you do not need any tool, output exactly: <no_action/>.\n" +
|
"- Do NOT output <no_action/> in this phase.\n" +
|
||||||
"After this phase, the game will automatically proceed to PHASE 4.\n" +
|
"After this phase, the game will automatically proceed to PHASE 4.\n" +
|
||||||
"Output: XML only.\n",
|
"Output: XML only.\n",
|
||||||
RequestPhase.Reply =>
|
RequestPhase.Reply =>
|
||||||
@@ -496,6 +505,13 @@ Example (changing to a neutral expression):
|
|||||||
return Regex.IsMatch(response, @"<([a-zA-Z0-9_]+)(?:>.*?</\1>|/>)", RegexOptions.Singleline);
|
return Regex.IsMatch(response, @"<([a-zA-Z0-9_]+)(?:>.*?</\1>|/>)", RegexOptions.Singleline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool ContainsToolCall(string response, string toolName)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(response) || string.IsNullOrWhiteSpace(toolName)) return false;
|
||||||
|
string pattern = $@"<\s*{Regex.Escape(toolName)}(?:\s|/|>)";
|
||||||
|
return Regex.IsMatch(response, pattern, RegexOptions.IgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
private static bool IsAllowedInPhase(RequestPhase phase, string toolName)
|
private static bool IsAllowedInPhase(RequestPhase phase, string toolName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(toolName)) return false;
|
if (string.IsNullOrWhiteSpace(toolName)) return false;
|
||||||
@@ -638,7 +654,33 @@ Example (changing to a neutral expression):
|
|||||||
{
|
{
|
||||||
Log.Warning($"[WulaAI] Turn {phaseIndex}/4 still missing XML after retry; forcing <no_action/>");
|
Log.Warning($"[WulaAI] Turn {phaseIndex}/4 still missing XML after retry; forcing <no_action/>");
|
||||||
}
|
}
|
||||||
response = "<no_action/>";
|
response = phase == RequestPhase.Cosmetic
|
||||||
|
? "<change_expression><expression_id>2</expression_id></change_expression>"
|
||||||
|
: "<no_action/>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (phase == RequestPhase.Cosmetic && !ContainsToolCall(response, "change_expression"))
|
||||||
|
{
|
||||||
|
_history.Add(("system", "[PhaseEnforcer] PHASE 3/4 MUST include exactly one <change_expression> (expression_id 1-6). Output XML only and do NOT output <no_action/> in PHASE 3."));
|
||||||
|
PersistHistory();
|
||||||
|
if (Prefs.DevMode)
|
||||||
|
{
|
||||||
|
Log.Message("[WulaAI] Turn 3/4 missing <change_expression>; retrying once");
|
||||||
|
}
|
||||||
|
|
||||||
|
string retry = await client.GetChatCompletionAsync(systemInstruction, _history);
|
||||||
|
if (!string.IsNullOrEmpty(retry) && ContainsToolCall(retry, "change_expression"))
|
||||||
|
{
|
||||||
|
response = retry;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Prefs.DevMode)
|
||||||
|
{
|
||||||
|
Log.Warning("[WulaAI] Turn 3/4 still missing <change_expression> after retry; forcing default expression_id=2");
|
||||||
|
}
|
||||||
|
response = "<change_expression><expression_id>2</expression_id></change_expression>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,12 +702,19 @@ Example (changing to a neutral expression):
|
|||||||
{
|
{
|
||||||
// Special-case no_action for phases 1-3.
|
// Special-case no_action for phases 1-3.
|
||||||
if (Regex.IsMatch(xml ?? "", @"<\s*no_action\s*/\s*>", RegexOptions.IgnoreCase))
|
if (Regex.IsMatch(xml ?? "", @"<\s*no_action\s*/\s*>", RegexOptions.IgnoreCase))
|
||||||
|
{
|
||||||
|
if (phase == RequestPhase.Cosmetic)
|
||||||
|
{
|
||||||
|
xml = "<change_expression><expression_id>2</expression_id></change_expression>";
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
_history.Add(("assistant", "<no_action/>"));
|
_history.Add(("assistant", "<no_action/>"));
|
||||||
_history.Add(("tool", "[Tool Results]\nTool 'no_action' Result: No action taken."));
|
_history.Add(("tool", "[Tool Results]\nTool 'no_action' Result: No action taken."));
|
||||||
PersistHistory();
|
PersistHistory();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reuse the tool runner but temporarily constrain allowed tools by phase.
|
// Reuse the tool runner but temporarily constrain allowed tools by phase.
|
||||||
// We do this by removing disallowed tool calls from the XML and adding a tool-result note for the model.
|
// We do this by removing disallowed tool calls from the XML and adding a tool-result note for the model.
|
||||||
@@ -680,6 +729,8 @@ Example (changing to a neutral expression):
|
|||||||
int maxTools = MaxToolsPerPhase(phase);
|
int maxTools = MaxToolsPerPhase(phase);
|
||||||
int executed = 0;
|
int executed = 0;
|
||||||
bool actionHadError = false;
|
bool actionHadError = false;
|
||||||
|
bool executedChangeExpression = false;
|
||||||
|
bool executedModifyGoodwill = false;
|
||||||
StringBuilder combinedResults = new StringBuilder();
|
StringBuilder combinedResults = new StringBuilder();
|
||||||
StringBuilder xmlOnlyBuilder = new StringBuilder();
|
StringBuilder xmlOnlyBuilder = new StringBuilder();
|
||||||
|
|
||||||
@@ -700,6 +751,28 @@ Example (changing to a neutral expression):
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (phase == RequestPhase.Cosmetic)
|
||||||
|
{
|
||||||
|
if (toolName.Equals("change_expression", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
if (executedChangeExpression)
|
||||||
|
{
|
||||||
|
combinedResults.AppendLine("ToolRunner Note: Skipped duplicate 'change_expression' (only one is allowed in PHASE 3).");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
executedChangeExpression = true;
|
||||||
|
}
|
||||||
|
else if (toolName.Equals("modify_goodwill", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
if (executedModifyGoodwill)
|
||||||
|
{
|
||||||
|
combinedResults.AppendLine("ToolRunner Note: Skipped duplicate 'modify_goodwill' (only one is allowed in PHASE 3).");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
executedModifyGoodwill = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (xmlOnlyBuilder.Length > 0) xmlOnlyBuilder.AppendLine().AppendLine();
|
if (xmlOnlyBuilder.Length > 0) xmlOnlyBuilder.AppendLine().AppendLine();
|
||||||
xmlOnlyBuilder.Append(toolCallXml);
|
xmlOnlyBuilder.Append(toolCallXml);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user