Flag cleanup custom agent for GitHub Copilot

Overview

This topic describes how to install and use the LaunchDarkly flag cleanup custom agent for GitHub Copilot.

The flag cleanup agent uses the LaunchDarkly MCP server to help you to automate feature flag workflows using either the Github UI or the GitHub Copilot CLI.

When using the agent, you can provide natural language prompts to safely perform tasks such as:

  • Cleaning up obsolete flags from your codebase
  • Determining whether a flag is ready for removal
  • Identifying the correct variation value to use when removing a flag
  • Creating pull requests (PRs) that preserve production behavior

Prerequisites

Before you can install or use the agent, you must configure the LaunchDarkly Feature management (feature flags) MCP server for GitHub Copilot. To learn more, read LaunchDarkly hosted MCP server.

Installing the agent

The LaunchDarkly custom agent file, hosted in the Awesome GitHub Copilot repo, defines the specialized agent behavior to use when performing LaunchDarkly workflows.

To install the agent file:

  1. Create a .github/agents/ directory in the top level of your GitHub repository if it does not already exist.
  2. Download the LaunchDarkly agent profile from the Awesome GitHub Copilot repository.
  3. Save the downloaded file to your repository as .github/agents/launchdarkly.agent.md.
  4. Commit and push the new file to the repository.

Using the agent

After you add the LaunchDarkly agent profile to your repository, you can use the agent from either the GitHub Copilot UI or the Copilot CLI.

GitHub Copilot UI (github.com)

To use the LaunchDarkly agent at github.com:

  1. Navigate to the Agents tab at https://github.com/copilot/agents.
  2. Use the dropdown in the prompt box to select the LaunchDarkly custom agent.
  3. Enter a natural language prompt, such as:
    • “Clean up the obsolete feature flag legacy-checkout-flow from this codebase”
    • “Check if the new-dashboard flag is safe to remove”
    • “Create a feature flag for the new authentication feature”

Copilot uses the custom agent rules with the LaunchDarkly API to execute the task and create a PR.

GitHub Copilot CLI

First, install the GitHub Copilot CLI if necessary:

$npm install -g @github/copilot

To use the agent in interactive mode:

  1. Start the Copilot CLI:
$copilot
  1. Select the LaunchDarkly agent:
$/agent launchdarkly
  1. Enter a natural language prompt, such as:
    • “Clean up the obsolete feature flag legacy-checkout-flow from this codebase”
    • “Check if the new-dashboard flag is safe to remove”
    • “Create a feature flag for the new authentication feature”

Copilot uses the custom agent rules with the LaunchDarkly API to execute the task and create a PR.

You can also execute agent commands directly from your shell prompt by using the --prompt option. For example:

$copilot --agent=launchdarkly --prompt "Remove the feature flag
>old-navigation and update the code to use the winning variant"

Example agent actions

The custom agent specification file ensures that Copilot performs common flag operations in a safe and organized fashion. For example, if you enter a prompt such as “Check if the flag ‘beta-search-v2’ is safe to remove from the codebase”, the LaunchDarkly agent performs the following actions, in order:

  1. Queries the LaunchDarkly API for flag status across all environments
  2. Checks for dependent flags
  3. Analyzes code usage
  4. Provides a removal readiness assessment
  5. If it is safe to remove the flag, it creates a PR to remove the flag and update code as necessary