#Help Needed: Creating a ReAct Agent with Autogen for .Net

11 messages · Page 1 of 1 (latest)

devout lantern
#

Hello everyone,

I'm trying to create a ReAct agent using Autogen for .Net, following the tutorial on this page: https://microsoft.github.io/autogen/docs/topics/prompting-and-reasoning/react/.

I've implemented the following method to create my ReAct agent, but I'm not sure if it's correct. Additionally, I couldn't find the "max_consecutive_auto_reply" parameter in Autogen for .Net, which is used in the tutorial. I would really appreciate any guidance or corrections from the community.
[Continued in reply]

Open In Colab

#

Here's my method for creating the agent:

{
    string openAIAPIKey = "My-super secret API Key";
    OpenAIConfig llmConfig = new OpenAIConfig(openAIAPIKey, "gpt-4-turbo");

    TypeSafeFunctionCall tools = new TypeSafeFunctionCall();

    MiddlewareAgent<ConversableAgent> weatherAgent = new ConversableAgent(
        name: "weatherAgent",
        systemMessage: "Only use the tools you have been provided with. Reply TERMINATE when the task is done.",
        llmConfig: new ConversableAgentConfig { 
            Temperature = 0,
            ConfigList = new[] { llmConfig },
            FunctionContracts = new[]
            {
                tools.WeatherReportFunctionContract,
                tools.GetLocalizationFunctionContract,
                tools.GetDateFunctionContract
            }
        },
        humanInputMode: HumanInputMode.NEVER,
        functionMap: new Dictionary<string, Func<string, Task<string>>>
        {
            { tools.WeatherReportFunctionContract.Name, tools.WeatherReportWrapper },
            { tools.GetLocalizationFunctionContract.Name, tools.GetLocalizationWrapper },
            { tools.GetDateFunctionContract.Name, tools.GetDateWrapper }
        }).RegisterPrintMessage();

    MiddlewareAgent<UserProxyAgent> userProxy = new UserProxyAgent(
        name: "userProxy",
        isTermination: async (messages, token) => messages.LastOrDefault()?.GetContent() == null ? false : (messages.LastOrDefault().GetContent().Contains("TERMINATE") ? true : false),
        humanInputMode: HumanInputMode.AUTO,
        defaultReply: "If you send the \"Final Answer\" reply TERMINATE. Otherwise, reply CONTINUE and the \"Thought\", \"Action\", \"Action input\" or \"Observation\" of the current step."
        ).RegisterPrintMessage();

#
        receiver: weatherAgent,
        message: $"Answer the following questions as best you can. You have access to tools provided.\r\n" +
        $"Use the following format:\r\n\r\n" +
        $"Question: the input question you must answer\r\n" +
        $"Thought: you should always think about what to do\r\n" +
        $"Action: the action to take\r\n" +
        $"Action Input: the input to the action\r\n" +
        $"Observation: the result of the action\r\n" +
        $"... (this process can repeat multiple times)\r\n" +
        $"Thought: I now know the final answer\r\n" +
        $"Final Answer: the final answer to the original input question\r\n\r\n" +
        $"Begin!\r\n" +
        $"Question: {input}",
        maxRound: 30
        );
}
#

And here's the class that defines my action methods :

{
    /// <summary>
    /// Get weather report for a specific place on a specific date
    /// </summary>
    /// <param name="city">city</param>
    /// <param name="date">date as DD/MM/YYYY</param>
    [Function]
    public async Task<string> WeatherReport(string city, string date)
    {
        return $"Weather report for {city} on {date} is sunny";
    }
}

public partial class TypeSafeFunctionCall
{
    /// <summary>
    /// Get current localization
    /// </summary>
    /// <param name="dummy">useless param</param>
    [Function]
    public async Task<string> GetLocalization(string dummy)
    {
        return $"Paris";
    }
}

public partial class TypeSafeFunctionCall
{
    /// <summary>
    /// Get current date as DD/MM/YYYY
    /// </summary>
    /// <param name="dummy">useless param</param>
    [Function]
    public async Task<string> GetDate(string dummy)
    {
        return $"27/05/2024";
    }
}
#

Any advice or suggestions on how to improve or correct my approach would be greatly appreciated!

Thank you in advance for your help!

Sorry for my English, I am not a native speaker.

potent sage
#

#1205927123089358989

#

this channel could help you solve the issue. thanks @devout lantern

devout lantern
#

Thank you very much 🙂

latent fern
#

@devout lantern maxRound is the max_consecutive_auto_reply in AutoGen.Net, they serve the same purpose

latent fern
#

Maybe create an issue in autogen repo and @LittleLittleCloud? he can take a look

latent fern
#

LittleLittleCloud just create an issue and PR for adding react agent sample. Hope this can help you
https://github.com/microsoft/autogen/issues/2978

The implementation is a little dfferent from pyautogen's because in AutoGen.Net, you can't have content and tool call message in the same message.
Check this issue for further information
https://github.com/microsoft/autogen/issues/2975

Therefore, the AutoGen.Net's implementation seperate reasoner and action steps into two inner agents, the idea behind is the same though