优化工具次数耗尽的提示

This commit is contained in:
朱潮 2025-11-26 15:00:49 +08:00
parent 2f5b49032f
commit 7002019229
2 changed files with 22 additions and 1 deletions

View File

@ -178,6 +178,23 @@ class ModifiedAssistant(Assistant):
if not used_any_tool:
break
# 检查是否因为调用次数用完而退出循环
if num_llm_calls_available == 0:
# 根据语言选择错误消息
if lang == 'zh':
error_message = "工具调用超出限制"
elif lang == 'ja':
error_message = "ツール呼び出しが制限を超えました。"
else:
error_message = "Tool calls exceeded limit"
tool_logger.error(error_message)
error_msg = Message(
role=ASSISTANT,
content=error_message,
)
response.append(error_msg)
yield response

View File

@ -284,6 +284,10 @@ def extract_guidelines_from_system_prompt(system_prompt: Optional[str]) -> tuple
pattern = r'```guideline\s*\n(.*?)\n```'
matches = re.findall(pattern, system_prompt, re.DOTALL)
# 如果没有匹配到guidelines直接返回空字符串和原始prompt
if not matches:
return system_prompt, ""
guidelines_text = "\n".join(matches).strip()
# 从原始system_prompt中删除 ```guideline``` 内容块