SRO.AI.Copilot 1.0.1

IFI.AI.Copilot

A simplified, multi-platform .NET API for interfacing with the GitHub Copilot CLI, providing transactional prompt-response interactions with Copilot.

Overview

IFI.AI.Copilot is a streamlined alternative to the GitHub.Copilot.SDK that offers:

  • Simplified API: Easy-to-use interface with minimal complexity
  • Multi-Platform Support: Compatible with both .NET Framework (4.7.2, 4.8) and .NET Core (.NET 8.0)
  • Straightforward Integration: Just three steps - construct, initialize, and send

Key Features

  • Simple API Surface: No complex configurations or extensive setup required
  • Cross-Platform Compatibility: Works across multiple .NET versions
  • Conversation History: Automatically maintains context across messages
  • Event-Driven Logging: Subscribe to diagnostic and logging events
  • Async/Await Support: Full support for asynchronous operations
  • Thread-Safe: Built with thread-safety in mind for multi-threaded applications

Prerequisites

  • GitHub Copilot CLI installed and accessible in your system PATH
  • Valid GitHub Copilot subscription
  • .NET Framework 4.7.2/4.8 or .NET 8.0+

Installation

Install via NuGet Package Manager:

dotnet add package IFI.AI.Copilot

Or via Package Manager Console:

Install-Package IFI.AI.Copilot

Quick Start

Basic Usage

using IFI.AI.Copilot;

// Create a new client
var copilotClient = new GitHubCopilotClient();

// Initialize the connection
copilotClient.Initialize();

// Send a message and get a response
string response = copilotClient.Send("What is the capital of France?");
Console.WriteLine(response);

// Don't forget to dispose when done
copilotClient.Dispose();

Async Usage

using IFI.AI.Copilot;

var copilotClient = new GitHubCopilotClient();
copilotClient.Initialize();

// Send messages asynchronously
string response = await copilotClient.SendAsync("Explain async/await in C#");
Console.WriteLine(response);

copilotClient.Dispose();
using (var copilotClient = new GitHubCopilotClient())
{
    copilotClient.Initialize();
    
    var response = copilotClient.Send("Write a hello world function in C#");
    Console.WriteLine(response);
}

API Reference

GitHubCopilotClient Class

The main class for interacting with the GitHub Copilot CLI.

Constructor

public GitHubCopilotClient()

Creates a new instance of the GitHub Copilot client.

Methods

Initialize
public void Initialize(int timeoutMilliseconds = 120000)

Initializes the GitHub Copilot Connector, including starting the GitHub Copilot CLI process and setting up the JSON-RPC communication channel.

Parameters:

  • timeoutMilliseconds (optional): Timeout for operations in milliseconds. Default is 120000 (2 minutes).
Send
public string Send(string message)

Sends a message to the GitHub Copilot CLI synchronously and returns the response.

Parameters:

  • message: The message to send to GitHub Copilot.

Returns: The response from GitHub Copilot.

Throws:

  • ArgumentException: If the message is null or empty.
  • InvalidOperationException: If the connection is not established.
  • CopilotException: If an error occurs while communicating with Copilot.
SendAsync
public async Task<string> SendAsync(string message)

Sends a message to the GitHub Copilot CLI asynchronously and returns the response.

Parameters:

  • message: The message to send to GitHub Copilot.

Returns: A task containing the response from GitHub Copilot.

Throws:

  • ArgumentException: If the message is null or empty.
  • InvalidOperationException: If the connection is not established.
  • TimeoutException: If the operation times out.
  • CopilotException: If an error occurs while communicating with Copilot.
Dispose
public void Dispose()

Releases all resources used by the GitHubCopilotClient. Always call this when finished with the client or use a using statement.

Properties

TimeoutMilliseconds
public int TimeoutMilliseconds { get; set; }

Gets or sets the timeout in milliseconds for communication operations. Default is 120000 (2 minutes).

IsInitialized
public bool IsInitialized { get; }

Gets a value indicating whether the session has been initialized.

IsConnected
public bool IsConnected { get; }

Gets a value indicating whether the JSON-RPC connection is active and ready for communication.

SessionId
public string SessionId { get; }

Gets the current session ID for the GitHub Copilot CLI conversation.

ConversationHistory
public List<ChatMessage> ConversationHistory { get; }

Gets the conversation history, which maintains context across multiple messages.

CopilotProcess
public Process CopilotProcess { get; }

Gets the GitHub Copilot CLI process instance.

Events

MessageSent
public event EventHandler<MessageSentEventArgs> MessageSent;

Raised when a message is sent from the GitHub Copilot Connector, such as log messages, errors, or diagnostic information.

Example:

copilotClient.MessageSent += (sender, args) =>
{
    switch (args.LogLevel)
    {
        case MessageLogLevel.Info:
            Console.WriteLine($"INFO: {args.Message}");
            break;
        case MessageLogLevel.Warning:
            Console.WriteLine($"WARNING: {args.Message}");
            break;
        case MessageLogLevel.Error:
            Console.WriteLine($"ERROR: {args.Message}");
            break;
    }
};

