规划研究任务
估算研究任务,但不创建任务。返回实际采用的检索深度,以及成本、延迟和工作量的估算,包括是否在拟定的预算之内。
规划、创建、轮询和读取结果的完整流程,详见 运行研究任务。
1 min read
post/knowledge-fs/spaces/{knowledge_base_id}/research-tasks/plan
Request example
curl --request POST \
--url https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/research-tasks/plan \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"budgetUsd": 0.05,
"mode": "research",
"query": "What changed in the 2025 refund policy, and which regions are affected?",
"topK": 10
}'import requests
url = "https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/research-tasks/plan"
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
}
payload = {
"budgetUsd": 0.05,
"mode": "research",
"query": "What changed in the 2025 refund policy, and which regions are affected?",
"topK": 10
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.text)const response = await fetch('https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/research-tasks/plan', {
method: 'POST',
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"budgetUsd": 0.05,
"mode": "research",
"query": "What changed in the 2025 refund policy, and which regions are affected?",
"topK": 10
})
});
const data = await response.json();
console.log(data);<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/research-tasks/plan',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"budgetUsd": 0.05,
"mode": "research",
"query": "What changed in the 2025 refund policy, and which regions are affected?",
"topK": 10
}',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer <token>',
'Content-Type: application/json',
],
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
url := "https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/research-tasks/plan"
payload := strings.NewReader("{\n \"budgetUsd\": 0.05,\n \"mode\": \"research\",\n \"query\": \"What changed in the 2025 refund policy, and which regions are affected?\",\n \"topK\": 10\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/research-tasks/plan"))
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("{\n \"budgetUsd\": 0.05,\n \"mode\": \"research\",\n \"query\": \"What changed in the 2025 refund policy, and which regions are affected?\",\n \"topK\": 10\n}"))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());require 'uri'
require 'net/http'
url = URI('https://api.dify.ai/v1/knowledge-fs/spaces/{knowledge_base_id}/research-tasks/plan')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTP::Post.new(url)
request['Authorization'] = 'Bearer <token>'
request['Content-Type'] = 'application/json'
request.body = '{
"budgetUsd": 0.05,
"mode": "research",
"query": "What changed in the 2025 refund policy, and which regions are affected?",
"topK": 10
}'
response = http.request(request)
puts response.read_bodyResponse
{
"budget": {
"budget_usd": 0.05,
"exceeds_budget": false,
"remaining_budget_usd": 0.018238
},
"estimates": {
"cacheHitProbability": 0.25,
"costUsd": {
"currency": "USD",
"estimated": 0.031762,
"max": 0.042879,
"min": 0.020645
},
"inputTokens": 3070,
"latencyMs": {
"p50": 2800,
"p95": 5040
},
"outputTokens": 1776,
"retrievalSteps": 3,
"scannedResources": 620,
"toolCalls": 6,
"totalTokens": 4846,
"workBounds": {
"modelCalls": {
"estimated": 3,
"max": 4,
"min": 2
},
"openedResources": {
"estimated": 20,
"max": 40,
"min": 0
},
"retrievalSteps": {
"estimated": 3,
"max": 5,
"min": 1
}
}
},
"knowledge_space_id": "b2f1d3a4-5e6c-4a7b-8c9d-0e1f2a3b4c5d",
"query": "What changed in the 2025 refund policy, and which regions are affected?",
"retrieval_plan": {
"dense_top_k": 100,
"fts_top_k": 100,
"fusion_limit": 50,
"query_language": "latin",
"requested_mode": "research",
"rerank_candidate_limit": 50,
"resolved_mode": "research",
"strategy_version": "retrieval-planner-v2",
"top_k": 10
},
"steps": [
{
"estimatedCostUsd": 0.003126,
"estimatedInputTokens": 274,
"estimatedLatencyMs": 350,
"estimatedOutputTokens": 192,
"estimatedToolCalls": 1,
"name": "plan"
},
{
"estimatedCostUsd": 0.00124,
"estimatedInputTokens": 0,
"estimatedLatencyMs": 600,
"estimatedOutputTokens": 0,
"estimatedToolCalls": 3,
"name": "retrieve"
},
{
"estimatedCostUsd": 0.007542,
"estimatedInputTokens": 978,
"estimatedLatencyMs": 650,
"estimatedOutputTokens": 384,
"estimatedToolCalls": 1,
"name": "analyze"
},
{
"estimatedCostUsd": 0.019854,
"estimatedInputTokens": 1818,
"estimatedLatencyMs": 1200,
"estimatedOutputTokens": 1200,
"estimatedToolCalls": 1,
"name": "generate"
}
],
"strategy_version": "research-dry-run-planner-v1"
}{
"code": "knowledge_fs_invalid_request",
"message": "Agent Knowledge Base request is invalid.",
"status": 400,
"violations": [
{
"field": [
"limits"
],
"type": "extra_forbidden"
}
]
}{
"code": "knowledge_fs_invalid_request",
"failure": {
"category": "validation",
"code": "KNOWLEDGE_FS_INVALID_REQUEST",
"message": "The Agent Knowledge Base request is invalid.",
"retryPolicy": "never",
"traceId": "d44c6dd1-da9c-46e7-81e1-5f09707c4352"
},
"message": "The Agent Knowledge Base request is invalid.",
"status": 400
}{
"code": "knowledge_fs_invalid_credential",
"message": "Invalid Agent Knowledge Base service credential.",
"status": 401
}{
"code": "unauthorized",
"message": "Access token is invalid",
"status": 401
}{
"code": "forbidden",
"message": "Sorry, you have reached the knowledge base request rate limit of your subscription.",
"status": 403
}{
"code": "knowledge_fs_access_denied",
"message": "Agent Knowledge Base operation is not allowed.",
"status": 403
}{
"code": "knowledge_fs_resource_not_found",
"failure": {
"category": "not_found",
"code": "KNOWLEDGE_FS_NOT_FOUND",
"message": "The requested Agent Knowledge Base resource was not found.",
"retryPolicy": "never",
"traceId": "8f3a2c14-9d6b-4c07-b5a1-2e7d0c93f5b2"
},
"message": "The requested Agent Knowledge Base resource was not found.",
"status": 404
}{
"code": "not_found",
"message": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
"status": 404
}{
"code": "knowledge_fs_request_too_large",
"message": "Agent Knowledge Base request is too large.",
"status": 413
}{
"code": "knowledge_fs_upstream_unavailable",
"failure": {
"action": "contact_admin",
"category": "internal",
"code": "KNOWLEDGE_FS_INTERNAL_ERROR",
"message": "Agent Knowledge Base could not complete the operation. Try again, or contact an administrator with the error reference.",
"retryPolicy": "manual",
"traceId": "5e2a9c17-3b4d-4f60-8a1b-2c3d4e5f6a7b"
},
"message": "Agent Knowledge Base could not complete the operation. Try again, or contact an administrator with the error reference.",
"status": 502
}{
"code": "knowledge_fs_upstream_unavailable",
"message": "Agent Knowledge Base is unavailable.",
"status": 502
}{
"code": "knowledge_fs_operation_unavailable",
"message": "Agent Knowledge Base operation is not available.",
"status": 503
}{
"code": "knowledge_fs_operation_unavailable",
"failure": {
"action": "retry",
"category": "dependency",
"code": "KNOWLEDGE_FS_UNAVAILABLE",
"message": "A service required by Agent Knowledge Base is temporarily unavailable.",
"retryPolicy": "manual",
"traceId": "5e2a9c17-3b4d-4f60-8a1b-2c3d4e5f6a7b"
},
"message": "A service required by Agent Knowledge Base is temporarily unavailable.",
"status": 503
}post/knowledge-fs/spaces/{knowledge_base_id}/research-tasks/plan
Authorization
Path parameters
知识库 ID:即知识库 API 访问 对话框中所示服务 API 端点的最后一段(
…/knowledge-fs/spaces/<knowledge base ID>),也是地址栏中 /datasets/new/ 之后的那一段。Body
application/json用于与成本估算比较的花费上限(USD)。决定响应中的
budget.exceeds_budget 和 budget.remaining_budget_usd。Range: >= 0
Options:
fastdeepresearchnull检索结果合并并重排序后最多保留的分段数。显式传入的值必须在 1~50 之间。省略时使用知识库已发布的 Top K 设置,该设置最高可达 100。值越大,模型获得的上下文越多,干扰也越多;值越小,结果越集中,但可能漏掉相关分段。
Range: 1–50
Responses
application/json
规划结果及其估算。
成本估算与请求中
budgetUsd 的比较结果。任务的工作量、成本和延迟估算。可与你打算发送给 创建研究任务 的
limits 对比。Show child attributesHide child attributes
预计由缓存提供的检索比例,取值范围为
0 到 1。任务的估算成本。
所有步骤预计消耗的模型输入 token 数。
预计的端到端耗时,单位为毫秒。可根据
p50 安排首次轮询 获取研究任务 的时间。所有步骤预计产生的模型输出 token 数。
预计的检索轮数。对照
limits.maxRetrievalSteps 检查。预计读取的文档和章节数。对照
limits.maxScannedResources 检查。预计的工具调用次数。对照
limits.maxToolCalls 检查。inputTokens 与 outputTokens 之和。点估计值背后的范围。创建研究任务 检查的是点估计值,不检查这些范围。
Show child attributesHide child attributes
模型调用次数的估计值、最小值和最大值。
打开的文档和章节数的估计值、最小值和最大值。
知识库的内部 ID,并非路径中的知识库 ID。
去除首尾空白后的问题。
检索将如何执行。
Show child attributesHide child attributes
从向量检索中选取的候选数。
从关键词检索中选取的候选数。
合并向量检索和关键词检索结果后保留的候选数。
检测到的问题语言:
cjk、latin、mixed-cjk-latin 或 other。请求中的
mode;省略时为知识库的默认深度。取值为 fast、deep 或 research。传给重排序模型的候选数。
生成此规划所用检索策略的版本。
检索结果合并并重排序后最多保留的分段数。
各步骤的估算,按执行顺序排列。
Show child attributesHide child attributes
估算器的版本。