Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[.Net][Feature Request]: Eanble step-by-step execution for two agent chat API. #3339

Closed
LittleLittleCloud opened this issue Aug 11, 2024 · 0 comments · Fixed by #3360
Closed
Assignees
Labels
api-break-change Will break existing api and needs an migration for previous code to work good first issue Good for newcomers

Comments

@LittleLittleCloud
Copy link
Collaborator

LittleLittleCloud commented Aug 11, 2024

Is your feature request related to a problem? Please describe.

Similar to how GroupChatExtension.SendAsync returns an IAsyncEnumerable iterator, the AgentExtension.SendAsync(this IAgent agent, IAgent receiver, IEnumerable<IMessage> chatHistory, int maxRound = 10, CancellationToken ct = default(CancellationToken)) should also return an IAsyncEnuemrable so the conversation can be driven step by step.

Describe the solution you'd like

Return IAsyncEnumerabe in AgentExtension.SendAsync(this IAgent agent, IAgent receiver, IEnumerable<IMessage> chatHistory, int maxRound = 10, CancellationToken ct = default(CancellationToken))

Before

var chatHistory = new List<IMessage>()
{
   new TextMessage("Hey teacher, please create math question for me."),
};

var maxRound = 10;
while(true && maxRound > 0)
{
    IEnumerable<IMessage> conversation = await student.SendAsync(
            receiver: teacher,
            chatHistory: chatHistory,
            maxRound: 1);
    chatHistory = conversation;
    maxRound --;
}

After

var chatHistory = new List<IMessage>()
{
   new TextMessage("Hey teacher, please create math question for me."),
};

await foreach(var msg in student.SendAsync(receiver: teacher, chatHistory: chatHistory, maxRound: 10)
{
    // do something with msg. e.g. update chatHistory
    chatHistory.Add(msg)
}

API break change

this issue deprecates the following APIs. It's recommended to use GroupChatExtension.SendAsync instead

  • AgentExtension.SendMessageToGroupAsync(IGroupChat, string, IEnumerable<IMessage>, int)
  • AgentExtension.SendMessageToGroupAsync(IGroupChat, IEnumerable<IMessage>, int)

This issue also changes the return type of AgentExtension.SendAsync from Task<IEnumerable<IMessage>> to IAsyncEnumerable<IMessage>. You can use ToArrayAsync or something similar to convert IAsyncEnumerable to IEnumerable if you don't want to iterate over messages using await foreach

Additional context

See also #3214 on how groupchat.sendasync implement step-by-step execution by returning IAsyncEnumerable
No response

@LittleLittleCloud LittleLittleCloud added this to the AutoGen.Net 0.1.0 milestone Aug 11, 2024
@LittleLittleCloud LittleLittleCloud added the good first issue Good for newcomers label Aug 11, 2024
@LittleLittleCloud LittleLittleCloud self-assigned this Aug 15, 2024
@LittleLittleCloud LittleLittleCloud added the api-break-change Will break existing api and needs an migration for previous code to work label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-break-change Will break existing api and needs an migration for previous code to work good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant