-
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
Open
danyalahmed1995
wants to merge
10
commits into
google:master
Choose a base branch
from
danyalahmed1995:add-agent-tasks-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8d3c4df
github: add agent tasks API support
danyalahmed1995 efa12d7
Merge remote-tracking branch 'upstream/master' into add-agent-tasks-api
danyalahmed1995 4263d58
test: cover agent tasks list options error
danyalahmed1995 43387ee
Update github/agent_tasks.go
danyalahmed1995 3c4d321
fix: address agent tasks review comments
danyalahmed1995 93e009c
fix: remove openapi operations diff
danyalahmed1995 738801b
fix: restore agent tasks creator id type
danyalahmed1995 ceabbf4
Update github/agent_tasks.go
danyalahmed1995 f8042ad
fix: address latest agent tasks review comments
danyalahmed1995 a2f45a2
fix: preserve agent tasks docs api version
danyalahmed1995 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| // 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" | ||
| ) | ||
|
|
||
| const agentTasksAPIVersion = "2026-03-10" | ||
|
|
||
| // 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 { | ||
| ID string `json:"id"` | ||
| URL *string `json:"url,omitempty"` | ||
| HTMLURL *string `json:"html_url,omitempty"` | ||
| Name *string `json:"name,omitempty"` | ||
| Creator *User `json:"creator,omitempty"` | ||
| CreatorType *string `json:"creator_type,omitempty"` | ||
| Owner *User `json:"owner,omitempty"` | ||
| Repository *Repository `json:"repository,omitempty"` | ||
| State string `json:"state"` | ||
| SessionCount *int `json:"session_count,omitempty"` | ||
| Artifacts []*AgentTaskArtifact `json:"artifacts,omitempty"` | ||
| ArchivedAt *Timestamp `json:"archived_at,omitempty"` | ||
| CreatedAt Timestamp `json:"created_at"` | ||
| 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"` | ||
| Type string `json:"type"` | ||
| Data json.RawMessage `json:"data"` | ||
| } | ||
|
|
||
| // AgentTaskSession represents a session associated with an agent task. | ||
| type AgentTaskSession struct { | ||
| ID string `json:"id"` | ||
| 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"` | ||
| CreatedAt Timestamp `json:"created_at"` | ||
| 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"` | ||
| } | ||
|
|
||
| // 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. | ||
| 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"` | ||
|
|
||
| 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"` | ||
| } | ||
|
|
||
| // CreateAgentTaskOptions represents the parameters for creating an agent task. | ||
| type CreateAgentTaskOptions struct { | ||
| // 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"` | ||
| } | ||
|
|
||
| // 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(agentTasksAPIVersion)) | ||
| 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) { | ||
| u := fmt.Sprintf("agents/repos/%v/%v/tasks", owner, repo) | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "POST", u, opts, WithVersion(agentTasksAPIVersion)) | ||
| 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 | ||
| } | ||
|
|
||
| // GetByRepoAndID gets a repository task by ID. | ||
| // | ||
| // 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) GetByRepoAndID(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(agentTasksAPIVersion)) | ||
| 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) { | ||
| u := "agents/tasks" | ||
| u, err := addOptions(u, opts) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion(agentTasksAPIVersion)) | ||
| 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(agentTasksAPIVersion)) | ||
| 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 | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.