microsoft / autogen

A programming framework for agentic AI 🤖
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
32.42k stars 4.72k forks source link

[Bug]: Error in resuming groupchat. #3364

Open gilada-shubham opened 2 months ago

gilada-shubham commented 2 months ago

Describe the bug

i am getting error while resuming the group chat.

i have a function name get_policy_details

chat_history : [{'content': 'i want to know policy details', 'name': 'chat_manager', 'role': 'user'}, {'content': 'Sure, I can help with that. Could you please provide me with your policy number?', 'name': 'policy_details_agent', 'role': 'user'}, {'content': 'its PDPAC045795', 'name': 'customer', 'role': 'assistant'}, {'content': '', 'function_call': {'arguments': '{"policy_number":"PDPAC045795"}', 'name': 'get_policy_details'}, 'name': 'policy_details_agent', 'role': 'assistant'}, {'content': "{'api_result_type': 'Success', 'concepts': {'policyDetails': {'policyDetails': {'account': {'name': 'test policy', 'coApplicantNames': '', 'email': 'rahulb@rozie.ai', 'geographicalArea': 'The Cayman Islands', 'peroidOfInsurance': '08/14/2024 to 08/14/2025', 'totalPremium': '958.05'}, 'vehicleCoverageDeductibles': {'vehicleDetailsList': {'Items': [{'vehicle': {'insuredValue': '7001-10000', 'year': '2025', 'makeCode': 'Brightdrop', 'modelCode': 'EV600', 'vIN': '444', 'registrationNo': '', 'makeOther': None, 'modelOther': None, 'vehicleType': 'Private Car', 'authorizedDrivers': ''}, 'coverages': {'Items': [{'caption': 'Collision Coverage:', 'value': 'Yes'}, {'caption': 'Fire and Theft Coverage:', 'value': 'Yes'}, {'caption': 'Catastrophe Coverage:', 'value': 'Yes'}, {'caption': 'Rental Coverage:', 'value': '7Days'}]}, 'deductibles': {'Items': [{'caption': 'Collision', 'value': '750'}, {'caption': 'Fire and Theft', 'value': '500'}, {'caption': 'Catastrophe', 'value': '1000'}]}, 'limitsOfLiabilities': {'thirdPartyPropertyDamage': '$250,000', 'perPersonThirdPartyBodilyInjury': '$1,000,000', 'perEventThirdPartyBodilyInjury': '$5,000,000'}}]}}}}}}", 'name': 'get_policy_details', 'role': 'function'}, {'content': 'Here are the details for the policy number **PDPAC045795**:\n\n### Account Information:\n- **Policy Name:** Test Policy\n- **Email:** rahulb@rozie.ai\n- **Geographical Area:** The Cayman Islands\n- **Period of Insurance:** 08/14/2024 to 08/14/2025\n- **Total Premium:** $958.05\n\n### Vehicle Coverage and Deductibles:\n- **Vehicle Type:** Private Car\n- **Make:** Brightdrop\n- **Model:** EV600\n- **Year:** 2025\n- **Insured Value:** $7001-10000\n- **VIN:** 444\n\n#### Coverages:\n- **Collision Coverage:** Yes\n- **Fire and Theft Coverage:** Yes\n- **Catastrophe Coverage:** Yes\n- **Rental Coverage:** 7 Days\n\n#### Deductibles:\n- **Collision:** $750\n- **Fire and Theft:** $500\n- **Catastrophe:** $1000\n\n#### Limits of Liabilities:\n- **Third Party Property Damage:** $250,000\n- **Per Person Third Party Bodily Injury:** $1,000,000\n- **Per Event Third Party Bodily Injury:** $5,000,000\n\nIf you have any more questions or need further details, feel free to ask!', 'name': 'policy_details_agent', 'role': 'user'}]

when i try to resume this chat it gives the error as


  File "/Users/shubhamgilada/Developer/scripts/autogen/mapping/autogen/Flask/Extented_framework/usecases/nested_chat/run.py", line 104, in <module>
    result = policy_group_chat("abc", abc)
  File "/Users/shubhamgilada/Developer/scripts/autogen/mapping/autogen/Flask/Extented_framework/usecases/nested_chat/group_chat_get_policy_details.py", line 323, in policy_group_chat
    last_agent, last_message = manager.resume(messages=messages_json)
  File "/Users/shubhamgilada/miniconda/lib/python3.10/site-packages/autogen/agentchat/groupchat.py", line 1202, in resume
    self._valid_resume_messages(messages)
  File "/Users/shubhamgilada/miniconda/lib/python3.10/site-packages/autogen/agentchat/groupchat.py", line 1391, in _valid_resume_messages
    raise Exception(f"Agent name in message doesn't exist as agent in group chat: {message['name']}")
Exception: Agent name in message doesn't exist as agent in group chat: get_policy_details```

### Steps to reproduce

_No response_

### Model Used

gpt4o

### Expected Behavior

it should resume.

### Screenshots and logs

_No response_

### Additional Information

_No response_
gilada-shubham commented 2 months ago

update: i have added one more condition to _valid_resume_messages which i think is working.

    def _valid_resume_messages(self, messages: List[Dict]):
        """Validates the messages used for resuming

        args:
            messages (List[Dict]): list of messages to resume with

        returns:
            - bool: Whether they are valid for resuming
        """
        # Must have messages to start with, otherwise they should run run_chat
        if not messages:
            raise Exception(
                "Cannot resume group chat as no messages were provided. Use GroupChatManager.run_chat or ConversableAgent.initiate_chat to start a new chat."
            )

        # Check that all agents in the chat messages exist in the group chat
        for message in messages:
            if message.get("name") and message.get("role") != "function": # here
                if (
                    not self._groupchat.agent_by_name(message["name"])
                    and not message["name"] == self._groupchat.admin_name  # ignore group chat's name
                    and not message["name"] == self.name  # ignore group chat manager's name
                ):
                    raise Exception(f"Agent name in message doesn't exist as agent in group chat: {message['name']}")

not sure if its a correct fix

marklysze commented 2 months ago

Can I just check that when you resume the group chat has the same agents as the original group chat?

SuMiaoALi commented 1 month ago

Can I just check that when you resume the group chat has the same agents as the original group chat?

I also have this problem. It occurred when a external UserProxyAgent initial_chat with a group_chat_manager. Becuase the UserProxyAgent is from external user to talk with the group_chat_manager, when resume, the message histories contain the external UserProxyAgent'name which is not in the group_chat internal agents. But I thank this should be supported to work fine.Because UserProxyAgent is always from external when I set the group_chat as an indenpendent workflow