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

fix(agenthub) : limit context size send to llm api #1485

Conversation

coffeecupjapan
Copy link

What?

When observation becoming bigger like more than 16385 words like when developing environment, the LLM API (in my case chatGPT-3.5) throws error like below image.

スクリーンショット 2024-04-30 19 50 48

I think If we can limit the context size send to LLM api, we don't have to worry about the above 400 error.
I did't try using Gemini or Vertex LLM, and even for GPT I didn't try using GPT4, so maybe there are improvement to have conditional branch that supports each LLM.

Thank you for reading my PR.

@iFurySt
Copy link
Collaborator

iFurySt commented May 1, 2024

should we dense the messages or swap a portion to long-term memory instead of truncating them directly?

@rbren
Copy link
Collaborator

rbren commented May 2, 2024

@xingyaoww I vaguely remember you doing something like this already

@coffeecupjapan we should at least extract out the magic constant, so we can tune this a bit

@rbren
Copy link
Collaborator

rbren commented May 2, 2024

See also: #1421

@codecov-commenter
Copy link

codecov-commenter commented May 2, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (main@31c1a2d). Click here to learn what that means.

Files Patch % Lines
agenthub/codeact_agent/codeact_agent.py 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1485   +/-   ##
=======================================
  Coverage        ?   58.52%           
=======================================
  Files           ?       83           
  Lines           ?     3479           
  Branches        ?        0           
=======================================
  Hits            ?     2036           
  Misses          ?     1443           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xingyaoww
Copy link
Collaborator

@rbren Yes! We already have this in-place in #1494

def truncate_observation(observation: str, max_chars: int=5000) -> str:
"""
Truncate the middle of the observation if it is too long.
"""
if len(observation) <= max_chars:
return observation
half = max_chars // 2
return observation[:half] + '\n[... Observation truncated due to length ...]\n' + observation[-half:]

@rbren
Copy link
Collaborator

rbren commented May 7, 2024

@coffeecupjapan I'm going to close this one, but feel free to open up an issue where we can discuss a more long-term solution!

@rbren rbren closed this May 7, 2024
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 this pull request may close these issues.

None yet

5 participants