# Tokens limit in Web Browser Automation

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftokens-limit-in-web-browser-automation%2F147771%3E%5C
**Category:** Beginners\
**Created:** [March 28, 2025, 6:05am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftokens-limit-in-web-browser-automation%2F147771 "2025-03-28T06:05:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tgaleev](https://avatars.discourse-cdn.com/v4/letter/t/ad7895/32.png) [@tgaleev](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ftgaleev)%5C
**Post date:** [March 28, 2025, 6:05am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftokens-limit-in-web-browser-automation%2F147771%2F1 "2025-03-28T06:05:01Z")

</div>

Hello. I often face the problem of token limits when using this code:

> **[Web Browser Automation with Agents 🤖🌐](https://huggingface.co/docs/smolagents/main/en/examples/web_browser)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

**Error message:**  
`422 Client Error... Input validation error: 'inputs' tokens + 'max_new_tokens' must be <= 131072. Given: 270767 'inputs' tokens and 0 'max_new_tokens'`

I suspect the issue lies in the browser screenshot function — it seems to generate too many tokens per screenshot. How can I resolve this?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 28, 2025, 6:20am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftokens-limit-in-web-browser-automation%2F147771%2F2 "2025-03-28T06:20:08Z")

</div>

Oh… Unresolved issue…

> <https://github.com/huggingface/smolagents/issues/703>
>
> \*\*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

---

<div class="post-metadata">

**Author:** ![tgaleev](https://avatars.discourse-cdn.com/v4/letter/t/ad7895/32.png) [@tgaleev](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Ftgaleev)%5C
**Post date:** [March 28, 2025, 6:45am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftokens-limit-in-web-browser-automation%2F147771%2F3 "2025-03-28T06:45:18Z")

</div>

Got it, thanks!
