Sanitize MSR analysis prompt echo

This commit is contained in:
OpenClaw Agent
2026-07-10 11:45:03 +00:00
parent e2c5c38b14
commit 6bc0aa1f71

View File

@@ -512,6 +512,58 @@ def _analysis_text_is_usable(text: str) -> bool:
return True
def _sanitize_analysis_text(text: str) -> str:
text = (text or "").strip()
if not text:
return ""
if "<think>" in text:
text = text.split("</think>")[-1].strip()
cleaned_lines = []
for raw_line in text.splitlines():
line = raw_line.strip().replace("**", "")
if not line:
continue
lower = line.lower()
if lower.startswith("the user wants"):
continue
if lower.startswith("key elements to include"):
continue
if lower.startswith("drafting the sentences"):
continue
if lower.startswith("sentence 1"):
continue
if lower.startswith("sentence 2"):
continue
if line.startswith("*"):
continue
if re.match(r"^\d+\.\s", line):
continue
cleaned_lines.append(line)
text = " ".join(cleaned_lines).strip()
text = re.sub(r"\s+", " ", text)
if not text:
return ""
sentences = re.split(r"(?<=[.!?])\s+", text)
descriptive = []
for sentence in sentences:
sentence = sentence.strip()
if not sentence:
continue
lower = sentence.lower()
if "the user wants" in lower or "key elements" in lower or "drafting the sentences" in lower:
continue
descriptive.append(sentence)
if descriptive:
return " ".join(descriptive[-2:]).strip()
return text
def _compress_analysis_image_b64(b64_payload: str, max_dim: int = 768, quality: int = 82) -> str:
"""Shrink analysis images so multimodal providers do not burn their full context on pixels."""
try:
@@ -674,8 +726,7 @@ async def analyze_character_endpoint(request):
"message": f"Could not connect to {provider} at {base_url}. Make sure the server is running and reachable.",
})
if "<think>" in generated_text:
generated_text = generated_text.split("</think>")[-1].strip()
generated_text = _sanitize_analysis_text(generated_text)
log.info("[LTXDirector] Analysis complete: %s", generated_text)
return web.json_response({"status": "success", "description": generated_text})