Copilotintermediate

How to Use Specialized Agents in GitHub Copilot CLI

Master GitHub Copilot CLI's specialized agents - Explore and Task - to efficiently analyze codebases and execute operations. Learn when to use each agent for optimal results.

7 min readUpdated January 2025

Want us to handle this for you?

Get expert help →

GitHub Copilot CLI includes specialized agents designed to handle specific types of development tasks more efficiently than general prompts. By understanding when and how to use these agents, you can dramatically improve your productivity and get more relevant results.

Overview of the Agent System

Copilot CLI operates as an AI agent capable of autonomous tool use. Rather than handling every request the same way, it routes tasks to specialized agents optimized for particular workflows. The two primary agents you will interact with most frequently are:

  • Explore agent: Analyzes code without modifying anything
  • Task agent: Executes commands and reports results

When you submit a request, Copilot automatically detects whether an agent would be beneficial. You can also explicitly invoke agents when you want precise control over how your request is handled.

The Explore Agent

The Explore agent is designed for codebase analysis and understanding. It reads files, traces code paths, and answers questions about how things work without making any modifications.

Purpose and Capabilities

The Explore agent excels at:

  • Answering architectural questions about your codebase
  • Tracing data flow through applications
  • Finding where specific functionality is implemented
  • Identifying patterns and conventions used in a project
  • Understanding unfamiliar codebases quickly

Most importantly, the Explore agent operates in a separate context from your main conversation. This prevents exploration queries from cluttering your primary working context with irrelevant files and code snippets.

Best Use Cases

Use the Explore agent when you need to:

  • Understand how a feature works before modifying it
  • Find all locations where a function or pattern is used
  • Learn the conventions established in an unfamiliar project
  • Investigate dependencies between components
  • Prepare for a refactoring by understanding impact

Example Queries

copilot

# Understanding architecture
> How does the authentication system work in this codebase?

# Finding implementations
> Where is the payment processing logic implemented?

# Tracing data flow
> Trace how a user request flows from the API endpoint to the database

# Identifying patterns
> What testing patterns does this project use?

# Understanding dependencies
> What external services does the checkout module depend on?

The Explore agent returns answers with relevant code references but does not modify any files or execute commands.

The Task Agent

The Task agent handles command execution, including running tests, builds, and other terminal operations. It is optimized for executing commands and providing intelligent summaries of results.

Purpose and Capabilities

The Task agent is designed to:

  • Run tests and report results concisely
  • Execute build processes and capture output
  • Perform git operations and summarize changes
  • Run security scans and audits
  • Execute any terminal command with intelligent result handling

A key feature is smart output handling: successful commands receive brief summaries, while failures include detailed output and suggested fixes.

Best Use Cases

Use the Task agent when you need to:

  • Run test suites and understand failures
  • Build projects and diagnose errors
  • Check for security vulnerabilities
  • Execute database migrations
  • Perform git operations like rebasing or cherry-picking

Example Operations

copilot

# Running tests
> Run the unit tests for the authentication module

# Building projects
> Build the project in production mode and report any warnings

# Security scanning
> Run npm audit and summarize critical vulnerabilities

# Git operations
> Show me the commits from the last week that touched the API routes

# Database operations
> Run the pending database migrations

The Task agent captures command output, interprets results, and provides actionable summaries rather than raw terminal output.

Choosing Between Agents

Understanding when to use each agent helps you get better results with less context pollution.

ScenarioBest AgentReason
Understanding code before changing itExploreDoes not modify context, focused analysis
Running tests to verify changesTaskCaptures output, provides failure analysis
Finding where a function is definedExploreFast file navigation, no side effects
Building and checking for errorsTaskInterprets build output intelligently
Learning project conventionsExploreSynthesizes patterns from codebase
Checking security vulnerabilitiesTaskRuns scanners, prioritizes findings

When in doubt, describe what you want to accomplish naturally. Copilot automatically routes to the appropriate agent based on your request.

Agent Context Management

One of the most valuable features of the agent system is context isolation. Each agent maintains its own context, preventing exploration from polluting your main conversation.

Why Context Management Matters

When you explore a large codebase through regular prompts, every file read gets added to your conversation context. This consumes tokens rapidly and can confuse the AI by mixing exploration artifacts with your actual working context.

The Explore agent solves this by:

  • Operating in an isolated context window
  • Returning only the relevant answer to your main session
  • Discarding intermediate files and analysis after responding

Monitoring Context Usage

Check your current token usage with the /context command:

copilot> /context
Context usage: 45,000 / 200,000 tokens (22%)
Files in context: 12

If context is getting full, use /compact to compress conversation history or /clear to start fresh.

Background Agent Execution

For longer operations, agents can run in the background while you continue working. This is particularly useful for:

  • Running comprehensive test suites
  • Full project builds
  • Long-running security scans
  • Complex git operations

When an agent runs in the background, you receive a notification upon completion. You can then review the results at your convenience without blocking your workflow.

Combining Agents Effectively

Complex tasks often benefit from multiple agents working together. Copilot can orchestrate agents in parallel for efficiency.

For example, when debugging an issue:

> Debug why login is failing with a 403 error

Copilot may simultaneously:

  1. Use Explore to analyze authentication code
  2. Use Task to run auth-related tests
  3. Correlate findings from both agents

This parallel execution can reduce investigation time significantly compared to sequential analysis.

Sequential Agent Workflows

Sometimes you want explicit control over agent sequencing:

# First, understand the current implementation
> Use explore to show me how rate limiting works

# Then, run tests to verify current behavior
> Run the rate limiter tests

# Finally, make informed changes
> Add IP-based rate limiting to the authentication endpoints

By understanding the code first, your subsequent modifications will be more accurate and contextual.

Tips for Better Agent Results

Be Specific with Explore Queries

Vague questions produce vague answers. Instead of asking "how does this work?", specify what you want to understand:

# Vague
> How does the API work?

# Specific
> How does the API authenticate requests and validate JWT tokens?

Include Context for Task Operations

When running commands that might fail, provide context about what you are trying to accomplish:

# Basic
> Run the tests

# Better
> Run the authentication tests - I just changed the password validation logic

This helps the Task agent provide more relevant failure analysis if tests do not pass.

Use Explicit Agent Invocation When Needed

While Copilot usually routes correctly, you can be explicit when you want guaranteed agent behavior:

# Explicitly use Explore
> Use the explore agent to trace the data flow for order processing

# Explicitly use Task
> Use the task agent to run the full test suite with coverage

Combine with Custom Agents

For specialized workflows, create custom agents that build on the base capabilities. Define them in .github/agents/ to encode team-specific knowledge and conventions.

Next Steps

Frequently Asked Questions

Find answers to common questions

Copilot CLI includes two main agents: Explore (for codebase analysis without modifications) and Task (for executing commands and operations). Each is optimized for its purpose and uses context more efficiently than general prompts.

Need Professional IT & Security Help?

Our team of experts is ready to help protect and optimize your technology infrastructure.