farizrahman4u / loopgpt

Modular Auto-GPT Framework
MIT License
1.43k stars 131 forks source link

Function call `agent.config()` throws an error if `agent.clear_state()` is called before it #41

Closed iskandarreza closed 1 year ago

iskandarreza commented 1 year ago

Please check that this issue hasn't been reported before.

Expected Behavior

It shouldn't cause an error

Current behaviour

It throws the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\GitHub\loopgpt\loopgpt\agent.py", line 441, in config
    "progress": self.progress[:],
TypeError: 'NoneType' object is not subscriptable

Steps to reproduce

import loopgpt

agent = loopgpt.Agent()
agent.name = "Node Exec Test"
agent.goals = "Run the list_files command and then the list_agents command"
agent_init_config = agent.config() # save init config

agent.clear_state() # start fresh
agent.from_config(agent_init_config) # reload cleared config
print(agent.config()) # 💀💀

Possible solution

Update line 346 in agent.py to this:

self.progress = []

Compare

Which Operating Systems are you using?

Python Version

LoopGPT Version

latest from main branch

Acknowledgements

blolt commented 1 year ago

Python throws the error, "TypeError: 'SomeType' object is not subscriptable," when you attempt to use a bracket [] on an object that is not a list or dict, i.e. is not subscriptable. Currently line 346 of agent.py in clear_state() is,

346: self.progress = None

The error, "TypeError: 'NoneType' object is not subscriptable," is thrown on line 441 of agent.py in config(),

441: "progress": self.progress[:],

Switching line 346 to self.progress = [] fixes this, as you found. This is the same value assigned to self.progress on line 60 of agent.py in __init__(), so it seems like an acceptable solution to me.

Thinking I will add your example as a test case in test_serde.py as test_serde_after_clear_state() and submit a PR. If you feel this test case should go into its own file, please let me know. In general, test coverage is pretty abysmal. It would be good to have a parallel file structure for unit tests and some proper mocking, imo, but that is a separate discussion.

FayazRahman commented 1 year ago

Thanks a lot for opening the issue @iskandarreza!