> ## 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.

# 网页搜索

## 功能说明

对应工具标识 `web_search`。

`web_search` 让智能体进行全网搜索。默认通过火山引擎融合信息搜索 API 搜索，详见[融合信息搜索 API 文档](https://www.volcengine.com/docs/85508/1650263)。当 `CLOUD_PROVIDER` 设为 `byteplus` 时，工具改用 BytePlus SearchInfinity API 搜索。

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

`parallel_web_search` 提供并行搜索能力，同样在 BytePlus 模式下使用 BytePlus SearchInfinity API。

## 环境变量与前提

<Warning>
  附加要求：

  1. 配置火山引擎 AK / SK，或使用火山引擎 IAM 授权的临时 StsToken；BytePlus 模式下改为使用 `BYTEPLUS_WEB_SEARCH_API_KEY`。
  2. 配置用于智能体推理模型的 API Key。
</Warning>

| 环境变量 | 适用模式 | 默认值 | 说明 |
| :- | :- | :- | :- |
| `MODEL_AGENT_API_KEY` | 通用 | — | 智能体推理模型的 API Key。 |
| `CLOUD_PROVIDER` | 通用 | `volcengine` | 云服务商，设为 `byteplus` 时切换到 BytePlus 搜索。 |
| `VOLCENGINE_ACCESS_KEY` | 火山引擎 | — | 火山引擎 AccessKey。 |
| `VOLCENGINE_SECRET_KEY` | 火山引擎 | — | 火山引擎 SecretKey。 |
| `BYTEPLUS_WEB_SEARCH_API_KEY` | BytePlus | — | BytePlus SearchInfinity API 的 API Key，BytePlus 模式下必填。 |
| `BYTEPLUS_WEB_SEARCH_URL` | BytePlus | 内置地址 | 覆盖 BytePlus SearchInfinity 搜索端点。 |

或在 `config.yaml` 中配置：

```yaml title="config.yaml" lines theme={null}
model:
  agent:
    provider: openai
    name: doubao-seed-2-1-pro-260628
    api_base: https://ark.cn-beijing.volces.com/api/v3/
    api_key: your-api-key-here
volcengine:
  # 供 Viking DB 与 web_search 等工具使用
  access_key: your-access-key-here
  secret_key: your-secret-key-here
```

BytePlus 模式示例：

```bash lines theme={null}
export CLOUD_PROVIDER="byteplus"
export BYTEPLUS_WEB_SEARCH_API_KEY="your-byteplus-search-api-key"
export MODEL_AGENT_API_KEY="your-model-api-key"
```

## 使用方法

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

agent = Agent(
    name="web_search_agent",
    model_name="doubao-seed-2-1-pro-260628",
    description="An agent that answers questions with web search.",
    instruction="You are a helpful assistant. Use the web_search tool when you need fresh information.",
    tools=[web_search],
)

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


async def main():
    response = await runner.run("杭州今天的天气怎么样？")
    print(response)


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