注意
代理任务 API 处于 公开预览 且可能会发生更改。
您可以使用代理任务 API 将 云代理 集成到您自己的工具和工作流中。 例如,可以启动新任务、列出现有任务或检查任务的状态。
有关完整的 API 参考,请参阅 代理任务的 REST API 终结点。
Authentication
代理任务 API 仅支持用户到服务器令牌。 可以使用 personal access token、OAuth app 或用户到服务器令牌 GitHub App 进行身份验证。
不支持服务器到服务器令牌,例如 GitHub App 安装访问令牌。
通过 API 启动任务
要启动新云代理任务,请发送POST请求至/agents/repos/{owner}/{repo}/tasks。 唯一必需的参数是 prompt,这是代理的提示。
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer YOUR-TOKEN" \
https://api.github.com/agents/repos/OWNER/REPO/tasks \
-d '{
"prompt": "Fix the login button on the homepage",
"base_ref": "main"
}'
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer YOUR-TOKEN" \
https://api.github.com/agents/repos/OWNER/REPO/tasks \
-d '{
"prompt": "Fix the login button on the homepage",
"base_ref": "main"
}'
替换以下占位符值:
YOUR-TOKEN:personal access token 或者 GitHub App 用户到服务器令牌。OWNER:存储库的帐户所有者。REPO:存储库的名称。
还可以在请求正文中包含以下可选参数:
base_ref:新分支和拉取请求的基分支。model:用于任务的 AI 模型。 如果省略,将使用 自动模型选择。 有关支持模型的详细信息,请参阅 代理任务的 REST API 终结点。create_pull_request:一个布尔值,用于确定是否为任务创建拉取请求。
列出任务
可以列出特定存储库或有权访问的所有存储库的任务。
列出特定存储库的任务:
curl -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ -H "Authorization: Bearer YOUR-TOKEN" \ https://api.github.com/agents/repos/OWNER/REPO/tasks
curl -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer YOUR-TOKEN" \
https://api.github.com/agents/repos/OWNER/REPO/tasks
要列出所有存储库中的任务,请执行以下步骤:
curl -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ -H "Authorization: Bearer YOUR-TOKEN" \ https://api.github.com/agents/tasks
curl -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer YOUR-TOKEN" \
https://api.github.com/agents/tasks
检查任务的状态
若要检查特定任务的状态,请使用任务 ID 发送请求 GET :
curl -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ -H "Authorization: Bearer YOUR-TOKEN" \ https://api.github.com/agents/repos/OWNER/REPO/tasks/TASK-ID
curl -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Authorization: Bearer YOUR-TOKEN" \
https://api.github.com/agents/repos/OWNER/REPO/tasks/TASK-ID
将 TASK-ID 替换为您要检查的任务的 ID。 创建任务或列表任务时,可以从响应中获取此 ID。 响应包括任务的当前state,可以是queued、in_progress、completed、failed、idle、waiting_for_user、timed_out或cancelled之一。