Skip to content

feat: Add agent tasks API support#4225

Open
danyalahmed1995 wants to merge 7 commits into
google:masterfrom
danyalahmed1995:add-agent-tasks-api
Open

feat: Add agent tasks API support#4225
danyalahmed1995 wants to merge 7 commits into
google:masterfrom
danyalahmed1995:add-agent-tasks-api

Conversation

@danyalahmed1995
Copy link
Copy Markdown

Summary

Adds typed client support for GitHub's Agent Tasks REST API.

This implements the documented public-preview Agent Tasks endpoints:

  • GET /agents/repos/{owner}/{repo}/tasks
  • POST /agents/repos/{owner}/{repo}/tasks
  • GET /agents/repos/{owner}/{repo}/tasks/{task_id}
  • GET /agents/tasks
  • GET /agents/tasks/{task_id}

Closes #4213.

Changes

  • Added AgentTasksService and registered it on Client.
  • Added Agent Tasks request/response types for tasks, sessions, artifacts, list options, and create options.
  • Added methods for listing, creating, and retrieving agent tasks.
  • Added tests covering:
    • endpoint paths
    • HTTP methods
    • request bodies
    • response parsing
    • query parameters
    • pagination
    • preview API headers
  • Added OpenAPI operation metadata for the new preview endpoints.
  • Regenerated accessors and iterators.

Notes

The Agent Tasks API is currently in public preview, so this PR keeps the implementation scoped to the fields and endpoints currently documented by GitHub.

Validation

Ran the repository validation flow from CONTRIBUTING.md:

  • script/fmt.sh
  • script/test.sh ./...
  • script/lint.sh
  • script/generate.sh
  • git diff --check

script/test.sh with the default race configuration could not run on this Windows machine because cgo/gcc was not available. I reran the full test script with the non-race fallback across all modules, and it passed.

@gmlewis gmlewis changed the title github: add agent tasks API support feat: Add agent tasks API support May 14, 2026
Comment thread openapi_operations.yaml Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.76%. Comparing base (40ed57f) to head (738801b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4225      +/-   ##
==========================================
+ Coverage   97.75%   97.76%   +0.01%     
==========================================
  Files         189      190       +1     
  Lines       19035    19133      +98     
==========================================
+ Hits        18608    18706      +98     
  Misses        231      231              
  Partials      196      196              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label May 14, 2026
Copy link
Copy Markdown
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @danyalahmed1995!
Just a couple tweaks/questions, then we should be ready for a second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell - @alexandear - @zyfy29 - @Not-Dhananjay-Mishra - @munlicode

Comment thread github/agent_tasks.go
Comment thread github/agent_tasks.go Outdated
Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
@danyalahmed1995
Copy link
Copy Markdown
Author

@gmlewis Thanks, sounds good. I’ll address the review comments and push an update shortly.

Comment thread github/agent_tasks.go Outdated
Copy link
Copy Markdown
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @danyalahmed1995, I've added a couple of comments.

Comment thread github/agent_tasks.go
type AgentTasksService service

// AgentTask represents a Copilot cloud agent task.
type AgentTask struct {
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.

This struct doesn't look correct to me as a number of these fields are required so shouldn't be pointers.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, I’ll review the documented required vs nullable fields and adjust the struct so required fields are non-pointers while keeping nullable/optional fields as pointers.

Comment thread github/agent_tasks.go
return s.list(ctx, "agents/tasks", opts)
}

func (s *AgentTasksService) list(ctx context.Context, u string, opts *AgentTaskListOptions) (*AgentTaskList, *Response, error) {
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.

Why is this separate to List?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This was split out only to make the addOptions error path testable after Codecov flagged it. I agree it adds some unnecessary indirection, so I can fold it back into List and drop that extra helper if that’s preferred.

Comment thread github/agent_tasks.go
return nil, nil, err
}

req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))
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.

Could we get "2026-03-10" made into a constant?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, makes sense. I’ll move the preview API version into a package-level constant and use it across the Agent Tasks methods.

Comment thread github/agent_tasks.go

// ListByRepo lists tasks for a repository.
//
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#list-tasks-for-repository
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
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2022-11-28#list-tasks-for-repository
// GitHub API docs: https://docs.github.com/rest/agent-tasks/agent-tasks?apiVersion=2026-03-10#list-tasks-for-repository

Because below you have:

req, err := s.client.NewRequest(ctx, "GET", u, nil, WithVersion("2026-03-10"))

Comment thread github/agent_tasks.go
Comment on lines +141 to +147
// 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, 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("2026-03-10"))
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 versions in the comment and the code do not match.

Comment thread github/agent_tasks.go
Comment on lines +163 to +169
// 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) {
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"))
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 versions in the comment and the code do not match.

Comment thread github/agent_tasks.go
Comment on lines +185 to +198
// 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) {
return s.list(ctx, "agents/tasks", opts)
}

func (s *AgentTasksService) list(ctx context.Context, u string, opts *AgentTaskListOptions) (*AgentTaskList, *Response, error) {
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"))
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 versions in the comment and the code do not match.

Comment thread github/agent_tasks.go
Comment on lines +214 to +220
// 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("2026-03-10"))
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 versions in the comment and the code do not match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for new agent tasks REST API

4 participants