Skip to content

Load from Copilot Config Files

CopilotAgent.from_copilot_config() builds a CopilotAgent from any directory that contains GitHub Copilot config files — your production project, a dedicated test fixture project, a shared team config repo, or anything else.

What it loads

Source Path (relative to the root you point at) Maps to
Instructions .github/copilot-instructions.md instructions
Custom agents .github/agents/**/*.agent.md (recursive) custom_agents

Agent files are discovered recursively — agents in subagents/ subdirectories (e.g. .github/agents/hve-core/subagents/) are included automatically.

Basic usage

from pytest_codingagents import CopilotAgent

# Current directory (default)
agent = CopilotAgent.from_copilot_config()

# Explicit path
agent = CopilotAgent.from_copilot_config("path/to/any/dir")

A/B testing with your production config

The main use case: use your real config as the baseline and compare against a variant — no duplication needed.

import pytest
from pytest_codingagents import CopilotAgent

@pytest.fixture
def baseline():
    """The actual production Copilot config."""
    return CopilotAgent.from_copilot_config()

@pytest.fixture
def treatment():
    """Same config, one instruction changed."""
    return CopilotAgent.from_copilot_config(
        instructions="Always add type hints to every function.",
    )

Point at any directory

There is no concept of "global" vs "project" — just a path. Point it wherever your config lives:

# Production project
baseline = CopilotAgent.from_copilot_config("/src/my-app")

# Dedicated test fixture project with stricter agents
treatment = CopilotAgent.from_copilot_config("tests/fixtures/strict-agents")

# Shared team config library (checked into a separate repo)
shared = CopilotAgent.from_copilot_config("/shared/team/copilot-config")

Override fields after loading

Any keyword argument overrides the loaded value:

# Load from the current project but force a specific model
agent = CopilotAgent.from_copilot_config(model="claude-opus-4.5")

# Load from a different path and override instructions
agent = CopilotAgent.from_copilot_config(
    "tests/fixtures/baseline",
    instructions="Tightened: always add type hints.",
)

Custom agent file format

Custom agents are defined in .agent.md files with optional YAML frontmatter:

---
name: test-specialist
description: Focuses on test coverage and quality
tools:
  - read
  - search
  - edit
---

You are a testing specialist. Your responsibilities:

- Analyse existing tests and identify coverage gaps
- Write unit and integration tests following best practices
- Focus only on test files; do not modify production code

The frontmatter supports name, description, tools, and mcp-servers. The Markdown body becomes the agent's prompt.

See also