-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: Add agent tasks API support #4225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
8d3c4df
efa12d7
4263d58
43387ee
3c4d321
93e009c
738801b
ceabbf4
f8042ad
a2f45a2
5160bbf
ab0cc87
d10a780
a982cae
41b1ac1
dc0817a
8e1ed64
96ff69b
d40f10b
526dbeb
ca7b94c
f60454c
38fdd45
127e602
e939a80
0de7fd7
5669508
4d43376
3637558
139e26e
24294fe
0c9c94e
a39607d
0ee670d
848a6ab
c8a51f9
7053044
77ee6f4
5847795
332e7f9
2f707eb
67b9739
5aeb196
d2b4f56
2860c60
cdc4021
05edbf1
b36299e
195d12f
a69466f
eb71298
48ea7ca
07c023c
be2aeb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,232 @@ | ||||||
| // Copyright 2026 The go-github AUTHORS. All rights reserved. | ||||||
| // | ||||||
| // Use of this source code is governed by a BSD-style | ||||||
| // license that can be found in the LICENSE file. | ||||||
|
|
||||||
| package github | ||||||
|
|
||||||
| import ( | ||||||
| "context" | ||||||
| "encoding/json" | ||||||
| "fmt" | ||||||
| "time" | ||||||
| ) | ||||||
|
|
||||||
| // AgentTasksService handles communication with the agent tasks | ||||||
| // methods of the GitHub API. | ||||||
| // | ||||||
| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10 | ||||||
| type AgentTasksService service | ||||||
|
|
||||||
| // AgentTask represents a Copilot cloud agent task. | ||||||
| type AgentTask struct { | ||||||
|
danyalahmed1995 marked this conversation as resolved.
|
||||||
| ID *string `json:"id,omitempty"` | ||||||
| URL *string `json:"url,omitempty"` | ||||||
| HTMLURL *string `json:"html_url,omitempty"` | ||||||
| Name *string `json:"name,omitempty"` | ||||||
| Creator *User `json:"creator,omitempty"` | ||||||
|
danyalahmed1995 marked this conversation as resolved.
Outdated
|
||||||
| CreatorType *string `json:"creator_type,omitempty"` | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danyalahmed1995 -
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| Owner *User `json:"owner,omitempty"` | ||||||
|
danyalahmed1995 marked this conversation as resolved.
Outdated
|
||||||
| Repository *Repository `json:"repository,omitempty"` | ||||||
|
danyalahmed1995 marked this conversation as resolved.
Outdated
|
||||||
| State *string `json:"state,omitempty"` | ||||||
| SessionCount *int `json:"session_count,omitempty"` | ||||||
| Artifacts []*AgentTaskArtifact `json:"artifacts,omitempty"` | ||||||
| ArchivedAt *Timestamp `json:"archived_at,omitempty"` | ||||||
| CreatedAt *Timestamp `json:"created_at,omitempty"` | ||||||
| UpdatedAt *Timestamp `json:"updated_at,omitempty"` | ||||||
| Sessions []*AgentTaskSession `json:"sessions,omitempty"` | ||||||
| } | ||||||
|
|
||||||
| // AgentTaskArtifact represents an artifact produced by an agent task. | ||||||
| type AgentTaskArtifact struct { | ||||||
| Provider *string `json:"provider,omitempty"` | ||||||
| Type *string `json:"type,omitempty"` | ||||||
| Data json.RawMessage `json:"data,omitempty"` | ||||||
| } | ||||||
|
|
||||||
| // AgentTaskSession represents a session associated with an agent task. | ||||||
| type AgentTaskSession struct { | ||||||
| ID *string `json:"id,omitempty"` | ||||||
| Name *string `json:"name,omitempty"` | ||||||
| User *User `json:"user,omitempty"` | ||||||
| Owner *User `json:"owner,omitempty"` | ||||||
| Repository *Repository `json:"repository,omitempty"` | ||||||
| TaskID *string `json:"task_id,omitempty"` | ||||||
| State *string `json:"state,omitempty"` | ||||||
| CreatedAt *Timestamp `json:"created_at,omitempty"` | ||||||
| UpdatedAt *Timestamp `json:"updated_at,omitempty"` | ||||||
| CompletedAt *Timestamp `json:"completed_at,omitempty"` | ||||||
| Prompt *string `json:"prompt,omitempty"` | ||||||
| HeadRef *string `json:"head_ref,omitempty"` | ||||||
| BaseRef *string `json:"base_ref,omitempty"` | ||||||
| Model *string `json:"model,omitempty"` | ||||||
| } | ||||||
|
|
||||||
| // AgentTaskList represents a list of agent tasks. | ||||||
| type AgentTaskList struct { | ||||||
| Tasks []*AgentTask `json:"tasks,omitempty"` | ||||||
|
danyalahmed1995 marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
|
danyalahmed1995 marked this conversation as resolved.
|
||||||
|
|
||||||
| // AgentTaskListOptions specifies optional parameters to AgentTasksService.List. | ||||||
| type AgentTaskListOptions struct { | ||||||
| // Sort specifies the field to sort results by. Possible values are: updated_at, created_at. | ||||||
| Sort string `url:"sort,omitempty"` | ||||||
|
|
||||||
| // Direction specifies the direction to sort results by. Possible values are: asc, desc. | ||||||
| Direction string `url:"direction,omitempty"` | ||||||
|
|
||||||
| // State is a comma-separated list of task states to filter by. | ||||||
|
danyalahmed1995 marked this conversation as resolved.
|
||||||
| State string `url:"state,omitempty"` | ||||||
|
|
||||||
| // IsArchived filters tasks by archived status. | ||||||
| IsArchived bool `url:"is_archived,omitempty"` | ||||||
|
|
||||||
| // Since filters tasks updated at or after this time. | ||||||
| Since *time.Time `url:"since,omitempty"` | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All fields should be non-pointer types with
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danyalahmed1995 - this comment has not yet been addressed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gmlewis This was tested both ways. The linter failed because Since has url:"since,omitempty" and is an optional query parameter. I restored it to *time.Time, which keeps the absent-vs-zero-value behavior and passes the fork CI/linter. So this is intentionally kept as: Since *time.Time
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danyalahmed1995 you're right, thanks.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexandear no problem, but I'm gonna keep the reviews unresolved to avoid more confusion, kindly resolve the reviews that you believe are fixed I have rechecked the implementation against GitHub rest api documentation directly also verified all the ci on my fork to make sure everything works properly. |
||||||
|
|
||||||
| ListOptions | ||||||
| } | ||||||
|
|
||||||
| // AgentTaskListByRepoOptions specifies optional parameters to AgentTasksService.ListByRepo. | ||||||
| type AgentTaskListByRepoOptions struct { | ||||||
| AgentTaskListOptions | ||||||
|
|
||||||
| // CreatorID filters tasks by creator user ID. | ||||||
| CreatorID int64 `url:"creator_id,omitempty"` | ||||||
|
danyalahmed1995 marked this conversation as resolved.
Outdated
danyalahmed1995 marked this conversation as resolved.
Outdated
|
||||||
| } | ||||||
|
|
||||||
| // CreateAgentTaskOptions represents the parameters for creating an agent task. | ||||||
| type CreateAgentTaskOptions struct { | ||||||
|
danyalahmed1995 marked this conversation as resolved.
Outdated
|
||||||
| // Prompt is the user's prompt for the agent. | ||||||
| Prompt string `json:"prompt"` | ||||||
|
|
||||||
| // Model is the model to use for this task. | ||||||
| Model *string `json:"model,omitempty"` | ||||||
|
|
||||||
| // CreatePullRequest indicates whether to create a pull request. | ||||||
| CreatePullRequest *bool `json:"create_pull_request,omitempty"` | ||||||
|
|
||||||
| // BaseRef is the base ref for the new branch or pull request. | ||||||
| BaseRef *string `json:"base_ref,omitempty"` | ||||||
| } | ||||||
|
danyalahmed1995 marked this conversation as resolved.
|
||||||
|
|
||||||
| // ListByRepo lists tasks for a repository. | ||||||
| // | ||||||
| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#list-tasks-for-repository | ||||||
| // | ||||||
| //meta:operation GET /agents/repos/{owner}/{repo}/tasks | ||||||
| func (s *AgentTasksService) ListByRepo(ctx context.Context, owner, repo string, opts *AgentTaskListByRepoOptions) (*AgentTaskList, *Response, error) { | ||||||
| u := fmt.Sprintf("agents/repos/%v/%v/tasks", owner, repo) | ||||||
| u, err := addOptions(u, opts) | ||||||
| if err != nil { | ||||||
| return nil, nil, err | ||||||
| } | ||||||
|
|
||||||
| req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10")) | ||||||
| if err != nil { | ||||||
| return nil, nil, err | ||||||
| } | ||||||
|
|
||||||
| var tasks *AgentTaskList | ||||||
| resp, err := s.client.Do(req, &tasks) | ||||||
| if err != nil { | ||||||
| return nil, resp, err | ||||||
| } | ||||||
|
|
||||||
| return tasks, resp, nil | ||||||
| } | ||||||
|
|
||||||
| // Create starts a new Copilot cloud agent task for a repository. | ||||||
| // | ||||||
| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#start-a-task | ||||||
| // | ||||||
| //meta:operation POST /agents/repos/{owner}/{repo}/tasks | ||||||
| func (s *AgentTasksService) Create(ctx context.Context, owner, repo string, opts *CreateAgentTaskOptions) (*AgentTask, *Response, error) { | ||||||
|
danyalahmed1995 marked this conversation as resolved.
Outdated
|
||||||
| u := fmt.Sprintf("agents/repos/%v/%v/tasks", owner, repo) | ||||||
|
|
||||||
| req, err := s.client.NewRequest(ctx, "POST", u, opts, WithVersion("2026-03-10")) | ||||||
| if err != nil { | ||||||
| return nil, nil, err | ||||||
| } | ||||||
|
|
||||||
| var task *AgentTask | ||||||
| resp, err := s.client.Do(req, &task) | ||||||
| if err != nil { | ||||||
| return nil, resp, err | ||||||
| } | ||||||
|
|
||||||
| return task, resp, nil | ||||||
| } | ||||||
|
|
||||||
| // GetByRepo gets a repository task by ID. | ||||||
|
gmlewis marked this conversation as resolved.
Outdated
|
||||||
| // | ||||||
| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#get-a-task-by-repo | ||||||
| // | ||||||
| //meta:operation GET /agents/repos/{owner}/{repo}/tasks/{task_id} | ||||||
| func (s *AgentTasksService) GetByRepo(ctx context.Context, owner, repo, taskID string) (*AgentTask, *Response, error) { | ||||||
| u := fmt.Sprintf("agents/repos/%v/%v/tasks/%v", owner, repo, taskID) | ||||||
|
|
||||||
| req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10")) | ||||||
| if err != nil { | ||||||
| return nil, nil, err | ||||||
| } | ||||||
|
|
||||||
| var task *AgentTask | ||||||
| resp, err := s.client.Do(req, &task) | ||||||
| if err != nil { | ||||||
| return nil, resp, err | ||||||
| } | ||||||
|
|
||||||
| return task, resp, nil | ||||||
| } | ||||||
|
|
||||||
| // List lists tasks for the authenticated user. | ||||||
| // | ||||||
| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#list-tasks | ||||||
| // | ||||||
| //meta:operation GET /agents/tasks | ||||||
| func (s *AgentTasksService) List(ctx context.Context, opts *AgentTaskListOptions) (*AgentTaskList, *Response, error) { | ||||||
| return s.list(ctx, "agents/tasks", opts) | ||||||
| } | ||||||
|
|
||||||
| func (s *AgentTasksService) list(ctx context.Context, u string, opts *AgentTaskListOptions) (*AgentTaskList, *Response, error) { | ||||||
|
danyalahmed1995 marked this conversation as resolved.
Outdated
|
||||||
| u, err := addOptions(u, opts) | ||||||
| if err != nil { | ||||||
| return nil, nil, err | ||||||
| } | ||||||
|
|
||||||
| req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10")) | ||||||
|
danyalahmed1995 marked this conversation as resolved.
Outdated
|
||||||
| if err != nil { | ||||||
| return nil, nil, err | ||||||
| } | ||||||
|
|
||||||
| var tasks *AgentTaskList | ||||||
| resp, err := s.client.Do(req, &tasks) | ||||||
| if err != nil { | ||||||
| return nil, resp, err | ||||||
| } | ||||||
|
|
||||||
| return tasks, resp, nil | ||||||
| } | ||||||
|
|
||||||
| // Get gets a task by ID for the authenticated user. | ||||||
| // | ||||||
| // GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#get-a-task-by-id | ||||||
| // | ||||||
| //meta:operation GET /agents/tasks/{task_id} | ||||||
| func (s *AgentTasksService) Get(ctx context.Context, taskID string) (*AgentTask, *Response, error) { | ||||||
| u := fmt.Sprintf("agents/tasks/%v", taskID) | ||||||
|
|
||||||
| req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10")) | ||||||
| if err != nil { | ||||||
| return nil, nil, err | ||||||
| } | ||||||
|
|
||||||
| var task *AgentTask | ||||||
| resp, err := s.client.Do(req, &task) | ||||||
| if err != nil { | ||||||
| return nil, resp, err | ||||||
| } | ||||||
|
|
||||||
| return task, resp, nil | ||||||
| } | ||||||

Uh oh!
There was an error while loading. Please reload this page.