Skip to content
Open
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8d3c4df
github: add agent tasks API support
danyalahmed1995 May 14, 2026
efa12d7
Merge remote-tracking branch 'upstream/master' into add-agent-tasks-api
danyalahmed1995 May 14, 2026
4263d58
test: cover agent tasks list options error
danyalahmed1995 May 14, 2026
43387ee
Update github/agent_tasks.go
danyalahmed1995 May 14, 2026
3c4d321
fix: address agent tasks review comments
danyalahmed1995 May 15, 2026
93e009c
fix: remove openapi operations diff
danyalahmed1995 May 15, 2026
738801b
fix: restore agent tasks creator id type
danyalahmed1995 May 15, 2026
ceabbf4
Update github/agent_tasks.go
danyalahmed1995 May 15, 2026
f8042ad
fix: address latest agent tasks review comments
danyalahmed1995 May 15, 2026
a2f45a2
fix: preserve agent tasks docs api version
danyalahmed1995 May 15, 2026
5160bbf
Update github/agent_tasks.go
danyalahmed1995 May 16, 2026
ab0cc87
Update github/agent_tasks.go
danyalahmed1995 May 16, 2026
d10a780
Update github/agent_tasks.go
danyalahmed1995 May 16, 2026
a982cae
Update github/agent_tasks.go
danyalahmed1995 May 16, 2026
41b1ac1
Update github/agent_tasks.go
danyalahmed1995 May 17, 2026
dc0817a
fix: address agent tasks schema review
danyalahmed1995 May 17, 2026
8e1ed64
fix: use shared agent tasks api version constant
danyalahmed1995 May 18, 2026
96ff69b
Merge remote-tracking branch 'upstream/master' into add-agent-tasks-api
danyalahmed1995 May 19, 2026
d40f10b
Update github/agent_tasks.go
danyalahmed1995 May 27, 2026
526dbeb
Update github/agent_tasks.go
danyalahmed1995 May 27, 2026
ca7b94c
Update agent_tasks.go
danyalahmed1995 May 27, 2026
f60454c
Update agent_tasks.go
danyalahmed1995 May 27, 2026
38fdd45
Update agent_tasks.go
danyalahmed1995 May 27, 2026
127e602
Update agent_tasks_test.go
danyalahmed1995 May 27, 2026
e939a80
Merge remote-tracking branch 'upstream/master' into add-agent-tasks-api
danyalahmed1995 May 29, 2026
0de7fd7
fix: address agent tasks review cleanup
danyalahmed1995 May 29, 2026
5669508
Merge remote-tracking branch 'origin/add-agent-tasks-api' into add-ag…
danyalahmed1995 May 29, 2026
4d43376
Update agent_tasks.go
danyalahmed1995 May 29, 2026
3637558
fix: address agent tasks schema review
danyalahmed1995 May 29, 2026
139e26e
Update github/agent_tasks.go
danyalahmed1995 May 29, 2026
24294fe
fix: use default docs version for agent tasks links
danyalahmed1995 May 29, 2026
0c9c94e
Update agent_tasks.go
danyalahmed1995 Jun 1, 2026
a39607d
Update agent_tasks.go
danyalahmed1995 Jun 1, 2026
0ee670d
Update agent_tasks.go
danyalahmed1995 Jun 1, 2026
848a6ab
Update agent_tasks.go
danyalahmed1995 Jun 1, 2026
c8a51f9
Update agent_tasks.go
danyalahmed1995 Jun 1, 2026
7053044
Update agent_tasks.go
danyalahmed1995 Jun 1, 2026
77ee6f4
Update agent_tasks.go
danyalahmed1995 Jun 1, 2026
5847795
Update agent_tasks_test.go
danyalahmed1995 Jun 1, 2026
332e7f9
Update agent_tasks_test.go
danyalahmed1995 Jun 1, 2026
2f707eb
fix: address agent tasks schema review
danyalahmed1995 Jun 1, 2026
67b9739
Merge remote-tracking branch 'upstream/master' into add-agent-tasks-api
danyalahmed1995 Jun 11, 2026
5aeb196
fix: address agent tasks review feedback
danyalahmed1995 Jun 11, 2026
d2b4f56
Update agent_tasks.go
danyalahmed1995 Jun 11, 2026
2860c60
Merge remote-tracking branch 'upstream/master' into add-agent-tasks-api
danyalahmed1995 Jun 11, 2026
cdc4021
Fix agent tasks option accessors
danyalahmed1995 Jun 11, 2026
05edbf1
Trigger fork CI
danyalahmed1995 Jun 11, 2026
b36299e
Fix agent tasks since option
danyalahmed1995 Jun 11, 2026
195d12f
Add agent task user collaborators field
danyalahmed1995 Jun 11, 2026
a69466f
Add agent task session error field
danyalahmed1995 Jun 13, 2026
eb71298
Remove agent tasks API version override
danyalahmed1995 Jun 14, 2026
48ea7ca
Merge branch 'master' into add-agent-tasks-api
gmlewis Jun 25, 2026
07c023c
Apply suggestion from @gmlewis
gmlewis Jun 25, 2026
be2aeb7
Apply suggestion from @gmlewis
gmlewis Jun 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
268 changes: 268 additions & 0 deletions github/agent_tasks.go
Comment thread
danyalahmed1995 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
// 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"
"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=2022-11-28
type AgentTasksService service

