-
Notifications
You must be signed in to change notification settings - Fork 568
fix(ai): truncate messages in openai agents #5049
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
base: master
Are you sure you want to change the base?
Conversation
| @@ -1,33 +1,35 @@ | |||
| import asyncio | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Organized some imports here
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #5049 +/- ##
==========================================
- Coverage 83.93% 83.91% -0.03%
==========================================
Files 179 179
Lines 17893 17906 +13
Branches 3181 3183 +2
==========================================
+ Hits 15019 15026 +7
- Misses 1909 1912 +3
- Partials 965 968 +3
|
| serialized_str = safe_serialize(message) | ||
| try: | ||
| serialized_message = json.loads(serialized_str) | ||
| except (json.JSONDecodeError, TypeError): | ||
| continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you serialize and deserialize here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't found a better way to be sure that whatever is in the messages is actually serialize-able down the line. I.e. if there is an object that is passed in the messages, and the object is not serializeable, it will fail. Do we have a better way of doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what exactly fails down the line?
I'm just trying to understand why we need this. Do we want to ensure we only have standard JSON types like strings, integers and so on in the dictionaries?
Because then we can just directly check the types in the dictionary.
| { | ||
| "role": GEN_AI_ALLOWED_MESSAGE_ROLES.TOOL, | ||
| "content": [message], | ||
| "content": [serialized_message], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Bug
The safe_serialize and json.loads pattern can result in serialized_message being a non-dictionary type. This causes AttributeError or TypeError when attempting to access dictionary-like properties, as the try/except block is too narrow. This can lead to messages being silently skipped or the function crashing.
Closes TET-1208