|
11 | 11 | from astrbot.core.agent.handoff import HandoffTool |
12 | 12 | from astrbot.core.agent.mcp_client import MCPTool |
13 | 13 | from astrbot.core.agent.message import Message |
| 14 | +from astrbot.core.message.components import Image |
14 | 15 | from astrbot.core.agent.run_context import ContextWrapper |
15 | 16 | from astrbot.core.agent.tool import FunctionTool, ToolSet |
16 | 17 | from astrbot.core.agent.tool_executor import BaseFunctionToolExecutor |
@@ -165,6 +166,23 @@ async def _execute_handoff( |
165 | 166 | ): |
166 | 167 | input_ = tool_args.get("input") |
167 | 168 | image_urls = tool_args.get("image_urls") |
| 169 | + if image_urls is None: |
| 170 | + image_urls = [] |
| 171 | + elif isinstance(image_urls, str): |
| 172 | + image_urls = [image_urls] |
| 173 | + |
| 174 | + # 获取当前事件中的图片 |
| 175 | + event = run_context.context.event |
| 176 | + if event.message_obj and event.message_obj.message: |
| 177 | + for component in event.message_obj.message: |
| 178 | + if isinstance(component, Image): |
| 179 | + try: |
| 180 | + # 调用组件的 convert_to_file_path 异步方法 |
| 181 | + path = await component.convert_to_file_path() |
| 182 | + if path and path not in image_urls: |
| 183 | + image_urls.append(path) |
| 184 | + except Exception as e: |
| 185 | + logger.error(f"转换图片失败: {e}") |
168 | 186 |
|
169 | 187 | # Build handoff toolset from registered tools plus runtime computer tools. |
170 | 188 | toolset = cls._build_handoff_toolset(run_context, tool.agent.tools) |
|
0 commit comments