Files
agent-framework/python/samples/02-agents/providers/github_copilot
T
Dineshsuriya D 63c0a51797 Python: Add OpenTelemetry integration for GitHubCopilotAgent (#5142)
* Python: Add OpenTelemetry integration for GitHubCopilotAgent

- Split GitHubCopilotAgent into RawGitHubCopilotAgent (core, no OTel) and
  GitHubCopilotAgent(AgentTelemetryLayer, RawGitHubCopilotAgent) with tracing
- Add default_options property to expose model for span attributes
- Export RawGitHubCopilotAgent from all public namespaces
- Add github_copilot_with_observability.py sample and update README

* Python: Fix OTEL_SERVICE_NAME default in GitHub Copilot README

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Python: Add unit tests for RawGitHubCopilotAgent.default_options property

* Python: Address review feedback on GitHubCopilotAgent OTel integration

- Add middleware param to GitHubCopilotAgent.run() overloads so per-call
  middleware is explicitly forwarded through AgentTelemetryLayer
- Remove github_copilot_with_observability.py sample per feedback; replace
  with inline snippet + link to observability samples in README

* Python: Address review feedback on log_level and session kwargs typing

- Add middleware param to RawGitHubCopilotAgent.run() overloads for interface
  compatibility with AgentTelemetryLayer
- Fix import in README observability snippet to use agent_framework.github

* Python: Add AgentMiddlewareLayer to GitHubCopilotAgent MRO

Follow FoundryAgent pattern: AgentMiddlewareLayer runs outside the telemetry
span so middleware execution time is not captured in traces. Overloads removed
as AgentMiddlewareLayer.run() handles dispatch via MRO.

* Python: Add explicit __init__ to GitHubCopilotAgent for auto-complete and docstrings

* Python: Address review feedback on middleware warning and test assertions

- Add assert "timeout" not in opts to test_default_options_includes_model_for_telemetry
  to document the intentional asymmetry where timeout is extracted into _settings
  and not returned in default_options.
- Replace silent del middleware with a logged warning when per-run middleware is
  passed to RawGitHubCopilotAgent, making it clear that the GitHub Copilot SDK
  handles tool execution internally and chat/function middleware cannot be injected.

* Python: Use Self for __aenter__ return type in RawGitHubCopilotAgent

Address review feedback: use typing.Self (3.11+) / typing_extensions.Self
(3.10) for __aenter__ so subclasses like GitHubCopilotAgent get the correct
return type from async context manager usage.

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
63c0a51797 ยท 2026-04-24 08:44:44 +00:00
History
..

GitHub Copilot Agent Examples

This directory contains examples demonstrating how to use the GitHubCopilotAgent from the Microsoft Agent Framework.

Security Note: These examples demonstrate various permission types (shell, read, write, url). Only enable permissions that are necessary for your use case. Each permission grants the agent additional capabilities that could affect your system.

Prerequisites

  1. GitHub Copilot CLI: Install and authenticate the Copilot CLI
  2. GitHub Copilot Subscription: An active GitHub Copilot subscription
  3. Install the package:
    pip install agent-framework-github-copilot --pre
    

Environment Variables

The following environment variables can be configured:

Variable Description Default
GITHUB_COPILOT_CLI_PATH Path to the Copilot CLI executable copilot
GITHUB_COPILOT_MODEL Model to use (e.g., "gpt-5", "claude-sonnet-4") Server default
GITHUB_COPILOT_TIMEOUT Request timeout in seconds 60
GITHUB_COPILOT_LOG_LEVEL CLI log level info

Observability

GitHubCopilotAgent has OpenTelemetry tracing built-in. To enable it, call configure_otel_providers() before running the agent:

from agent_framework.observability import configure_otel_providers
from agent_framework.github import GitHubCopilotAgent

configure_otel_providers(enable_console_exporters=True)

async with GitHubCopilotAgent() as agent:
    response = await agent.run("Hello!")

See the observability samples for full examples with OTLP exporters.

Examples

File Description
github_copilot_basic.py The simplest way to create an agent using GitHubCopilotAgent. Demonstrates both streaming and non-streaming responses with function tools.
github_copilot_with_session.py Shows session management with automatic creation, persistence via session objects, and resuming sessions by ID.
github_copilot_with_shell.py Shows how to enable shell command execution permissions. Demonstrates running system commands like listing files and getting system information.
github_copilot_with_file_operations.py Shows how to enable file read and write permissions. Demonstrates reading file contents and creating new files.
github_copilot_with_url.py Shows how to enable URL fetching permissions. Demonstrates fetching and processing web content.
github_copilot_with_mcp.py Shows how to configure MCP (Model Context Protocol) servers, including local (stdio) and remote (HTTP) servers.
github_copilot_with_multiple_permissions.py Shows how to combine multiple permission types for complex tasks that require shell, read, and write access.