Skip to content

feat: Add agent tasks API support#4225

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

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

Conversation

@danyalahmed1995

Copy link
Copy Markdown
Contributor

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

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.93814% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.46%. Comparing base (34dd998) to head (195d12f).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
github/agent_tasks.go 96.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4225   +/-   ##
=======================================
  Coverage   97.46%   97.46%           
=======================================
  Files         192      193    +1     
  Lines       19258    19355   +97     
=======================================
+ Hits        18770    18865   +95     
- Misses        270      271    +1     
- Partials      218      219    +1     

☔ View full report in Codecov by Harness.
📢 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

@gmlewis gmlewis left a comment

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.

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 Outdated
Comment thread github/agent_tasks.go Outdated
Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
@danyalahmed1995

Copy link
Copy Markdown
Contributor Author

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

Comment thread github/agent_tasks.go Outdated

@gmlewis gmlewis left a comment

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.

@stevehipwell stevehipwell left a comment

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.

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

Comment thread github/agent_tasks.go
Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go
Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go Outdated
danyalahmed1995 and others added 2 commits May 15, 2026 18:05
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
@danyalahmed1995

Copy link
Copy Markdown
Contributor Author

@stevehipwell @alexandear updated, thanks for the reviews.

Changes in the latest update:

  • adjusted the Agent Tasks response structs so documented required fields are non-pointers, while nullable/optional fields remain pointers
  • folded the private list helper back into List and removed the Codecov-only List bad-options test so the production code stays simpler
  • added agentTasksAPIVersion and replaced the repeated WithVersion("2026-03-10") usage
  • updated the Agent Tasks doc comment URLs so the apiVersion value matches the request version
  • regenerated the affected accessors/tests

Validation:

  • script/generate.sh passed
  • gofmt passed on changed Go files
  • go test ./github passed
  • script/fmt.sh passed
  • script/test.sh ./... passed
  • script/lint.sh passed
  • git diff --check passed
  • confirmed openapi_operations.yaml and go.mod have no diff
  • confirmed changed files are LF-only with no CRLF churn

Comment thread github/agent_tasks.go
Comment thread github/agent_tasks.go
@danyalahmed1995

danyalahmed1995 commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

@alexandear @stevehipwell Thanks for pointing me to the right direction.

Root cause was generator-side: the Agent Tasks documentation URLs did not include an explicit apiVersion, so the metadata normalizer defaulted the generated comments to 2022-11-28.

I added a narrow metadata mapping for /rest/agent-tasks/agent-tasks so generated Agent Tasks doc links normalize to apiVersion=2026-03-10, then reran script/generate.sh. The generated comments now stay aligned with agentTasksAPIVersion.

Validation:

  • script/generate.sh passed and preserved the corrected Agent Tasks comments
  • go test ./github passed
  • go test ./metadata from tools passed
  • script/lint.sh passed
  • git diff --check passed
  • confirmed openapi_operations.yaml and go.mod have no diff
  • confirmed changed files are LF-only with no CRLF churn

Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go
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.

Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go
Comment thread github/agent_tasks.go
Comment thread github/agent_tasks.go
Comment thread github/agent_tasks.go Outdated
HTMLURL *string `json:"html_url,omitempty"`
Name *string `json:"name,omitempty"`
Creator *User `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

Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go Outdated
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
Comment thread tools/metadata/metadata.go Outdated
Comment thread tools/metadata/metadata.go Outdated
Comment thread tools/metadata/metadata_test.go
Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go Outdated
AgentTaskListOptions

// CreatorIDs filters tasks by creator user IDs.
CreatorIDs []int64 `url:"creator_id,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.

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.

Comment thread github/agent_tasks.go
Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go
Comment thread github/agent_tasks.go
Comment thread github/agent_tasks_test.go Outdated
Comment thread github/agent_tasks_test.go Outdated
danyalahmed1995 and others added 10 commits June 1, 2026 15:48
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
@danyalahmed1995

Copy link
Copy Markdown
Contributor Author

Guys is anything left 🤔

@alexandear

Copy link
Copy Markdown
Contributor

Guys is anything left 🤔

Please read all our comments and apply fixes. Also, do not forget to fix lint issues and tests. Run the following commands:

$ ./script/lint.sh
$ ./script/test.sh

Comment thread github/agent_tasks.go
Comment thread github/agent_tasks.go Outdated
HTMLURL *string `json:"html_url,omitempty"`
Name *string `json:"name,omitempty"`
Creator *User `json:"creator,omitempty"`
CreatorType *string `json:"creator_type,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 - user_collaborators is still missing from this struct. Stopping review here.

Comment thread github/agent_tasks.go
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
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.

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