|
| 1 | +--- |
| 2 | +title: Invoking custom agents |
| 3 | +shortTitle: Invoke custom agents |
| 4 | +intro: Use custom agents, skills, and MCP servers in {% data variables.copilot.copilot_cli_short %} to extend its capabilities. |
| 5 | +product: '{% data reusables.gated-features.copilot-cli %}' |
| 6 | +versions: |
| 7 | + feature: copilot |
| 8 | +topics: |
| 9 | + - Copilot |
| 10 | +contentType: how-tos |
| 11 | +category: |
| 12 | + - Build with Copilot CLI |
| 13 | +--- |
| 14 | + |
| 15 | +## Use {% data variables.copilot.custom_agents_short %} |
| 16 | + |
| 17 | +A {% data variables.copilot.copilot_custom_agent_short %} is a specialized version of {% data variables.product.prodname_copilot_short %}. {% data variables.copilot.custom_agents_caps_short %} help {% data variables.product.prodname_copilot_short %} handle unique workflows, particular coding conventions, and specialist use cases. |
| 18 | + |
| 19 | +{% data variables.copilot.copilot_cli_short %} includes a default group of {% data variables.copilot.custom_agents_short %} for common tasks: |
| 20 | + |
| 21 | +<table> |
| 22 | + <thead> |
| 23 | + <tr> |
| 24 | + <th style="width:20%">Agent</th> |
| 25 | + <th>Description</th> |
| 26 | + </tr> |
| 27 | + </thead> |
| 28 | + <tbody> |
| 29 | + <tr> |
| 30 | + <td>Explore</td> |
| 31 | + <td>Performs quick codebase analysis, allowing you to ask questions about your code without adding to your main context.</td> |
| 32 | + </tr> |
| 33 | + <tr> |
| 34 | + <td>Task</td> |
| 35 | + <td>Executes commands such as tests and builds, providing brief summaries on success and full output on failure.</td> |
| 36 | + </tr> |
| 37 | + <tr> |
| 38 | + <td>General-purpose</td> |
| 39 | + <td>Handles complex, multi-step tasks that require the full toolset and high-quality reasoning, running in a separate context to keep your main conversation clearly focused.</td> |
| 40 | + </tr> |
| 41 | + <tr> |
| 42 | + <td>Code-review</td> |
| 43 | + <td>Reviews changes with a focus on surfacing only genuine issues, minimizing noise.</td> |
| 44 | + </tr> |
| 45 | + </tbody> |
| 46 | +</table> |
| 47 | + |
| 48 | +The AI model being used by the CLI can choose to delegate a task to a subsidiary subagent process, that operates using a {% data variables.copilot.copilot_custom_agent_short %} with specific expertise, if it judges that this would result in the work being completed more effectively. The model may equally choose to handle the work directly in the main agent. |
| 49 | + |
| 50 | +You can define your own {% data variables.copilot.custom_agents_short %} using Markdown files, called {% data variables.copilot.agent_profiles %}, that specify what expertise the agent should have, what tools it can use, and any specific instructions for how it should respond. |
| 51 | + |
| 52 | +You can define {% data variables.copilot.custom_agents_short %} at the user, repository, or organization/enterprise level: |
| 53 | + |
| 54 | +| Type | Location | Scope | |
| 55 | +| --- | --- | --- | |
| 56 | +| User-level {% data variables.copilot.copilot_custom_agent_short %} | local `~/.copilot/agents` directory | All projects | |
| 57 | +| Repository-level {% data variables.copilot.copilot_custom_agent_short %} | `.github/agents` directory in your local and remote repositories | Current project | |
| 58 | +| Organization and Enterprise-level {% data variables.copilot.copilot_custom_agent_short %} | `/agents` directory in the `.github-private` repository in an organization or enterprise | All projects under your organization and enterprise account | |
| 59 | + |
| 60 | +In the case of naming conflicts, a system-level agent overrides a repository-level agent, and the repository-level agent would override an organization-level agent. |
| 61 | + |
| 62 | +{% data variables.copilot.custom_agents_caps_short %} can be used in three ways: |
| 63 | + |
| 64 | +* Using the slash command in the CLI's interactive interface to select from the list of available {% data variables.copilot.custom_agents_short %}: |
| 65 | + |
| 66 | + ```shell |
| 67 | + /agent |
| 68 | + ``` |
| 69 | + |
| 70 | +* Calling out to the {% data variables.copilot.copilot_custom_agent_short %} directly in a prompt: |
| 71 | + |
| 72 | + ```shell |
| 73 | + Use the refactoring agent to refactor this code block |
| 74 | + ``` |
| 75 | + |
| 76 | + {% data variables.product.prodname_copilot_short %} will automatically infer the agent you want to use. |
| 77 | + |
| 78 | +* Specifying the {% data variables.copilot.copilot_custom_agent_short %} you want to use with the command-line option. For example: |
| 79 | + |
| 80 | + ```shell |
| 81 | + copilot --agent=refactor-agent --prompt "Refactor this code block" |
| 82 | + ``` |
| 83 | + |
| 84 | +For more information, see [AUTOTITLE](/copilot/how-tos/use-copilot-agents/coding-agent/create-custom-agents). |
| 85 | + |
| 86 | +## Use skills |
| 87 | + |
| 88 | +You can create skills to enhance the ability of {% data variables.product.prodname_copilot_short %} to perform specialized tasks with instructions, scripts, and resources. |
| 89 | + |
| 90 | +For more information, see [AUTOTITLE](/copilot/how-tos/copilot-cli/customize-copilot/create-skills). |
| 91 | + |
| 92 | +## Add an MCP server |
| 93 | + |
| 94 | +{% data variables.copilot.copilot_cli_short %} comes with the {% data variables.product.github %} MCP server already configured. This MCP server allows you to interact with resources on {% data variables.product.prodname_dotcom_the_website %}—for example, allowing you to merge pull requests from the CLI. |
| 95 | + |
| 96 | +To extend the functionality available to you in {% data variables.copilot.copilot_cli_short %}, you can add more MCP servers: |
| 97 | + |
| 98 | +1. Use the following slash command: |
| 99 | + |
| 100 | + ```shell |
| 101 | + /mcp add |
| 102 | + ``` |
| 103 | + |
| 104 | +1. Fill in the details for the MCP server you want to add, using the <kbd>Tab</kbd> key to move between fields. |
| 105 | +1. Press <kbd>Ctrl</kbd>+<kbd>S</kbd> to save the details. |
| 106 | + |
| 107 | +Details of your configured MCP servers are stored in the `mcp-config.json` file, which is located, by default, in the `~/.copilot` directory. This location can be changed by setting the `XDG_CONFIG_HOME` environment variable. For information about the JSON structure of a server definition, see [AUTOTITLE](/copilot/how-tos/use-copilot-agents/coding-agent/extend-coding-agent-with-mcp#writing-a-json-configuration-for-mcp-servers). |
| 108 | + |
| 109 | +For more detailed information on adding and managing MCP servers in {% data variables.copilot.copilot_cli_short %}, see [AUTOTITLE](/copilot/how-tos/copilot-cli/customize-copilot/add-mcp-servers). |
| 110 | + |
| 111 | +## Next steps |
| 112 | + |
| 113 | +To learn how to guide and refine agent behavior during task execution to keep work on track, see [AUTOTITLE](/copilot/how-tos/copilot-cli/use-copilot-cli-agents/steer-agents). |
0 commit comments