// AgentTask represents a Copilot cloud agent task.
type AgentTask struct {
Comment thread
danyalahmed1995 marked this conversation as resolved.
ID string `json:"id"`
URL *string `json:"url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
Name *string `json:"name,omitempty"`
Creator *AgentTaskCreator `json:"creator,omitempty"`
CreatorType *string `json:"creator_type,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing user_collaborators field:

        "user_collaborators": {
          "type": "array",
          "items": {
            "type": "object",
            "description": "A GitHub user",
            "properties": {
              "id": {
                "type": "integer",
                "format": "int64",
                "description": "The unique identifier of the user"
              }
            }
          },
          "description": "User objects of collaborators on this task",
          "deprecated": true
        },

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danyalahmed1995 - user_collaborators is still missing from this struct. Stopping review here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am so sorry for this confusion 😔. I must have missed it because it was asked to be removed I restored it and checked the CI again on my fork to make sure it doesnt fail again.

image

Owner *AgentTaskOwner `json:"owner,omitempty"`
Repository *AgentTaskRepository `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"`
}

// AgentTaskCreator represents an agent task creator.
type AgentTaskCreator struct {
ID *int64 `json:"id,omitempty"`
}

// AgentTaskOwner represents an agent task owner.
type AgentTaskOwner struct {
ID *int64 `json:"id,omitempty"`
}

// AgentTaskRepository represents an agent task repository.
type AgentTaskRepository struct {
ID *int64 `json:"id,omitempty"`
}

// AgentTaskArtifact represents an artifact produced by an agent task.
type AgentTaskArtifact struct {
Provider string `json:"provider"`
Type string `json:"type"`
Data *AgentTaskArtifactData `json:"data,omitempty"`
}

// AgentTaskArtifactData represents data associated with an agent task artifact.
type AgentTaskArtifactData struct {
ID *int64 `json:"id,omitempty"`
GlobalID *string `json:"global_id,omitempty"`
HeadRef *string `json:"head_ref,omitempty"`
BaseRef *string `json:"base_ref,omitempty"`
}

// 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 *AgentTaskOwner `json:"owner,omitempty"`
Repository *AgentTaskRepository `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"`
TotalActiveCount *int `json:"total_active_count,omitempty"`
TotalArchivedCount *int `json:"total_archived_count,omitempty"`
}
Comment thread
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.
Comment thread
danyalahmed1995 marked this conversation as resolved.
// Possible values are: queued, in_progress, completed, failed, idle,
// waiting_for_user, timed_out, cancelled.
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"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All fields should be non-pointer types with url tags:

