This commit is contained in:
Mikan
2026-06-21 07:52:25 +03:00
parent e98559a587
commit 7cbe8da103
25 changed files with 1091 additions and 284 deletions

View File

@@ -341,13 +341,26 @@ async def _run_tool_loop(
"tokens": (resp.get("prompt_tokens") or 0) + (resp.get("completion_tokens") or 0),
})
msg = resp.get("message", {})
# Apply text replacements to content
content = msg.get("content", "") or ""
if content:
from app.core.settings_service import apply_text_replacements
content = await apply_text_replacements(db, content)
msg = dict(msg)
msg["content"] = content
tool_calls = msg.get("tool_calls") or []
if not tool_calls:
# No tool calls — append assistant message and ask again
# No tool calls — append assistant message and retry with a nudge.
# Up to 3 retries.
messages.append({"role": "assistant", "content": msg.get("content", "")})
messages.append({
"role": "user",
"content": f"You must call a tool. Available terminal tool: {terminal_tool}. If you are done with your work, call {terminal_tool} now.",
"content": (
f"You did not call any tools in your previous response. "
f"You MUST use the available tools to accomplish the task. "
f"If you tried to call a tool but it didn't work, try again with proper JSON arguments. "
f"When you are done, call {terminal_tool}."
),
})
continue