-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathCopilotClientExtensions.cs
More file actions
73 lines (67 loc) · 3.1 KB
/
CopilotClientExtensions.cs
File metadata and controls
73 lines (67 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) Microsoft. All rights reserved.
using System.Collections.Generic;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.GithubCopilot;
using Microsoft.Extensions.AI;
using Microsoft.Shared.Diagnostics;
namespace GitHub.Copilot.SDK;
/// <summary>
/// Provides extension methods for <see cref="CopilotClient"/>
/// to simplify the creation of GitHub Copilot agents.
/// </summary>
/// <remarks>
/// These extensions bridge the gap between GitHub Copilot SDK client objects
/// and the Microsoft Agent Framework.
/// <para>
/// They allow developers to easily create AI agents that can interact
/// with GitHub Copilot by handling the conversion from Copilot clients to
/// <see cref="GithubCopilotAgent"/> instances that implement the <see cref="AIAgent"/> interface.
/// </para>
/// </remarks>
public static class CopilotClientExtensions
{
/// <summary>
/// Retrieves an instance of <see cref="AIAgent"/> for a GitHub Copilot client.
/// </summary>
/// <param name="client">The <see cref="CopilotClient"/> to use for the agent.</param>
/// <param name="sessionConfig">Optional session configuration for the agent.</param>
/// <param name="ownsClient">Whether the agent owns the client and should dispose it. Default is false.</param>
/// <param name="id">The unique identifier for the agent.</param>
/// <param name="name">The name of the agent.</param>
/// <param name="description">The description of the agent.</param>
/// <returns>An <see cref="AIAgent"/> instance backed by the GitHub Copilot client.</returns>
public static AIAgent AsAIAgent(
this CopilotClient client,
SessionConfig? sessionConfig = null,
bool ownsClient = false,
string? id = null,
string? name = null,
string? description = null)
{
Throw.IfNull(client);
return new GithubCopilotAgent(client, sessionConfig, ownsClient, id, name, description);
}
/// <summary>
/// Retrieves an instance of <see cref="AIAgent"/> for a GitHub Copilot client.
/// </summary>
/// <param name="client">The <see cref="CopilotClient"/> to use for the agent.</param>
/// <param name="ownsClient">Whether the agent owns the client and should dispose it. Default is false.</param>
/// <param name="id">The unique identifier for the agent.</param>
/// <param name="name">The name of the agent.</param>
/// <param name="description">The description of the agent.</param>
/// <param name="tools">The tools to make available to the agent.</param>
/// <param name="instructions">Optional instructions to append as a system message.</param>
/// <returns>An <see cref="AIAgent"/> instance backed by the GitHub Copilot client.</returns>
public static AIAgent AsAIAgent(
this CopilotClient client,
bool ownsClient = false,
string? id = null,
string? name = null,
string? description = null,
IList<AITool>? tools = null,
string? instructions = null)
{
Throw.IfNull(client);
return new GithubCopilotAgent(client, ownsClient, id, name, description, tools, instructions);
}
}