代理任务
使用 REST API 启动和管理 Copilot 云代理任务。
列出仓库的任务
注意
此端点处于公开预览阶段,可能会更改。
返回特定仓库的任务列表
“列出仓库的任务” 参数
| 名称, 类型, 描述 |
|---|
accept string建议设置为 |
| 名称, 类型, 描述 |
|---|
owner string 必填仓库的账户所有者。名称不区分大小写。 |
repo string 必填仓库的名称。名称不区分大小写。 |
| 名称, 类型, 描述 |
|---|
per_page integer每页的结果数量(最大 100)。 默认值: |
page integer要获取的结果页码。 默认值: |
sort string用于排序结果的字段。可为 默认: 可为以下之一: |
direction string排序方向。可为 默认值: 可以是以下之一: |
state string逗号分隔的任务状态过滤列表。可任意组合以下状态: |
is_archived boolean按归档状态过滤。当 默认值: |
since 字符串仅显示更新时间在此时间或之后的任务(ISO 8601 时间戳) |
creator_id integer按创建者用户 ID 过滤任务 |
“列出仓库的任务” HTTP 响应状态码
| 状态码 | 描述 |
|---|---|
200 | 成功检索任务 |
400 | 错误的请求 |
401 | 需要身份验证 |
403 | 权限不足 |
404 | 未找到资源 |
422 | 验证失败 |
“列出仓库的任务” 代码示例
请求示例
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2026-03-10" \ https://api.github.com/agents/repos/OWNER/REPO/tasks成功检索任务
状态: 200{ "tasks": [ { "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "url": "https://api.github.com/agents/repos/octocat/hello-world/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890", "html_url": "https://github.com/octocat/hello-world/copilot/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890", "name": "Fix the login button on the homepage", "creator": { "id": 1 }, "creator_type": "user", "owner": { "id": 1 }, "repository": { "id": 1296269 }, "state": "completed", "session_count": 1, "artifacts": [ { "provider": "github", "type": "pull", "data": { "id": 42 } } ], "archived_at": null, "created_at": "2025-01-01T00:00:00Z", "updated_at": "2025-01-01T01:00:00Z" } ] }创建任务
注意
此端点处于公开预览阶段,可能会更改。
为仓库创建新任务。
“创建任务” 参数
| 名称, 类型, 描述 |
|---|
accept string建议设置为 |
| 名称, 类型, 描述 |
|---|
owner string 必填仓库的账户所有者。名称不区分大小写。 |
repo string 必填仓库的名称。名称不区分大小写。 |
| 名称, 类型, 描述 |
|---|
prompt string 必需用户提供给代理的提示词 |
model string此任务使用的模型。允许的模型可能随时间变化,并取决于用户的 GitHub Copilot 计划和组织策略。目前支持的取值有: |
create_pull_request boolean是否创建拉取请求。 默认值: |
base_ref string新分支/拉取请求的基础引用 |
“创建任务” HTTP 响应状态码
| 状态码 | 描述 |
|---|---|
201 | 任务创建成功 |
400 | JSON 解析错误 |
401 | 需要身份验证 |
403 | 权限不足 |
422 | 验证失败 |
“创建任务” 代码示例
请求示例
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2026-03-10" \ https://api.github.com/agents/repos/OWNER/REPO/tasks \ -d '{"prompt":"Fix the login button on the homepage","base_ref":"main"}'任务创建成功
状态:201{ "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "url": "https://api.github.com/agents/repos/octocat/hello-world/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890", "html_url": "https://github.com/octocat/hello-world/copilot/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890", "name": "Fix the login button on the homepage", "creator": { "id": 1 }, "creator_type": "user", "owner": { "id": 1 }, "repository": { "id": 1296269 }, "state": "queued", "session_count": 1, "artifacts": [], "archived_at": null, "created_at": "2025-01-01T00:00:00Z", "updated_at": "2025-01-01T00:00:00Z" }通过仓库获取任务
注意
此端点处于公开预览阶段,可能会更改。
返回在 owner/repo 路径下通过 ID 获取的任务
“通过仓库获取任务” 参数
| 名称, 类型, 描述 |
|---|
accept string建议设置为 |
| 名称, 类型, 描述 |
|---|
owner string 必填仓库的账户所有者。名称不区分大小写。 |
repo string 必填仓库的名称。名称不区分大小写。 |
task_id string 必需任务的唯一标识符。 |
“通过仓库获取任务” HTTP 响应状态码
| 状态码 | 描述 |
|---|---|
200 | 成功检索任务 |
400 | 错误的请求 |
401 | 需要身份验证 |
403 | 权限不足 |
404 | 未找到资源 |
422 | 验证失败 |
“通过仓库获取任务” 代码示例
请求示例
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2026-03-10" \ https://api.github.com/agents/repos/OWNER/REPO/tasks/TASK_ID成功检索任务
状态: 200{ "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "url": "https://api.github.com/agents/repos/octocat/hello-world/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890", "html_url": "https://github.com/octocat/hello-world/copilot/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890", "name": "Fix the login button on the homepage", "creator": { "id": 1 }, "creator_type": "user", "owner": { "id": 1 }, "repository": { "id": 1296269 }, "state": "completed", "session_count": 1, "artifacts": [ { "provider": "github", "type": "pull", "data": { "id": 42 } } ], "archived_at": null, "created_at": "2025-01-01T00:00:00Z", "updated_at": "2025-01-01T01:00:00Z", "sessions": [ { "id": "s1a2b3c4-d5e6-7890-abcd-ef1234567890", "name": "Fix the login button on the homepage", "user": { "id": 1 }, "owner": { "id": 1 }, "repository": { "id": 1296269 }, "task_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "state": "completed", "created_at": "2025-01-01T00:00:00Z", "updated_at": "2025-01-01T01:00:00Z", "completed_at": "2025-01-01T01:00:00Z", "prompt": "Fix the login button on the homepage", "head_ref": "copilot/fix-1", "base_ref": "main", "model": "claude-sonnet-4.6" } ] }列出任务
注意
此端点处于公开预览阶段,可能会更改。
返回已认证用户的任务列表
“列出任务” 参数
| 名称, 类型, 描述 |
|---|
accept string建议设置为 |
| 名称, 类型, 描述 |
|---|
per_page integer每页的结果数量(最大 100)。 默认值: |
page integer要获取的结果页码。 默认值: |
sort string用于排序结果的字段。可为 默认: 可为以下之一: |
direction string排序方向。可为 默认值: 可以是以下之一: |
state string逗号分隔的任务状态过滤列表。可任意组合以下状态: |
is_archived boolean按归档状态过滤。当 默认值: |
since 字符串仅显示更新时间在此时间或之后的任务(ISO 8601 时间戳) |
“列出任务” HTTP 响应状态码
| 状态码 | 描述 |
|---|---|
200 | 成功检索任务 |
400 | 错误的请求 |
401 | 需要身份验证 |
403 | 权限不足 |
422 | 验证失败 |
“列出任务” 代码示例
请求示例
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2026-03-10" \ https://api.github.com/agents/tasks成功检索任务
状态: 200{ "tasks": [ { "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "name": "Fix the login button on the homepage", "creator": { "id": 1 }, "creator_type": "user", "owner": { "id": 1 }, "repository": { "id": 1296269 }, "state": "completed", "session_count": 1, "artifacts": [ { "provider": "github", "type": "pull", "data": { "id": 42 } } ], "archived_at": null, "created_at": "2025-01-01T00:00:00Z", "updated_at": "2025-01-01T01:00:00Z" } ] }通过 ID 获取任务
注意
此端点处于公开预览阶段,可能会更改。
返回通过 ID 获取的任务及其关联的会话
“通过 ID 获取任务” 参数
| 名称, 类型, 描述 |
|---|
accept string建议设置为 |
| 名称, 类型, 描述 |
|---|
task_id string 必需任务的唯一标识符。 |
“通过 ID 获取任务” HTTP 响应状态码
| 状态码 | 描述 |
|---|---|
200 | 成功检索任务 |
400 | 请求解析错误 |
401 | 需要身份验证 |
403 | 权限不足 |
404 | 未找到资源 |
422 | 验证失败 |
“通过 ID 获取任务” 代码示例
请求示例
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2026-03-10" \ https://api.github.com/agents/tasks/TASK_ID成功检索任务
状态: 200{ "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "url": "https://api.github.com/agents/repos/octocat/hello-world/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890", "html_url": "https://github.com/octocat/hello-world/copilot/tasks/a1b2c3d4-e5f6-7890-abcd-ef1234567890", "name": "Fix the login button on the homepage", "creator": { "id": 1 }, "creator_type": "user", "owner": { "id": 1 }, "repository": { "id": 1296269 }, "state": "completed", "session_count": 1, "artifacts": [ { "provider": "github", "type": "pull", "data": { "id": 42 } } ], "archived_at": null, "created_at": "2025-01-01T00:00:00Z", "updated_at": "2025-01-01T01:00:00Z", "sessions": [ { "id": "s1a2b3c4-d5e6-7890-abcd-ef1234567890", "name": "Fix the login button on the homepage", "user": { "id": 1 }, "owner": { "id": 1 }, "repository": { "id": 1296269 }, "task_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "state": "completed", "created_at": "2025-01-01T00:00:00Z", "updated_at": "2025-01-01T01:00:00Z", "completed_at": "2025-01-01T01:00:00Z", "prompt": "Fix the login button on the homepage", "head_ref": "copilot/fix-1", "base_ref": "main", "model": "claude-sonnet-4.6" } ] }