Skip to content

feat: Add agent tasks API support#4225

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

feat: Add agent tasks API support#4225
danyalahmed1995 wants to merge 24 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
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

❌ Patch coverage is 97.93814% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.46%. Comparing base (5475166) to head (96ff69b).
⚠️ Report is 10 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.45%   97.46%           
=======================================
  Files         189      190    +1     
  Lines       19164    19261   +97     
=======================================
+ Hits        18677    18772   +95     
- Misses        270      271    +1     
- Partials      217      218    +1     

☔ 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
Contributor 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
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
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 Outdated
Comment thread github/agent_tasks.go Outdated
@danyalahmed1995
Copy link
Copy Markdown
Contributor Author

danyalahmed1995 commented May 15, 2026

@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
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
Comment thread github/agent_tasks.go Outdated
Comment thread github/agent_tasks.go Outdated
Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
danyalahmed1995 and others added 5 commits May 17, 2026 04:41
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

@alexandear updated, thanks.

I added total_active_count and total_archived_count to AgentTaskList, added the deprecated user_collaborators field, and modeled owner / repository as minimal Agent Tasks ID-only structs instead of broader *User / *Repository.

I also added the public preview note to the Agent Tasks endpoint docs and kept agentTasksAPIVersion unchanged for now pending the constant naming/location preference.

I checked the schema for owner.id and repository.id; both are integer / int64, but the nested id fields are not marked as required, so they remain *int64 with omitempty.

Validation:

  • script/generate.sh passed
  • gofmt / script/fmt.sh passed
  • 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

I leave the api20260310 / github.go constant discussion untouched until @stevehipwell answers.

Comment thread github/github.go
Comment thread tools/metadata/metadata.go Outdated
@gmlewis
Copy link
Copy Markdown
Collaborator

gmlewis commented May 26, 2026

@stevehipwell - @alexandear - could you please take another look when you get a chance?

Comment thread github/agent_tasks.go
Comment on lines +39 to +40
// Deprecated: UserCollaborators is deprecated by GitHub.
UserCollaborators []*User `json:"user_collaborators,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.

I propose not adding the deprecated field. Or should we?

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.

This field is still present in the response schema, exposing it would keep the client complete and let callers read it if GitHub still returns it. I marked it deprecated so users are discouraged from relying on it.

GitHub’s official OpenAPI description still includes user_collaborators in the Agent Tasks response schema, marked deprecated. Since go-github models API response fields, exposing it keeps the SDK schema-complete and allows callers to read the field if GitHub still returns it.

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
Comment on lines +19 to +22
const (
agentTaskID = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
agentTaskSessionID = "s1a2b3c4-d5e6-7890-abcd-ef1234567890"
)
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.

Please do not declare global constants. It's better to have a separate constant for each test.

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.

Fix here and below.

Comment thread github/agent_tasks_test.go Outdated
Comment on lines +72 to +73
createdAt := &Timestamp{time.Date(2025, time.January, 1, 0, 0, 0, 0, time.UTC)}
updatedAt := &Timestamp{time.Date(2025, time.January, 1, 1, 0, 0, 0, time.UTC)}
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 use a different date, not 2025-01-01?

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.

What do you think could be a good golden number for the date here 🤔 ?

testJSONMarshal(t, u, want, cmpJSONRawMessageComparator())
}

func TestAgentTaskOwner_Marshal(t *testing.T) {
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 *_Marshal tests are not needed and can be removed.

They are required only if we have custom marshal/unmarshal functions.

See #4253 (comment)

// Keep this in sync with defaultAPIVersion in github/github.go.
const metadataDocsAPIVersion = "2022-11-28"

var customDocsAPIVersions = map[string]string{
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.

Maybe previewDocsAPIVersions would be a better name? And the var requires the comment.

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.

Yeah that was the plan initially but you asked to change it, you want me to revert it back ?

danyalahmed1995 and others added 6 commits May 27, 2026 17:17
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>
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. waiting for reply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for new agent tasks REST API

4 participants