camel-ai / camel

🐫 CAMEL: Finding the Scaling Law of Agents. A multi-agent framework. https://www.camel-ai.org
https://www.camel-ai.org
Apache License 2.0
5.32k stars 647 forks source link

RuntimeError: Property msg is only availablefor a single message in msgs #228

Closed monkeyshichi closed 1 year ago

monkeyshichi commented 1 year ago

Required prerequisites

Questions

i run role_playing.py under ai_society . RuntimeError: Property msg is only availablefor a single message in msgs

Obs01ete commented 1 year ago

Hi @monkeyshichi. Thanks for reporting the issue! Could you share the launch command and the stack trace?

monkeyshichi commented 1 year ago

Hi @monkeyshichi. Thanks for reporting the issue! Could you share the launch command and the stack trace?

@dataclass(frozen=True) class ChatAgentResponse: r"""Response of a ChatAgent.

Attributes:
    msgs (List[BaseMessage]): A list of zero, one or several messages.
        If the list is empty, there is some error in message generation.
        If the list has one message, this is normal mode.
        If the list has several messages, this is the critic mode.
    terminated (bool): A boolean indicating whether the agent decided
        to terminate the chat session.
    info (Dict[str, Any]): Extra information about the chat message.
"""
msgs: List[BaseMessage]
terminated: bool
info: Dict[str, Any]

@property
def msg(self):
    if len(self.msgs) != 1:
        raise RuntimeError("Property msg is only available"
                           "for a single message in msgs")
    return self.msgs[0]
monkeyshichi commented 1 year ago

Traceback (most recent call last): File "C:\Users\DELL\Downloads\ChatGPT-main\camel-real\role_playing.py", line 79, in main() File "C:\Users\DELL\Downloads\ChatGPT-main\camel-real\role_playing.py", line 56, in main input_assistant_msg = assistant_response.msg File "C:\Users\DELL\Downloads\ChatGPT-main\camel-real\camel\agents\chat_agent.py", line 57, in msg return self.msgs[0] IndexError: list index out of range

Process finished with exit code 1

HalberdOfPineapple commented 1 year ago

Traceback (most recent call last): File "C:\Users\DELL\Downloads\ChatGPT-main\camel-real\role_playing.py", line 79, in main() File "C:\Users\DELL\Downloads\ChatGPT-main\camel-real\role_playing.py", line 56, in main input_assistant_msg = assistant_response.msg File "C:\Users\DELL\Downloads\ChatGPT-main\camel-real\camel\agents\chat_agent.py", line 57, in msg return self.msgs[0] IndexError: list index out of range

Process finished with exit code 1

Thanks for your reporting. But from this traceback, it seems the response does not contain any message (len(self.msgs) == 0) instead of containing multiple ones, which results in list index out of range. May I ask whether you modified any of the input prompts in role_playing.py? That is a strange case as I can still run this script correctly.

monkeyshichi commented 1 year ago

Traceback (most recent call last): File "C:\Users\DELL\Downloads\ChatGPT-main\camel-real\role_playing.py", line 79, in main() File "C:\Users\DELL\Downloads\ChatGPT-main\camel-real\role_playing.py", line 56, in main input_assistant_msg = assistant_response.msg File "C:\Users\DELL\Downloads\ChatGPT-main\camel-real\camel\agents\chat_agent.py", line 57, in msg return self.msgs[0] IndexError: list index out of range Process finished with exit code 1

Thanks for your reporting. But from this traceback, it seems the response does not contain any message (len(self.msgs) == 0) instead of containing multiple ones, which results in list index out of range. May I ask whether you modified any of the input prompts in role_playing.py? That is a strange case as I can still run this script correctly.

No,i don't modified any code.

monkeyshichi commented 1 year ago

Sorry, maybe because my chatgpt ran out of api, I'll try recharging

monkeyshichi commented 1 year ago

But the first time I made that mistake, my chatgpt didn't ran out of api

monkeyshichi commented 1 year ago

AI User:

Instruction: Implement the functionality to execute automated buy/sell orders based on the predicted market trends. Input: None

AI Assistant:

Solution: To implement the functionality to execute automated buy/sell orders based on the predicted market trends, we need to define the rules and conditions for making trading decisions. Here's a general outline of how you can approach this:

  1. Define the trading strategy: Determine the rules and conditions for buying and selling stocks based on the predicted market trends. This could involve indicators such as moving averages, relative strength index (RSI), or any other technical analysis tools.

  2. Implement the decision-making logic: Write the code that evaluates the predicted market trends and triggers buy or sell orders based on the defined trading strategy. This logic should consider factors such as the current portfolio, available funds, risk tolerance, and any other relevant considerations.

  3. Connect to a brokerage or trading platform: To execute the buy/sell orders automatically, you'll need to connect your trading bot to a brokerage or trading platform that supports automated trading. This typically involves using APIs provided by the brokerage or platform to place orders.

  4. Test and monitor the trading bot: Before deploying the trading bot in a live trading environment, it's crucial to thoroughly test and monitor its performance using historical data or a simulated trading environment. This helps ensure that the bot is making accurate and profitable trading decisions.

It's important to note that implementing automated trading functionality involves significant risks and complexities. It requires a deep understanding of trading strategies, risk management, and the specific APIs and protocols of the chosen brokerage or trading platform. It's recommended to consult with a financial advisor or professional trader before deploying an automated trading bot.

Next request.

Traceback (most recent call last): File "C:\Users\DELL\Downloads\ChatGPT-main\camel-real\role_playing.py", line 80, in main() File "C:\Users\DELL\Downloads\ChatGPT-main\camel-real\role_playing.py", line 57, in main input_assistant_msg = assistant_response.msg File "C:\Users\DELL\Downloads\ChatGPT-main\camel-real\camel\agents\chat_agent.py", line 57, in msg return self.msgs[0] IndexError: list index out of range

Process finished with exit code 1 the error appears again

lightaime commented 1 year ago

It seems this happens when the return message is an empty list []. Thanks for reporting this. We will look into it.

lightaime commented 1 year ago

@Obs01ete could you have a look at this? Thanks!

Obs01ete commented 1 year ago

@monkeyshichi Please share the instruction to reproduce the crash. Do you have any try-except in your code?

monkeyshichi commented 1 year ago

@monkeyshichi Please share the instruction to reproduce the crash. Do you have any try-except in your code?

python ai_society/role_playing.py.i don't have any try-except .i just use the same code,i don't modify code except comment these code:

if len(self.msgs) != 1:

raise RuntimeError("Property msg is only available for a single message in msgs")

but i don't affect the result.

Obs01ete commented 1 year ago

@monkeyshichi Please share the instruction to reproduce the crash. Do you have any try-except in your code?

python ai_society/role_playing.py.i don't have any try-except .i just use the same code,i don't modify code except comment these code: #if len(self.msgs) != 1: #raise RuntimeError("Property msg is only available for a single message in msgs") but i don't affect the result.

I suppose something is wrong with your OpenAI API. You get empty messages from OpenAI. We will improve the exception message to be more specific, but fixing your access to OpenAI API you will need to do yourself.

monkeyshichi commented 1 year ago

ok thanks,i will try again

lightaime commented 1 year ago

@monkeyshichi The bug is due to the token limit. It is fixed in this commit: https://github.com/camel-ai/camel/commit/9922dd3c0e5aba196a9a8df5f0af8d28317800ee to break the loop when out of token limit. If you want to use a large token limit you can try ModelType.GPT_3_5_TURBO_16K. Let me know if you find any question.