Supporting Classes

ChatMessage

Represents a message in the conversation history.

public class ChatMessage
{
    public string Role { get; set; }        // "user", "assistant", or "system"
    public string Content { get; set; }     // Message content
    public DateTime Timestamp { get; set; } // When the message was sent
}

MessageSentEventArgs

Event arguments for the MessageSent event.

public class MessageSentEventArgs : EventArgs
{
    public string Message { get; set; }
    public MessageLogLevel LogLevel { get; set; }
}

MessageLogLevel Enum

Log level for diagnostic messages.

public enum MessageLogLevel
{
    Verbose = 0,  // Debug-level messages
    Info = 1,     // Informational messages
    Warning = 2,  // Warning messages
    Error = 3     // Error messages
}

Exceptions

CopilotException

Custom exception thrown when errors occur during Copilot communication.

public class CopilotException : Exception
{
    public CopilotException(string message);
    public CopilotException(string message, Exception innerException);
}

Advanced Usage

With Event Logging

using (var copilotClient = new GitHubCopilotClient())
{
    // Subscribe to logging events
    copilotClient.MessageSent += (sender, args) =>
    {
        Console.WriteLine($"[{args.LogLevel}] {args.Message}");
    };
    
    copilotClient.Initialize();
    
    string response = copilotClient.Send("Explain dependency injection");
    Console.WriteLine(response);
}

Custom Timeout

using (var copilotClient = new GitHubCopilotClient())
{
    // Set a custom timeout of 5 minutes
    copilotClient.Initialize(timeoutMilliseconds: 300000);
    
    string response = copilotClient.Send("Generate a complex algorithm");
    Console.WriteLine(response);
}

Multiple Conversations

using (var copilotClient = new GitHubCopilotClient())
{
    copilotClient.Initialize();
    
    // First message
    var response1 = copilotClient.Send("What is C#?");
    Console.WriteLine(response1);
    
    // Follow-up message (maintains context)
    var response2 = copilotClient.Send("Can you give me an example?");
    Console.WriteLine(response2);
    
    // Check conversation history
    Console.WriteLine($"Total messages: {copilotClient.ConversationHistory.Count}");
}

Error Handling

using (var copilotClient = new GitHubCopilotClient())
{
    try
    {
        copilotClient.Initialize();
        string response = await copilotClient.SendAsync("Your prompt here");
        Console.WriteLine(response);
    }
    catch (CopilotException ex)
    {
        Console.WriteLine($"Copilot error: {ex.Message}");
        if (ex.InnerException != null)
        {
            Console.WriteLine($"Inner exception: {ex.InnerException.Message}");
        }
    }
    catch (TimeoutException ex)
    {
        Console.WriteLine($"Operation timed out: {ex.Message}");
    }
    catch (ArgumentException ex)
    {
        Console.WriteLine($"Invalid argument: {ex.Message}");
    }
}

Best Practices

  1. Always Dispose: Use using statements or explicitly call Dispose() when finished
  2. Handle Exceptions: Wrap calls in try-catch blocks to handle potential errors gracefully
  3. Set Appropriate Timeouts: Adjust the timeout based on your expected response times
  4. Monitor Events: Subscribe to the MessageSent event for debugging and diagnostics
  5. Check Connection: Use IsConnected and IsInitialized properties to verify state
  6. Maintain Context: The API automatically maintains conversation history for contextual responses

Troubleshooting

GitHub Copilot CLI Not Found

Ensure that the GitHub Copilot CLI is installed and accessible in your system PATH. You can verify by running:

copilot --version

Connection Timeout

If you're experiencing timeouts, try increasing the timeout value:

copilotClient.Initialize(timeoutMilliseconds: 300000); // 5 minutes

Invalid Operation Exception

Ensure you call Initialize() before sending messages:

var client = new GitHubCopilotClient();
client.Initialize(); // Must call before Send()
var response = client.Send("Your message");

Dependencies

This package uses the following key dependencies:

  • StreamJsonRpc - For JSON-RPC communication
  • Newtonsoft.Json - For JSON serialization
  • MessagePack - For efficient binary serialization
  • Microsoft.VisualStudio.Threading - For async/await utilities

License

Copyright © 2026 Indiana Farmers Mutual Insurance Group

Support

For issues, questions, or contributions, please contact the IFI.AI development team.

Version History

1.0.0

  • Initial release
  • Multi-platform support (.NET Framework 4.7.2/4.8 and .NET 8.0)
  • Simple three-step API (construct, initialize, send)
  • Conversation history management
  • Event-driven logging
  • Full async/await support

No packages depend on SRO.AI.Copilot.

.NET Framework 4.7.2

.NET Framework 4.8

.NET 8.0

Version Downloads Last updated
1.0.1 8 09/03/2026