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

SmolAgents AgentMemory is kept in Gradio global state and cannot be turned off. #703

Open
ddewaele opened this issue Feb 18, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@ddewaele
Copy link

ddewaele commented Feb 18, 2025

Describe the bug
When launching the agent in Gradio GradioUI(agent).launch(), the agent is kept in the global state of Gradio, meaning all users share the same agent.
Although messages seem to be stored in Gradio Session state, some internal agent state like AgentMemory is saved globally
I would imagine that it would be better to scope everything on Session State.
There is a reset_agent_memory flag on SmolAgents that is False by default, but there is no way to override it.

Code to reproduce the error
Open a chat session in a gradio space and keep talking until you hit the context window limit.
Open a new chat session in a different browser. You will not be able to have a conversation due to the context window limit error that was triggered by the first chat session.
The global agent memory will consume all of the context size.
From that point on the space will be broken for everyone and nobody will be able to start conversations again.

Error logs (if any)
All users will experience an error like this

Input validation error: inputs tokens + max_new_tokens must be <= 16000. Given: 43384 inputs tokens and 2096 max_new_tokens
Make sure 'text-generation' task is supported by the model.

Expected behavior
I would expect that there are proper user scoped sessions. And that one user session cannot influence the behavior of another session.

Packages version:
smolagents==1.9.2

Additional context
This issue became clear during the HuggingFace Agents Course, when students were asked to promote their Agents through their spaces. Because the underlying LLM had a small context window, as soon as 1 person hit that max context size the space was ruined for everyone.
HuggingFace provided a template https://huggingface.co/spaces/agents-course/First_agent_template for students to create agents and tools.
That template contains a copy of Gradio_UI.py where we can manipulate the reset_agent_memory flag, but I assume you want to keep Gradio_UI.py a part of SmolAgents and not have people create copies of it.

Otherwise the only way to fix the issue is to restart the entire space

@ddewaele ddewaele added the bug Something isn't working label Feb 18, 2025
@dlflannery
Copy link

+1 on this, and also: in the HF agents course (duplicated) space, it would be nice if refreshing the space could cause the current memory of context window to be cleared. Restarting the space does this, of course, and I’ve been able to force it with a prompt like “clear your memory of previous chats”, but that seems like a crude way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants