mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET: Update GitHub.Copilot.SDK to 0.1.23 and copy new session config prope… (#3788)
* Update GitHub.Copilot.SDK to 0.1.23 and copy new session config properties - Bump GitHub.Copilot.SDK from 0.1.18 to 0.1.23 - Add new SessionConfig properties: ReasoningEffort, Hooks, OnUserInputRequest, WorkingDirectory, ConfigDir, InfiniteSessions - Add missing ResumeSessionConfig properties: Model, SystemMessage, AvailableTools, ExcludedTools, ReasoningEffort, Hooks, OnUserInputRequest, WorkingDirectory, ConfigDir, InfiniteSessions - Fix UserMessageDataAttachmentsItem -> UserMessageDataAttachmentsItemFile for new polymorphic attachment API - Add unit tests for new session config properties * Address PR review: centralize config mapping and improve test coverage - Extract CopySessionConfig/CopyResumeSessionConfig as internal static helpers to eliminate duplicated mapping logic between RunCoreStreamingAsync and CreateResumeConfig (addresses reviewer comment on drift risk) - Add InternalsVisibleTo for unit test project - Replace shallow constructor tests with comprehensive property-verification tests that validate every config property is correctly copied, including OnUserInputRequest (addresses reviewer comments on test coverage) * Remove accidentally committed git-lfs hooks
This commit is contained in:
committed by
GitHub
Unverified
parent
a2856d3b92
commit
0c67dbbce5
@@ -89,7 +89,7 @@
|
||||
<PackageVersion Include="Microsoft.SemanticKernel.Agents.AzureAI" Version="1.67.0-preview" />
|
||||
<PackageVersion Include="Microsoft.SemanticKernel.Plugins.OpenApi" Version="1.67.0" />
|
||||
<!-- Agent SDKs -->
|
||||
<PackageVersion Include="GitHub.Copilot.SDK" Version="0.1.18" />
|
||||
<PackageVersion Include="GitHub.Copilot.SDK" Version="0.1.23" />
|
||||
<PackageVersion Include="Microsoft.Agents.CopilotStudio.Client" Version="1.3.171-beta" />
|
||||
<!-- M365 Agents SDK -->
|
||||
<PackageVersion Include="AdaptiveCards" Version="3.1.0" />
|
||||
|
||||
@@ -147,21 +147,7 @@ public sealed class GitHubCopilotAgent : AIAgent, IAsyncDisposable
|
||||
|
||||
// Create or resume a session with streaming enabled
|
||||
SessionConfig sessionConfig = this._sessionConfig != null
|
||||
? new SessionConfig
|
||||
{
|
||||
Model = this._sessionConfig.Model,
|
||||
Tools = this._sessionConfig.Tools,
|
||||
SystemMessage = this._sessionConfig.SystemMessage,
|
||||
AvailableTools = this._sessionConfig.AvailableTools,
|
||||
ExcludedTools = this._sessionConfig.ExcludedTools,
|
||||
Provider = this._sessionConfig.Provider,
|
||||
OnPermissionRequest = this._sessionConfig.OnPermissionRequest,
|
||||
McpServers = this._sessionConfig.McpServers,
|
||||
CustomAgents = this._sessionConfig.CustomAgents,
|
||||
SkillDirectories = this._sessionConfig.SkillDirectories,
|
||||
DisabledSkills = this._sessionConfig.DisabledSkills,
|
||||
Streaming = true
|
||||
}
|
||||
? CopySessionConfig(this._sessionConfig)
|
||||
: new SessionConfig { Streaming = true };
|
||||
|
||||
CopilotSession copilotSession;
|
||||
@@ -283,16 +269,64 @@ public sealed class GitHubCopilotAgent : AIAgent, IAsyncDisposable
|
||||
}
|
||||
|
||||
private ResumeSessionConfig CreateResumeConfig()
|
||||
{
|
||||
return CopyResumeSessionConfig(this._sessionConfig);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies all supported properties from a source <see cref="SessionConfig"/> into a new instance
|
||||
/// with <see cref="SessionConfig.Streaming"/> set to <c>true</c>.
|
||||
/// </summary>
|
||||
internal static SessionConfig CopySessionConfig(SessionConfig source)
|
||||
{
|
||||
return new SessionConfig
|
||||
{
|
||||
Model = source.Model,
|
||||
ReasoningEffort = source.ReasoningEffort,
|
||||
Tools = source.Tools,
|
||||
SystemMessage = source.SystemMessage,
|
||||
AvailableTools = source.AvailableTools,
|
||||
ExcludedTools = source.ExcludedTools,
|
||||
Provider = source.Provider,
|
||||
OnPermissionRequest = source.OnPermissionRequest,
|
||||
OnUserInputRequest = source.OnUserInputRequest,
|
||||
Hooks = source.Hooks,
|
||||
WorkingDirectory = source.WorkingDirectory,
|
||||
ConfigDir = source.ConfigDir,
|
||||
McpServers = source.McpServers,
|
||||
CustomAgents = source.CustomAgents,
|
||||
SkillDirectories = source.SkillDirectories,
|
||||
DisabledSkills = source.DisabledSkills,
|
||||
InfiniteSessions = source.InfiniteSessions,
|
||||
Streaming = true
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies all supported properties from a source <see cref="SessionConfig"/> into a new
|
||||
/// <see cref="ResumeSessionConfig"/> with <see cref="ResumeSessionConfig.Streaming"/> set to <c>true</c>.
|
||||
/// </summary>
|
||||
internal static ResumeSessionConfig CopyResumeSessionConfig(SessionConfig? source)
|
||||
{
|
||||
return new ResumeSessionConfig
|
||||
{
|
||||
Tools = this._sessionConfig?.Tools,
|
||||
Provider = this._sessionConfig?.Provider,
|
||||
OnPermissionRequest = this._sessionConfig?.OnPermissionRequest,
|
||||
McpServers = this._sessionConfig?.McpServers,
|
||||
CustomAgents = this._sessionConfig?.CustomAgents,
|
||||
SkillDirectories = this._sessionConfig?.SkillDirectories,
|
||||
DisabledSkills = this._sessionConfig?.DisabledSkills,
|
||||
Model = source?.Model,
|
||||
ReasoningEffort = source?.ReasoningEffort,
|
||||
Tools = source?.Tools,
|
||||
SystemMessage = source?.SystemMessage,
|
||||
AvailableTools = source?.AvailableTools,
|
||||
ExcludedTools = source?.ExcludedTools,
|
||||
Provider = source?.Provider,
|
||||
OnPermissionRequest = source?.OnPermissionRequest,
|
||||
OnUserInputRequest = source?.OnUserInputRequest,
|
||||
Hooks = source?.Hooks,
|
||||
WorkingDirectory = source?.WorkingDirectory,
|
||||
ConfigDir = source?.ConfigDir,
|
||||
McpServers = source?.McpServers,
|
||||
CustomAgents = source?.CustomAgents,
|
||||
SkillDirectories = source?.SkillDirectories,
|
||||
DisabledSkills = source?.DisabledSkills,
|
||||
InfiniteSessions = source?.InfiniteSessions,
|
||||
Streaming = true
|
||||
};
|
||||
}
|
||||
@@ -427,9 +461,8 @@ public sealed class GitHubCopilotAgent : AIAgent, IAsyncDisposable
|
||||
string tempFilePath = await dataContent.SaveToAsync(tempDir, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
attachments ??= [];
|
||||
attachments.Add(new UserMessageDataAttachmentsItem
|
||||
attachments.Add(new UserMessageDataAttachmentsItemFile
|
||||
{
|
||||
Type = UserMessageDataAttachmentsItemType.File,
|
||||
Path = tempFilePath,
|
||||
DisplayName = Path.GetFileName(tempFilePath)
|
||||
});
|
||||
|
||||
+4
@@ -17,6 +17,10 @@
|
||||
<ProjectReference Include="..\Microsoft.Agents.AI.Abstractions\Microsoft.Agents.AI.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="Microsoft.Agents.AI.GitHub.Copilot.UnitTests" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GitHub.Copilot.SDK" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -100,4 +100,125 @@ public sealed class GitHubCopilotAgentTests
|
||||
Assert.NotNull(agent);
|
||||
Assert.NotNull(agent.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopySessionConfig_CopiesAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
List<AIFunction> tools = [AIFunctionFactory.Create(() => "test", "TestFunc", "Test function")];
|
||||
var hooks = new SessionHooks();
|
||||
var infiniteSessions = new InfiniteSessionConfig();
|
||||
var systemMessage = new SystemMessageConfig { Mode = SystemMessageMode.Append, Content = "Be helpful" };
|
||||
PermissionHandler permissionHandler = (_, _) => Task.FromResult(new PermissionRequestResult());
|
||||
UserInputHandler userInputHandler = (_, _) => Task.FromResult(new UserInputResponse { Answer = "input" });
|
||||
var mcpServers = new Dictionary<string, object> { ["server1"] = new McpLocalServerConfig() };
|
||||
|
||||
var source = new SessionConfig
|
||||
{
|
||||
Model = "gpt-4o",
|
||||
ReasoningEffort = "high",
|
||||
Tools = tools,
|
||||
SystemMessage = systemMessage,
|
||||
AvailableTools = ["tool1", "tool2"],
|
||||
ExcludedTools = ["tool3"],
|
||||
WorkingDirectory = "/workspace",
|
||||
ConfigDir = "/config",
|
||||
Hooks = hooks,
|
||||
InfiniteSessions = infiniteSessions,
|
||||
OnPermissionRequest = permissionHandler,
|
||||
OnUserInputRequest = userInputHandler,
|
||||
McpServers = mcpServers,
|
||||
DisabledSkills = ["skill1"],
|
||||
};
|
||||
|
||||
// Act
|
||||
SessionConfig result = GitHubCopilotAgent.CopySessionConfig(source);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("gpt-4o", result.Model);
|
||||
Assert.Equal("high", result.ReasoningEffort);
|
||||
Assert.Same(tools, result.Tools);
|
||||
Assert.Same(systemMessage, result.SystemMessage);
|
||||
Assert.Equal(new List<string> { "tool1", "tool2" }, result.AvailableTools);
|
||||
Assert.Equal(new List<string> { "tool3" }, result.ExcludedTools);
|
||||
Assert.Equal("/workspace", result.WorkingDirectory);
|
||||
Assert.Equal("/config", result.ConfigDir);
|
||||
Assert.Same(hooks, result.Hooks);
|
||||
Assert.Same(infiniteSessions, result.InfiniteSessions);
|
||||
Assert.Same(permissionHandler, result.OnPermissionRequest);
|
||||
Assert.Same(userInputHandler, result.OnUserInputRequest);
|
||||
Assert.Same(mcpServers, result.McpServers);
|
||||
Assert.Equal(new List<string> { "skill1" }, result.DisabledSkills);
|
||||
Assert.True(result.Streaming);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyResumeSessionConfig_CopiesAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
List<AIFunction> tools = [AIFunctionFactory.Create(() => "test", "TestFunc", "Test function")];
|
||||
var hooks = new SessionHooks();
|
||||
var infiniteSessions = new InfiniteSessionConfig();
|
||||
var systemMessage = new SystemMessageConfig { Mode = SystemMessageMode.Append, Content = "Be helpful" };
|
||||
PermissionHandler permissionHandler = (_, _) => Task.FromResult(new PermissionRequestResult());
|
||||
UserInputHandler userInputHandler = (_, _) => Task.FromResult(new UserInputResponse { Answer = "input" });
|
||||
var mcpServers = new Dictionary<string, object> { ["server1"] = new McpLocalServerConfig() };
|
||||
|
||||
var source = new SessionConfig
|
||||
{
|
||||
Model = "gpt-4o",
|
||||
ReasoningEffort = "high",
|
||||
Tools = tools,
|
||||
SystemMessage = systemMessage,
|
||||
AvailableTools = ["tool1", "tool2"],
|
||||
ExcludedTools = ["tool3"],
|
||||
WorkingDirectory = "/workspace",
|
||||
ConfigDir = "/config",
|
||||
Hooks = hooks,
|
||||
InfiniteSessions = infiniteSessions,
|
||||
OnPermissionRequest = permissionHandler,
|
||||
OnUserInputRequest = userInputHandler,
|
||||
McpServers = mcpServers,
|
||||
DisabledSkills = ["skill1"],
|
||||
};
|
||||
|
||||
// Act
|
||||
ResumeSessionConfig result = GitHubCopilotAgent.CopyResumeSessionConfig(source);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("gpt-4o", result.Model);
|
||||
Assert.Equal("high", result.ReasoningEffort);
|
||||
Assert.Same(tools, result.Tools);
|
||||
Assert.Same(systemMessage, result.SystemMessage);
|
||||
Assert.Equal(new List<string> { "tool1", "tool2" }, result.AvailableTools);
|
||||
Assert.Equal(new List<string> { "tool3" }, result.ExcludedTools);
|
||||
Assert.Equal("/workspace", result.WorkingDirectory);
|
||||
Assert.Equal("/config", result.ConfigDir);
|
||||
Assert.Same(hooks, result.Hooks);
|
||||
Assert.Same(infiniteSessions, result.InfiniteSessions);
|
||||
Assert.Same(permissionHandler, result.OnPermissionRequest);
|
||||
Assert.Same(userInputHandler, result.OnUserInputRequest);
|
||||
Assert.Same(mcpServers, result.McpServers);
|
||||
Assert.Equal(new List<string> { "skill1" }, result.DisabledSkills);
|
||||
Assert.True(result.Streaming);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CopyResumeSessionConfig_WithNullSource_ReturnsDefaults()
|
||||
{
|
||||
// Act
|
||||
ResumeSessionConfig result = GitHubCopilotAgent.CopyResumeSessionConfig(null);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result.Model);
|
||||
Assert.Null(result.ReasoningEffort);
|
||||
Assert.Null(result.Tools);
|
||||
Assert.Null(result.SystemMessage);
|
||||
Assert.Null(result.OnPermissionRequest);
|
||||
Assert.Null(result.OnUserInputRequest);
|
||||
Assert.Null(result.Hooks);
|
||||
Assert.Null(result.WorkingDirectory);
|
||||
Assert.Null(result.ConfigDir);
|
||||
Assert.True(result.Streaming);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user