跳至主要内容
REST API 现在已启用版本控制。 更多信息请参见“关于 API 版本控制”。

代理任务

使用 REST API 启动和管理 Copilot 云代理任务。

列出仓库的任务

注意

此端点处于公开预览阶段,可能会更改。

返回特定仓库的任务列表

“列出仓库的任务” 参数

标头 (Headers)
名称, 类型, 描述
accept string

建议设置为 application/vnd.github+json

路径参数
名称, 类型, 描述
owner string 必填

仓库的账户所有者。名称不区分大小写。

repo string 必填

仓库的名称。名称不区分大小写。

查询参数
名称, 类型, 描述
per_page integer

每页的结果数量(最大 100)。

默认值:30

page integer

要获取的结果页码。

默认值:1

sort string

用于排序结果的字段。可为 updated_atcreated_at

默认: updated_at

可为以下之一: updated_at, created_at

direction string

排序方向。可为 ascdesc

默认值:desc

可以是以下之一:asc, desc

state string

逗号分隔的任务状态过滤列表。可任意组合以下状态: queued(排队中),in_progress(进行中),completed(已完成),failed(失败),idle(空闲),waiting_for_user(等待用户),timed_out(超时),cancelled(已取消)。

is_archived boolean

按归档状态过滤。当 true 时,只返回已归档的任务。false 或省略时,只返回未归档的任务。默认值为 false

默认值:false

since 字符串

仅显示更新时间在此时间或之后的任务(ISO 8601 时间戳)

creator_id integer

按创建者用户 ID 过滤任务

“列出仓库的任务” HTTP 响应状态码

状态码描述
200

成功检索任务

400

错误的请求

401

需要身份验证

403

权限不足

404

未找到资源

422

验证失败

“列出仓库的任务” 代码示例

请求示例

get/agents/repos/{owner}/{repo}/tasks
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" } ] }

创建任务

注意

此端点处于公开预览阶段,可能会更改。

为仓库创建新任务。

“创建任务” 参数

标头 (Headers)
名称, 类型, 描述
accept string

建议设置为 application/vnd.github+json

路径参数
名称, 类型, 描述
owner string 必填

仓库的账户所有者。名称不区分大小写。

repo string 必填

仓库的名称。名称不区分大小写。

正文参数 (Body parameters)
名称, 类型, 描述
prompt string 必需

用户提供给代理的提示词

model string

此任务使用的模型。允许的模型可能随时间变化,并取决于用户的 GitHub Copilot 计划和组织策略。目前支持的取值有: claude-sonnet-4.6claude-opus-4.6gpt-5.2-codexgpt-5.3-codexgpt-5.4claude-sonnet-4.5claude-opus-4.5

create_pull_request boolean

是否创建拉取请求。

默认值:false

base_ref string

新分支/拉取请求的基础引用

“创建任务” HTTP 响应状态码

状态码描述
201

任务创建成功

400

JSON 解析错误

401

需要身份验证

403

权限不足

422

验证失败

“创建任务” 代码示例

请求示例

post/agents/repos/{owner}/{repo}/tasks
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 获取的任务

“通过仓库获取任务” 参数

标头 (Headers)
名称, 类型, 描述
accept string

建议设置为 application/vnd.github+json

路径参数
名称, 类型, 描述
owner string 必填

仓库的账户所有者。名称不区分大小写。

repo string 必填

仓库的名称。名称不区分大小写。

task_id string 必需

任务的唯一标识符。

“通过仓库获取任务” HTTP 响应状态码

状态码描述
200

成功检索任务

400

错误的请求

401

需要身份验证

403

权限不足

404

未找到资源

422

验证失败

“通过仓库获取任务” 代码示例

请求示例

get/agents/repos/{owner}/{repo}/tasks/{task_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/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" } ] }

列出任务

注意

此端点处于公开预览阶段,可能会更改。

返回已认证用户的任务列表

“列出任务” 参数

标头 (Headers)
名称, 类型, 描述
accept string

建议设置为 application/vnd.github+json

查询参数
名称, 类型, 描述
per_page integer

每页的结果数量(最大 100)。

默认值:30

page integer

要获取的结果页码。

默认值:1

sort string

用于排序结果的字段。可为 updated_atcreated_at

默认: updated_at

可为以下之一: updated_at, created_at

direction string

排序方向。可为 ascdesc

默认值:desc

可以是以下之一:asc, desc

state string

逗号分隔的任务状态过滤列表。可任意组合以下状态: queued(排队中),in_progress(进行中),completed(已完成),failed(失败),idle(空闲),waiting_for_user(等待用户),timed_out(超时),cancelled(已取消)。

is_archived boolean

按归档状态过滤。当 true 时,只返回已归档的任务。false 或省略时,只返回未归档的任务。默认值为 false

默认值:false

since 字符串

仅显示更新时间在此时间或之后的任务(ISO 8601 时间戳)

“列出任务” HTTP 响应状态码

状态码描述
200

成功检索任务

400

错误的请求

401

需要身份验证

403

权限不足

422

验证失败

“列出任务” 代码示例

请求示例

get/agents/tasks
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 获取任务” 参数

标头 (Headers)
名称, 类型, 描述
accept string

建议设置为 application/vnd.github+json

路径参数
名称, 类型, 描述
task_id string 必需

任务的唯一标识符。

“通过 ID 获取任务” HTTP 响应状态码

状态码描述
200

成功检索任务

400

请求解析错误

401

需要身份验证

403

权限不足

404

未找到资源

422

验证失败

“通过 ID 获取任务” 代码示例

请求示例

get/agents/tasks/{task_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" } ] }
© . This site is unofficial and not affiliated with GitHub, Inc.