Skip to content

Commit 8d3c4df

Browse files
github: add agent tasks API support
1 parent a5eca73 commit 8d3c4df

8 files changed

Lines changed: 1661 additions & 0 deletions

github/agent_tasks.go

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
// Copyright 2026 The go-github AUTHORS. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style
4+
// license that can be found in the LICENSE file.
5+
6+
package github
7+
8+
import (
9+
"context"
10+
"encoding/json"
11+
"fmt"
12+
"time"
13+
)
14+
15+
// AgentTasksService handles communication with the agent tasks
16+
// methods of the GitHub API.
17+
//
18+
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10
19+
type AgentTasksService service
20+
21+
// AgentTask represents a Copilot cloud agent task.
22+
type AgentTask struct {
23+
ID *string `json:"id,omitempty"`
24+
URL *string `json:"url,omitempty"`
25+
HTMLURL *string `json:"html_url,omitempty"`
26+
Name *string `json:"name,omitempty"`
27+
Creator *User `json:"creator,omitempty"`
28+
CreatorType *string `json:"creator_type,omitempty"`
29+
Owner *User `json:"owner,omitempty"`
30+
Repository *Repository `json:"repository,omitempty"`
31+
State *string `json:"state,omitempty"`
32+
SessionCount *int `json:"session_count,omitempty"`
33+
Artifacts []*AgentTaskArtifact `json:"artifacts,omitempty"`
34+
ArchivedAt *Timestamp `json:"archived_at,omitempty"`
35+
CreatedAt *Timestamp `json:"created_at,omitempty"`
36+
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
37+
Sessions []*AgentTaskSession `json:"sessions,omitempty"`
38+
}
39+
40+
// AgentTaskArtifact represents an artifact produced by an agent task.
41+
type AgentTaskArtifact struct {
42+
Provider *string `json:"provider,omitempty"`
43+
Type *string `json:"type,omitempty"`
44+
Data json.RawMessage `json:"data,omitempty"`
45+
}
46+
47+
// AgentTaskSession represents a session associated with an agent task.
48+
type AgentTaskSession struct {
49+
ID *string `json:"id,omitempty"`
50+
Name *string `json:"name,omitempty"`
51+
User *User `json:"user,omitempty"`
52+
Owner *User `json:"owner,omitempty"`
53+
Repository *Repository `json:"repository,omitempty"`
54+
TaskID *string `json:"task_id,omitempty"`
55+
State *string `json:"state,omitempty"`
56+
CreatedAt *Timestamp `json:"created_at,omitempty"`
57+
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
58+
CompletedAt *Timestamp `json:"completed_at,omitempty"`
59+
Prompt *string `json:"prompt,omitempty"`
60+
HeadRef *string `json:"head_ref,omitempty"`
61+
BaseRef *string `json:"base_ref,omitempty"`
62+
Model *string `json:"model,omitempty"`
63+
}
64+
65+
// AgentTaskList represents a list of agent tasks.
66+
type AgentTaskList struct {
67+
Tasks []*AgentTask `json:"tasks,omitempty"`
68+
}
69+
70+
// AgentTaskListOptions specifies optional parameters to AgentTasksService.List.
71+
type AgentTaskListOptions struct {
72+
// Sort specifies the field to sort results by. Possible values are: updated_at, created_at.
73+
Sort string `url:"sort,omitempty"`
74+
75+
// Direction specifies the direction to sort results by. Possible values are: asc, desc.
76+
Direction string `url:"direction,omitempty"`
77+
78+
// State is a comma-separated list of task states to filter by.
79+
State string `url:"state,omitempty"`
80+
81+
// IsArchived filters tasks by archived status.
82+
IsArchived bool `url:"is_archived,omitempty"`
83+
84+
// Since filters tasks updated at or after this time.
85+
Since *time.Time `url:"since,omitempty"`
86+
87+
ListOptions
88+
}
89+
90+
// AgentTaskListByRepoOptions specifies optional parameters to AgentTasksService.ListByRepo.
91+
type AgentTaskListByRepoOptions struct {
92+
AgentTaskListOptions
93+
94+
// CreatorID filters tasks by creator user ID.
95+
CreatorID int64 `url:"creator_id,omitempty"`
96+
}
97+
98+
// CreateAgentTaskOptions represents the parameters for creating an agent task.
99+
type CreateAgentTaskOptions struct {
100+
// Prompt is the user's prompt for the agent.
101+
Prompt string `json:"prompt"`
102+
103+
// Model is the model to use for this task.
104+
Model *string `json:"model,omitempty"`
105+
106+
// CreatePullRequest indicates whether to create a pull request.
107+
CreatePullRequest *bool `json:"create_pull_request,omitempty"`
108+
109+
// BaseRef is the base ref for the new branch or pull request.
110+
BaseRef *string `json:"base_ref,omitempty"`
111+
}
112+
113+
// ListByRepo lists tasks for a repository.
114+
//
115+
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#list-tasks-for-repository
116+
//
117+
//meta:operation GET /agents/repos/{owner}/{repo}/tasks
118+
func (s *AgentTasksService) ListByRepo(ctx context.Context, owner, repo string, opts *AgentTaskListByRepoOptions) (*AgentTaskList, *Response, error) {
119+
u := fmt.Sprintf("agents/repos/%v/%v/tasks", owner, repo)
120+
u, err := addOptions(u, opts)
121+
if err != nil {
122+
return nil, nil, err
123+
}
124+
125+
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))
126+
if err != nil {
127+
return nil, nil, err
128+
}
129+
130+
var tasks *AgentTaskList
131+
resp, err := s.client.Do(req, &tasks)
132+
if err != nil {
133+
return nil, resp, err
134+
}
135+
136+
return tasks, resp, nil
137+
}
138+
139+
// Create starts a new Copilot cloud agent task for a repository.
140+
//
141+
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#start-a-task
142+
//
143+
//meta:operation POST /agents/repos/{owner}/{repo}/tasks
144+
func (s *AgentTasksService) Create(ctx context.Context, owner, repo string, opts *CreateAgentTaskOptions) (*AgentTask, *Response, error) {
145+
u := fmt.Sprintf("agents/repos/%v/%v/tasks", owner, repo)
146+
147+
req, err := s.client.NewRequest(ctx, "POST", u, opts, WithVersion("2026-03-10"))
148+
if err != nil {
149+
return nil, nil, err
150+
}
151+
152+
var task *AgentTask
153+
resp, err := s.client.Do(req, &task)
154+
if err != nil {
155+
return nil, resp, err
156+
}
157+
158+
return task, resp, nil
159+
}
160+
161+
// GetByRepo gets a repository task by ID.
162+
//
163+
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#get-a-task-by-repo
164+
//
165+
//meta:operation GET /agents/repos/{owner}/{repo}/tasks/{task_id}
166+
func (s *AgentTasksService) GetByRepo(ctx context.Context, owner, repo, taskID string) (*AgentTask, *Response, error) {
167+
u := fmt.Sprintf("agents/repos/%v/%v/tasks/%v", owner, repo, taskID)
168+
169+
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))
170+
if err != nil {
171+
return nil, nil, err
172+
}
173+
174+
var task *AgentTask
175+
resp, err := s.client.Do(req, &task)
176+
if err != nil {
177+
return nil, resp, err
178+
}
179+
180+
return task, resp, nil
181+
}
182+
183+
// List lists tasks for the authenticated user.
184+
//
185+
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#list-tasks
186+
//
187+
//meta:operation GET /agents/tasks
188+
func (s *AgentTasksService) List(ctx context.Context, opts *AgentTaskListOptions) (*AgentTaskList, *Response, error) {
189+
u := "agents/tasks"
190+
u, err := addOptions(u, opts)
191+
if err != nil {
192+
return nil, nil, err
193+
}
194+
195+
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))
196+
if err != nil {
197+
return nil, nil, err
198+
}
199+
200+
var tasks *AgentTaskList
201+
resp, err := s.client.Do(req, &tasks)
202+
if err != nil {
203+
return nil, resp, err
204+
}
205+
206+
return tasks, resp, nil
207+
}
208+
209+
// Get gets a task by ID for the authenticated user.
210+
//
211+
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#get-a-task-by-id
212+
//
213+
//meta:operation GET /agents/tasks/{task_id}
214+
func (s *AgentTasksService) Get(ctx context.Context, taskID string) (*AgentTask, *Response, error) {
215+
u := fmt.Sprintf("agents/tasks/%v", taskID)
216+
217+
req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))
218+
if err != nil {
219+
return nil, nil, err
220+
}
221+
222+
var task *AgentTask
223+
resp, err := s.client.Do(req, &task)
224+
if err != nil {
225+
return nil, resp, err
226+
}
227+
228+
return task, resp, nil
229+
}

0 commit comments

Comments
 (0)