Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: #2341

Closed
aullrich2013 opened this issue Apr 10, 2024 · 4 comments · Fixed by #2350
Closed

[Bug]: #2341

aullrich2013 opened this issue Apr 10, 2024 · 4 comments · Fixed by #2350

Comments

@aullrich2013
Copy link

Describe the bug

When attempting to use the transforms.MessageTokenLimiter(max_tokens=1000) on a chatbot,
I receive error IndexError: list index out of range

Because
/home/ish/.venv/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py line 1659 fails because messages is an empty list and not None as expected

Steps to reproduce

create a chatbot agent with registered functions and attempt to add the MessageTokenLimiter context_handling.add_to_agent(chatbot)

Model Used

No response

Expected Behavior

No response

Screenshots and logs

No response

Additional Information

No response

@BeibinLi
Copy link
Collaborator

Thanks for this great feedback!

@BeibinLi
Copy link
Collaborator

@sonichi I believe the error occurs at here

It is possible that the messages is an empty list, either from the line above when sender is None or the input messages is already an empty list.

Would the following update resolve the issue?

if len(messages):
    message = messages[-1]
else:
    message = "empty message"

Of courese, @WaelKarkoub , we need to update this function such that we should avoid returning an empty list. Maybe we can cut the message and get the first few tokens.

@WaelKarkoub
Copy link
Contributor

@BeibinLi I opened a PR to fix this behavior. @aullrich2013 would you be able to test your setup with this PR #2350?

@BeibinLi
Copy link
Collaborator

BeibinLi commented Apr 11, 2024

Note that this line and this line in the conversable agent still needs to be fixed.

@sonichi Do you think my suggestion from yesterday makes sense? If yes, I can go ahead and update the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants