> ## Documentation Index
> Fetch the complete documentation index at: https://docs.veadk.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# 图片理解

## 功能说明

对应工具标识 `image_understand`。

`image_understand` 使用当前配置的视觉模型理解一张或多张图片，可用于描述画面内容、识别图中文字、回答与图片相关的问题。一次最多传入 8 张图片，来源支持本地路径或可公开访问的 `http(s)` URL。

该工具为异步函数（`async def`），复用智能体模型的 API Key、模型名与接口地址配置。

导入路径：`from veadk.tools.builtin_tools.image_understand import image_understand`

## 环境变量与前提

> [!WARNING]
>
> 附加要求：配置用于智能体推理模型的 API Key；所选模型需具备视觉理解能力。

环境变量：

* `MODEL_AGENT_API_KEY`：视觉请求使用的 API Key；未设置时回退到配置文件中的 `model.api_key`
* `MODEL_VISION_NAME`：可选，视觉模型名称；未设置时使用智能体模型名称
* 接口地址取配置文件中的 `model.api_base`

模型名解析顺序为：调用参数 `model_name`、环境变量 `MODEL_VISION_NAME`、智能体模型名称。

## 使用方法

```python title="examples/tools/image_understand/agent.py" lines theme={null}
import asyncio

from veadk import Agent, Runner
from veadk.memory.short_term_memory import ShortTermMemory
from veadk.tools.builtin_tools.image_understand import image_understand

agent = Agent(
    name="vision_agent",
    model_name="doubao-seed-2-1-pro-260628",
    description="An agent that understands images.",
    instruction="用户给出图片并提问时，调用 image_understand 工具理解图片。",
    tools=[image_understand],
)

runner = Runner(agent=agent, short_term_memory=ShortTermMemory())


async def main():
    response = await runner.run("描述一下 /tmp/whiteboard.jpg 里写了什么")
    print(response)


if __name__ == "__main__":
    asyncio.run(main())
```

直接调用：

```python lines theme={null}
import asyncio

from veadk.tools.builtin_tools.image_understand import image_understand


async def main():
    result = await image_understand(
        images=["/tmp/a.jpg", "https://example.com/b.png"],
        prompt="对比这两张图片的差异",
    )
    if "error" in result:
        print("理解失败:", result["error"])
    else:
        print(result["model"])
        print(result["text"])


asyncio.run(main())
```

## 参数

| 参数 | 类型 | 默认值 | 说明 |
| :- | :- | :- | :- |
| `images` | `list[str]` | 必填 | 本地图片路径或公网 `http(s)` URL 列表，1–8 项 |
| `prompt` | `str` | `"Describe the image in detail."` | 向视觉模型提出的问题或指令 |
| `model_name` | `str \| None` | — | 覆盖本次使用的视觉模型；省略时按模型名解析顺序确定 |

成功返回 `{"text": ..., "model": ...}`，`model` 为实际使用的模型名。失败时返回 `{"error": ...}`。

## 额外说明

> [!NOTE]
>
> * 本地图片单张不超过 20 MB、总体不超过 40 MB；远程 URL 在转发给模型前会经过 SSRF 校验，私网与环回地址会被拦截。
> * 远程 URL 由模型服务端拉取，链接必须可被服务端公网访问；需要鉴权或在内网才能访问的图片，应先下载到本地再传入路径。
> * 只需要逐字提取图中文字时，使用 [`ocr`](https://docs.veadk.xyz/productions/veadk/preview/zh/components/tools/ocr) 可获得更聚焦的转写结果。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.