openclaw - 💡(How to fix) Fix 优化 Kimi web_search:实现完整的两轮对话流程 [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#50916Fetched 2026-04-08 01:06:37
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Code Example

POST https://api.moonshot.cn/v1/chat/completions
Content-Type: application/json
Authorization: Bearer <api_key>

{
  "model": "kimi-k2.5",
  "messages": [{"role": "user", "content": "查询内容"}],
  "tools": [{"type": "builtin_function", "function": {"name": "$web_search"}}]
}
RAW_BUFFERClick to expand / collapse

问题描述

当前 OpenClaw 的 Kimi web_search 实现使用单次请求,返回结果简略且不够准确。

建议改进

实现完整的两轮对话流程:

第一轮:发起搜索请求

POST https://api.moonshot.cn/v1/chat/completions
Content-Type: application/json
Authorization: Bearer <api_key>

{
  "model": "kimi-k2.5",
  "messages": [{"role": "user", "content": "查询内容"}],
  "tools": [{"type": "builtin_function", "function": {"name": "$web_search"}}]
}

返回 tool_calls,包含 search_id。

第二轮:回传凭证获取结果

将第一轮返回的 tool_calls 原封不动放回 messages,并添加 tool 角色消息。

效果对比

方式腾讯股价结果
单次请求369.00 HKD(简略)
两轮对话510 HKD(详细准确,含开盘、收盘、成交量等)

技术要点

  • Kimi API 需要 builtin_function 类型
  • 需要正确处理 reasoning_content 字段
  • 保持 tool_calls 和 tool 消息的一致性

感谢考虑这个优化!

extent analysis

Fix Plan

To improve the accuracy of the Kimi web search implementation, we need to implement a two-round conversation flow.

Step 1: First Round - Search Request

Send a POST request to the Kimi API with the search query:

import requests

api_key = "YOUR_API_KEY"
url = "https://api.moonshot.cn/v1/chat/completions"
headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {api_key}"
}
data = {
    "model": "kimi-k2.5",
    "messages": [{"role": "user", "content": "查询内容"}],
    "tools": [{"type": "builtin_function", "function": {"name": "$web_search"}}]
}

response = requests.post(url, headers=headers, json=data)

Step 2: Second Round - Get Search Results

Use the tool_calls from the first round's response and add a tool role message:

tool_calls = response.json()["tool_calls"]
data = {
    "model": "kimi-k2.5",
    "messages": tool_calls + [{"role": "tool", "content": "search_results"}],
    "tools": [{"type": "builtin_function", "function": {"name": "$web_search"}}]
}

response = requests.post(url, headers=headers, json=data)

Verification

Verify that the response from the second round contains the detailed and accurate search results.

Extra Tips

  • Make sure to handle the reasoning_content field correctly.
  • Keep the tool_calls and tool messages consistent.
  • Replace YOUR_API_KEY with your actual API key.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix 优化 Kimi web_search:实现完整的两轮对话流程 [1 participants]