myagent-ai 1.15.46 → 1.15.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
Binary file
|
package/agents/main_agent.py
CHANGED
|
@@ -585,7 +585,24 @@ class MainAgent(BaseAgent):
|
|
|
585
585
|
response = await self._call_llm(messages)
|
|
586
586
|
|
|
587
587
|
if not response.success:
|
|
588
|
-
|
|
588
|
+
_llm_error = response.error or ""
|
|
589
|
+
logger.error(f"[{task_id}] LLM 调用失败: {_llm_error}")
|
|
590
|
+
|
|
591
|
+
# 特殊处理审查拦截 (451 censorship_blocked)
|
|
592
|
+
if "451" in _llm_error or "censorship" in _llm_error.lower() or "blocked" in _llm_error.lower():
|
|
593
|
+
_censor_msg = "抱歉,当前对话内容触发了安全审查,无法继续处理。请尝试修改您的请求内容后重试。"
|
|
594
|
+
logger.warning(f"[{task_id}] 内容审查拦截,终止当前请求")
|
|
595
|
+
context.working_memory["final_response"] = _censor_msg
|
|
596
|
+
await self._emit_v2_event("v2_reasoning", {"content": _censor_msg}, stream_callback)
|
|
597
|
+
if self.memory:
|
|
598
|
+
self.memory.add_session(
|
|
599
|
+
session_id=context.session_id,
|
|
600
|
+
role="assistant",
|
|
601
|
+
content=_censor_msg,
|
|
602
|
+
)
|
|
603
|
+
break
|
|
604
|
+
|
|
605
|
+
# 其他 LLM 错误
|
|
589
606
|
error_msg = f"LLM 调用失败: {response.error}"
|
|
590
607
|
context.working_memory["final_response"] = error_msg
|
|
591
608
|
await self._emit_v2_event("v2_reasoning", {"content": error_msg}, stream_callback)
|
|
@@ -1147,10 +1164,12 @@ class MainAgent(BaseAgent):
|
|
|
1147
1164
|
_max_output = 6000
|
|
1148
1165
|
else:
|
|
1149
1166
|
_max_output = 3000
|
|
1167
|
+
# 超时工具明确标注状态,让 LLM 清楚知道哪个工具超时了
|
|
1168
|
+
_status = "超时" if is_timeout else ('成功' if tool_result.get('success') else '失败')
|
|
1150
1169
|
tool_outputs_parts.append(
|
|
1151
1170
|
f"### {before_call}\n"
|
|
1152
1171
|
f"**工具**: {tool_name}\n"
|
|
1153
|
-
f"**结果**: {
|
|
1172
|
+
f"**结果**: {_status}\n"
|
|
1154
1173
|
f"{truncate_str(output_str, _max_output)}\n"
|
|
1155
1174
|
)
|
|
1156
1175
|
|
|
@@ -1160,7 +1179,7 @@ class MainAgent(BaseAgent):
|
|
|
1160
1179
|
))
|
|
1161
1180
|
conversation_history.append(Message(
|
|
1162
1181
|
role="user",
|
|
1163
|
-
content=f"[工具 {tool_name}
|
|
1182
|
+
content=f"[工具 {tool_name} {'超时' if is_timeout else '执行完成'}] {_status}",
|
|
1164
1183
|
))
|
|
1165
1184
|
|
|
1166
1185
|
# 保存工具调用到会话记忆
|
|
@@ -1177,13 +1196,25 @@ class MainAgent(BaseAgent):
|
|
|
1177
1196
|
self.memory.add_session(
|
|
1178
1197
|
session_id=context.session_id,
|
|
1179
1198
|
role="tool",
|
|
1180
|
-
content=f"[{tool_name}] {
|
|
1199
|
+
content=f"[{tool_name}] {_status}\n{truncate_str(output_str, 5000)}",
|
|
1181
1200
|
key="tool_result",
|
|
1182
1201
|
importance=0.4,
|
|
1183
1202
|
)
|
|
1184
1203
|
|
|
1185
|
-
# 任一工具超时 →
|
|
1204
|
+
# 任一工具超时 → 立即停止执行剩余工具
|
|
1186
1205
|
if _has_timeout:
|
|
1206
|
+
# 收集当前工具之后未执行的工具,一并写入回调数据
|
|
1207
|
+
_current_idx = parsed.tools_to_call.index(tool_info)
|
|
1208
|
+
_skipped_tools = []
|
|
1209
|
+
for _remaining in parsed.tools_to_call[_current_idx + 1:]:
|
|
1210
|
+
_rname = _remaining.get("toolname", "").strip()
|
|
1211
|
+
if _rname:
|
|
1212
|
+
_skipped_tools.append(_rname)
|
|
1213
|
+
if _skipped_tools:
|
|
1214
|
+
tool_outputs_parts.append(
|
|
1215
|
+
f"**注意**: 工具 {tool_name} 执行超时 ({timeout}s),"
|
|
1216
|
+
f"以下工具未执行: {', '.join(_skipped_tools)}"
|
|
1217
|
+
)
|
|
1187
1218
|
break
|
|
1188
1219
|
|
|
1189
1220
|
all_tool_outputs = "\n".join(tool_outputs_parts)
|