ML Ops
ML Ops

Reputation: 51

autogen forward input to another agent (register_reply??)

I'm having a scenario where I need to develop a solution which the one agent will comeup with a plan and then goes a review cycle with the user, before forward it into a group of other agents. I have my human_input_mode set to ALWAYS on the user_proxy but not sure how to sort forward the conversation automatically once the user agrees with the plan.

I tried to use register_reply but for whatever reason this doesn't work on my approach. (I think I'm doing something silly)

project_manager = autogen.AssistantAgent(
    name="project_manager",
    system_message="""You are responsible for coming up with a plan to estimate the cost.""",
    llm_config=llm_config,
)

comedian = autogen.AssistantAgent(
    name= "comedian",
    system_message="""Your job is to make a joke about the plan shared.
    """,
    llm_config=llm_config,)

user_proxy = autogen.UserProxyAgent(
   name="User_proxy",
   system_message="A human admin.",
   code_execution_config={"last_n_messages": 2, "work_dir": "groupchat"},
   human_input_mode="ALWAYS",
   function_map={"ask_planner": ask_planner},
)

project_manager.register_reply(user_proxy,add_data_reply)

async def add_data_reply(recipient, messages, sender, config):
    print("HERE")
    print("messages:" + str(messages))
    comedian.generate_reply(messages=messages)



user_proxy.initiate_chat(
    project_manager,
    message="""I would like you to comeup with a plan to build a model rocket""", 
)

Upvotes: 1

Views: 1772

Answers (2)

rachit
rachit

Reputation: 31

I believe you have a async reply function add_data_reply and the chat is initiated as sync user_proxy.initiate_chat. You can try using a sync function or initiate async chat.

From the docs -

Both sync and async reply functions can be registered. The sync reply function will be triggered from both sync and async chats. However, an async reply function will only be triggered from async chats (initiated with ConversableAgent.a_initiate_chat). If an async reply function is registered and a chat is initialized with a sync function, ignore_async_in_sync_chat determines the behaviour as follows: if ignore_async_in_sync_chat is set to False (default value), an exception will be raised, and if ignore_async_in_sync_chat is set to True, the reply function will be ignored.

Upvotes: 0

Burhan
Burhan

Reputation: 790

I believe register_reply() is used when you want to control how an agent replies.

There are a couple of other ways you can control conversation flow:

  • Override GroupChat to construct a custom class where you have full control over the next speaker (see this notebook)
  • Convert agents into a tool / function. This way, top-level agents can control when the other agents are invoked. (see this notebook)

Upvotes: 2

Related Questions