> ## 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_edit`。

`image_edit` 在给定原图的基础上按文本指令做图生图编辑（替换元素、改风格等）。智能体会从用户输入中提取原图与编辑要求，无需手动构造参数。它使用独立的编辑模型环境变量 `MODEL_EDIT_NAME`（**注意：与 `image_generate` 的 `MODEL_IMAGE_NAME` 不同**）。

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

## 环境变量与前提

<Warning>
  附加要求：

  1. 配置用于智能体推理模型的 API Key；
  2. 配置用于图像编辑的模型名称（`MODEL_EDIT_NAME`）。
</Warning>

环境变量：

* `MODEL_EDIT_API_KEY`：图像编辑模型的 API Key；未设置时依次回退到 `MODEL_AGENT_API_KEY` 和配置文件中的 `model.api_key`
* `MODEL_AGENT_API_KEY`：智能体推理模型的 API Key
* `MODEL_EDIT_NAME`：图像编辑模型名称
* `MODEL_EDIT_API_BASE`：图像编辑模型 API 地址，默认为火山方舟端点

<Note>
  凭证在工具执行时解析，而非导入时。导入工具模块不会触发客户端初始化，也不会要求凭证已配置。
</Note>

`config.yaml` 配置项：

```yaml title="config.yaml" lines theme={null}
model:
  edit:
    name: doubao-seededit-3-0-i2i-250628
    api_base: https://ark.cn-beijing.volces.com/api/v3/
    api_key: your-api-key-here
```

## 使用方法

```python title="examples/tools/image_edit/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_edit import image_edit

agent = Agent(
    name="image_edit_agent",
    model_name="doubao-seed-2-1-pro-260628",
    description="按指令编辑图片。",
    instruction="你是一个图片编辑专家，根据用户给定的原图与要求调用 image_edit 工具完成编辑。",
    tools=[image_edit],
)

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


async def main():
    response = await runner.run(
        "把这张图 https://example.com/cat.png 里的猫换成一只小狗"
    )
    print(response)


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