Suggested change
Since *time.Time `url:"since,omitempty"`
Since time.Time `url:"since,omitempty"`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danyalahmed1995 - this comment has not yet been addressed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 url:"since,omitempty"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danyalahmed1995 you're right, thanks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

// CreatorIDs filters tasks by creator user IDs.
CreatorIDs []int64 `url:"creator_id,omitempty"`

Check failure on line 121 in github/agent_tasks.go

View workflow job for this annotation

GitHub Actions / golangci-lint

change Go field name "CreatorIDs" to "CreatorID" for url tag "creator_id" in struct "AgentTaskListByRepoOptions" (structfield)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CreatorIDs []int64 `url:"creator_id,omitempty"`
CreatorID []int64 `url:"creator_id,omitempty"`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why our linter didn't catch this one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linter catches this:

image

I just wanted to emphasize that this needs to be fixed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sincere apology for the inconvenience , I went through the reviews and this time properly double checked all the missing pieces and linter errors on my fork . Kindly when you guys have time confirm if everything is good . I will keep this and the other review thread open , until you guys verify it.

}

// CreateAgentTaskRequest represents the parameters for creating an agent task.
type CreateAgentTaskRequest 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"`

// HeadRef is the head ref for the new branch or pull request.
HeadRef *string `json:"head_ref,omitempty"`

// BaseRef is the base ref for the new branch or pull request.
BaseRef *string `json:"base_ref,omitempty"`
}
Comment thread
danyalahmed1995 marked this conversation as resolved.

// ListByRepo lists tasks for a repository.
//
// Note: This endpoint is in public preview and is subject to change.
//
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#list-tasks-for-repository
Comment thread
danyalahmed1995 marked this conversation as resolved.
Comment thread
danyalahmed1995 marked this conversation as resolved.
Comment thread
danyalahmed1995 marked this conversation as resolved.
//
//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(api20260310))
Comment thread
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
}

// Create starts a new Copilot cloud agent task for a repository.
//
// Note: This endpoint is in public preview and is subject to change.
//
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#start-a-task
//
//meta:operation POST /agents/repos/{owner}/{repo}/tasks
func (s *AgentTasksService) Create(ctx context.Context, owner, repo string, req CreateAgentTaskRequest) (*AgentTask, *Response, error) {
Comment thread
gmlewis marked this conversation as resolved.
Outdated
u := fmt.Sprintf("agents/repos/%v/%v/tasks", owner, repo)

request, err := s.client.NewRequest(ctx, "POST", u, req, WithVersion(api20260310))
if err != nil {
return nil, nil, err
}

var task *AgentTask
resp, err := s.client.Do(request, &task)
if err != nil {
return nil, resp, err
}

return task, resp, nil
}

// GetByRepoAndID gets a repository task by ID.
//
// Note: This endpoint is in public preview and is subject to change.
//
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#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) {
Comment thread
danyalahmed1995 marked this conversation as resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The session schema for this endpoint and for AgentTasksService.Get defines the following in the response:

error:
  type: object
  description: Error details for a failed session
  properties:
    message:
      type: string

The AgentTask contains the field Sessions of the type []*AgentTaskSession.
But AgentTaskSession omits the error defined in the schema.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added AgentTaskSession.Error with a small AgentTaskSessionError type, updated the session fixture/expected struct coverage, regenerated accessors/tests, validated CI on my fork.

u := fmt.Sprintf("agents/repos/%v/%v/tasks/%v", owner, repo, taskID)

req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion(api20260310))
Comment thread
danyalahmed1995 marked this conversation as resolved.
Outdated
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.
//
// Note: This endpoint is in public preview and is subject to change.
//
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#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(api20260310))
Comment thread
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.
//
// Note: This endpoint is in public preview and is subject to change.
//
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#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(api20260310))
Comment thread
danyalahmed1995 marked this conversation as resolved.
Outdated
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
}
Loading
Loading