Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 18, 2026

The assign-to-agent safe output type now supports an optional branch parameter to specify the base branch for agent work.

Changes

  • TypeScript/JavaScript: Added branch?: string field to AssignToAgentItem interface and MCP tools schema
  • Go: Added DefaultBranch field to AssignToAgentConfig for YAML frontmatter configuration
  • Handler: Modified assign_to_agent.cjs to:
    • Accept branch from agent output or use default from config
    • Call Copilot REST API directly (POST https://api.github.com/agents/swe/v1/jobs/{owner}/{repo}) with pull_request.base_ref parameter
    • Fall back to standard GraphQL assignment if REST API fails
    • Include branch in summary and staged preview outputs
  • Issue Monster workflow: Updated instructions to extract branch from issue body using patterns like "base branch: develop" and pass to agent assignment

Implementation Details

After reviewing the gh CLI source code (pkg/cmd/agent-task/capi/job.go), discovered that agent task creation uses the Copilot REST API endpoint rather than GraphQL. The implementation now makes a direct REST API call, which is more reliable than shelling out to the gh CLI and provides better integration with the existing codebase.

Usage

// Agent can now specify target branch
safeoutputs/assign_to_agent(issue_number=123, agent="copilot", branch="develop")
# Or configure default in frontmatter
safe-outputs:
  assign-to-agent:
    name: copilot
    branch: main  # Default branch for all assignments

When a branch is specified for an issue, the handler calls the Copilot API with the payload:

{
  "problem_statement": "Work on issue #123",
  "event_type": "gh_cli",
  "pull_request": {
    "base_ref": "refs/heads/develop"
  }
}

This ensures the agent task is created with the correct base branch, and PRs are created from the specified branch.

Original prompt

At @copilot, update the assign-to-agent safe-output type to support also assigning a branch. Update the Issue Monster agentic-workflow to mine the base-branch of the fix so that you assign it to the correct branch.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 18, 2026 18:44
- Add optional 'branch' field to AssignToAgentItem TypeScript interface
- Add DefaultBranch field to AssignToAgentConfig struct
- Update safe_outputs_tools.json to document branch parameter
- Update assign_to_agent.cjs to handle branch parameter:
  - Extract branch from item or use default branch
  - Add comment to issue with branch information when branch is specified
  - Include branch in summary and staged preview
- Update Issue Monster workflow to instruct agent to extract base branch from issue body
- Build and format successful, unit tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Add test for branch parameter handling in agent output
- Verify branch comment is created when branch is specified
- Verify branch is included in summary output
- All tests passing (22 passed, 2 skipped)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Update assign-to-agent safe-output type to include branch support Add branch parameter to assign-to-agent safe output type Jan 18, 2026
Copilot AI requested a review from pelikhan January 18, 2026 18:59
// Assign agent using GraphQL mutation - uses built-in github object authenticated via github-token
// Pass the allowed list so existing assignees are filtered before calling replaceActorsForAssignable
core.info(`Assigning ${agentName} coding agent to ${type} #${number}...`);
const success = await assignAgentToIssue(assignableId, agentId, currentAssignees, agentName, allowedAgents);
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot this function API call must take the branch and apply it in the API call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3ec5193. When a branch is specified, the handler now calls gh agent-task create #<issue_number> --base <branch> which properly passes the branch parameter to the agent task creation API. Falls back to standard GraphQL assignment if the CLI command fails.

When a branch is specified for assign-to-agent, now uses the gh CLI
'agent-task create' command with the --base flag instead of just
assigning via GraphQL (which doesn't support branch specification).

This properly passes the branch information to the agent task creation
API, ensuring the agent creates PRs based on the correct branch.

- Modified assign_to_agent.cjs to call 'gh agent-task create #<issue> --base <branch>'
- Falls back to standard GraphQL assignment if gh CLI fails
- Updated tests to mock exec.getExecOutput and verify correct CLI invocation
- All tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan January 18, 2026 19:41
@pelikhan
Copy link
Contributor

@copilot review the agent-task source to discover how to update the graphql calls

After reviewing gh CLI source code (pkg/cmd/agent-task/capi/job.go),
discovered that agent tasks use a REST API endpoint, not GraphQL.

Changed implementation to call the Copilot API directly:
- POST https://api.github.com/agents/swe/v1/jobs/{owner}/{repo}
- Payload includes pull_request.base_ref: "refs/heads/{branch}"
- This matches how gh CLI implements branch support

Benefits over gh CLI execution:
- Direct API call is more reliable and efficient
- Better error handling and integration with existing code
- No dependency on gh CLI being installed/configured

Updated tests to mock github.request() instead of exec.getExecOutput()
All tests passing (22 passed, 2 skipped)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 18, 2026

@copilot review the agent-task source to discover how to update the graphql calls

Reviewed gh CLI source code and discovered the solution in 248e31e. The gh agent-task command uses a REST API (Copilot API), not GraphQL.

The implementation now calls POST https://api.github.com/agents/swe/v1/jobs/{owner}/{repo} with payload:

{
  "pull_request": {
    "base_ref": "refs/heads/{branch}"
  }
}

This matches how gh CLI implements it in pkg/cmd/agent-task/capi/job.go CreateJob() method. Direct REST API call is more reliable than shelling out to gh CLI.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants