Skip to content

Comments

feat: AgentChat.NET Agents#5837

Open
lokitoth wants to merge 5 commits intomainfrom
dev/agentchat_dotnet_agents
Open

feat: AgentChat.NET Agents#5837
lokitoth wants to merge 5 commits intomainfrom
dev/agentchat_dotnet_agents

Conversation

@lokitoth
Copy link
Member

@lokitoth lokitoth commented Mar 5, 2025

Implements the pre-defined AgentChat agents: Assistant, CodeExecutor, CodingAssistant, SocietOfMind, and UserProxy, based on their Python counterparts.

Closes #5802

@lokitoth lokitoth changed the title feat: AgentChat Agents feat: AgentChat.NET Agents Mar 5, 2025
@codecov
Copy link

codecov bot commented Mar 5, 2025

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 70.14%. Comparing base (05b14f1) to head (5181f28).
Report is 223 commits behind head on main.

Files with missing lines Patch % Lines
...t/src/Microsoft.AutoGen/Contracts/ICodeExecutor.cs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5837      +/-   ##
==========================================
- Coverage   70.16%   70.14%   -0.02%     
==========================================
  Files         262      263       +1     
  Lines       14712    14716       +4     
  Branches      243      243              
==========================================
  Hits        10322    10322              
- Misses       4200     4204       +4     
  Partials      190      190              
Flag Coverage Δ
unittests 70.14% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lokitoth lokitoth force-pushed the dev/agentchat_dotnet_agents branch 2 times, most recently from 7f1752a to 357cac8 Compare March 5, 2025 14:43
@lokitoth lokitoth requested a review from Copilot March 5, 2025 15:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR implements five new AgentChat agents for the .NET project, mirroring existing Python agents. Key changes include new agent implementations (CodeExecutorAgent, UserProxyAgent, SocietyOfMindAgent, CodingAssistantAgent, and AssistantAgent), additions to shared abstractions (PromptTemplate, ICodeExecutor), and a new ToolManager component for tool/handoff handling.

Reviewed Changes

File Description
dotnet/src/Microsoft.AutoGen/AgentChat/Agents/CodeExecutorAgent.cs Implements an agent to execute code blocks and return results (note a logic error in response construction and non‐standard collection initialization).
dotnet/src/Microsoft.AutoGen/AgentChat/Agents/UserProxyAgent.cs Introduces an agent that proxies user input with custom async conversion (collection initializer syntax is used).
dotnet/src/Microsoft.AutoGen/AgentChat/Abstractions/PromptTemplate.cs Implements a message templating mechanism with parameter checking and formatting (contains an invalid list initializer).
dotnet/src/Microsoft.AutoGen/Contracts/ICodeExecutor.cs Defines code execution contracts and related types (includes a typo in documentation).
dotnet/src/Microsoft.AutoGen/AgentChat/Agents/SocietyOfMindAgent.cs Provides an agent to manage conversation streams and handoffs (contains several instances of non‐standard empty list initializations).
dotnet/src/Microsoft.AutoGen/AgentChat/Agents/ToolManager.cs Implements tool lookup/invocation logic along with handoff configuration (utilizes an invalid empty list initializer).
dotnet/src/Microsoft.AutoGen/AgentChat/Agents/CodingAssistantAgent.cs Adds an agent for coding assistance based on a custom prompt and message translation.
dotnet/src/Microsoft.AutoGen/AgentChat/Agents/AssistantAgent.cs Implements an assistant agent coordinating tool calls and model inferences (uses non‐standard collection initializers in several places).

Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.

Implements the pre-defined AgentChat agents: Assistant, CodeExecutor, CodingAssistant, SocietOfMind, and UserProxy, based on their Python counterparts.
@lokitoth lokitoth force-pushed the dev/agentchat_dotnet_agents branch from 357cac8 to d8a6b6f Compare March 5, 2025 19:15

if (handoffs.Count > 1)
{
throw new InvalidOperationException($"Multiple handoffs detected: {String.Join(", ", from handoff in handoffs select handoff.Name)}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible that mutiple handoffs can happen. In that case it's better to warn and choose the first one, and remind user to disable parallel tool calling.

namespace Microsoft.AutoGen.AgentChat.Agents;

// TODO: Replatfrom this on top of AssistantAgent
public class CodingAssistantAgent : ChatAgentBase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class potentially is going to be depreciated. Consider removing it from the PR?

// In the Python implementation AssistantAgent and SocietyOfMindAgent have different strategies for
// reducing on_messages to on_messages_stream. The former returns the first Response as the final
// result, while the latter takes the last
Response? response = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should ever be only one. If there are more it's bug.

public override async IAsyncEnumerable<ChatStreamFrame> StreamAsync(IEnumerable<ChatMessage> item, [EnumeratorCancellation] CancellationToken cancellationToken)
{
List<ChatMessage> delta = item.ToList();
string taskSpecification = this.FormatTask(this.CreateTranscript(delta));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may use multi message list as a task for the inner team to avoid creating transcript string

}
else
{
string prompt = this.FormatResponse(this.CreateTranscript(innerMessages.Skip(1)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here we may use multi message list to get a model response rather than using a single transcript string.

select this.toolManager.InvokeToolAsync(call, cancellationToken))
.ToList();

// TODO: Enable streaming the results as they come in, rather than in a batch?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting idea

};

List<Task<FunctionResultContent>> toolCallTasks = (from call in calls
select this.toolManager.InvokeToolAsync(call, cancellationToken))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tools not found or parameter is incorrect. It's better to return a well formatted string with the error rather than throw. The model can use this to generate a new call again next time the agent is invoked.

Copy link
Collaborator

@rysweet rysweet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are tests for tests for most of these (except prompt template) in the python side that we could port. if you don't get to it before me I'll try to do that - I'll check with you again before I start

lokitoth added a commit that referenced this pull request Mar 11, 2025
Partially addresses #5800, others pending the Agents PR #5837 and GroupChats PR #5838 coming in to have the classes to attach save/load logic to.
@achmstein
Copy link

Thanks for the great work on this! Could you please let us know when this implementation is expected to be available in a release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port AgentChat Agents to .NET

4 participants