fix: DSML fallback — 3rd LLM call for clean synthesis + think tag stripping

Router (main.py):
- When DSML detected in 2nd LLM response after tool execution,
  make a 3rd LLM call with explicit synthesis prompt instead of
  returning raw tool results to the user
- Falls back to format_tool_calls_for_response only if 3rd call fails

Router (tool_manager.py):
- Added _strip_think_tags() helper for <think>...</think> removal
  from DeepSeek reasoning artifacts

Gateway (http_api.py):
- Strip <think>...</think> tags before sending to Telegram
- Strip DSML/XML-like markup (function_calls, invoke, parameter tags)
- Ensure empty text after stripping gets "..." fallback

Deployed to NODE1 and verified services running.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Apple
2026-02-09 10:30:37 -08:00
parent 990e594a1d
commit 7887f7cbe9
3 changed files with 53 additions and 2 deletions

View File

@@ -699,6 +699,16 @@ async def send_telegram_message(chat_id: str, text: str, bot_token: Optional[str
logger.error("TELEGRAM_BOT_TOKEN not set")
return False
# Strip <think>...</think> tags (DeepSeek reasoning leak)
import re
text = re.sub(r'<think>.*?</think>', '', text, flags=re.DOTALL)
text = re.sub(r'<think>.*$', '', text, flags=re.DOTALL) # unclosed tag
# Strip any DSML/XML-like markup
text = re.sub(r'</?(?:function_calls|invoke|parameter)[^>]*>', '', text)
text = text.strip()
if not text:
text = "..."
url = f"https://api.telegram.org/bot{token}/sendMessage"
payload = {
"chat_id": chat_id,