fix: attach tool-viewed media into model context
This commit is contained in:
parent
1a3235be09
commit
2b633afbb3
@ -418,6 +418,7 @@ async def execute_tool_calls(*, web_terminal, tool_calls, sender, messages, clie
|
||||
):
|
||||
img_path = inj.get("path") if isinstance(inj, dict) else None
|
||||
if img_path:
|
||||
tool_images = [img_path]
|
||||
if metadata_payload is None:
|
||||
metadata_payload = {}
|
||||
metadata_payload["tool_image_path"] = img_path
|
||||
@ -436,6 +437,7 @@ async def execute_tool_calls(*, web_terminal, tool_calls, sender, messages, clie
|
||||
):
|
||||
video_path = inj.get("path") if isinstance(inj, dict) else None
|
||||
if video_path:
|
||||
tool_videos = [video_path]
|
||||
if metadata_payload is None:
|
||||
metadata_payload = {}
|
||||
metadata_payload["tool_video_path"] = video_path
|
||||
@ -443,6 +445,17 @@ async def execute_tool_calls(*, web_terminal, tool_calls, sender, messages, clie
|
||||
'content': f'系统已记录视频路径(不再附带二进制数据): {video_path}'
|
||||
})
|
||||
|
||||
# 将工具结果即时组装为多模态消息,确保同一轮 tool loop 的下一次模型请求能真正看到图片/视频
|
||||
if tool_images or tool_videos:
|
||||
try:
|
||||
tool_message_content = web_terminal.context_manager._build_content_with_images(
|
||||
str(tool_result_content or ""),
|
||||
tool_images or [],
|
||||
tool_videos or []
|
||||
)
|
||||
except Exception:
|
||||
tool_message_content = tool_result_content
|
||||
|
||||
# 立即保存工具结果
|
||||
web_terminal.context_manager.add_conversation(
|
||||
"tool",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user