-
Notifications
You must be signed in to change notification settings - Fork 16
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
Migrates to langgraph #165
Conversation
…'s not a tool call
… Tests run with as_graph.
@@ -73,13 +77,17 @@ def add_messages(self, messages: Sequence[BaseMessage]) -> None: | |||
messages: A list of BaseMessage objects to store. | |||
""" | |||
with transaction.atomic(): | |||
existing_messages = self.get_messages() | |||
|
|||
messages_to_create = [m for m in messages if m not in existing_messages] |
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.
how is the not in
making the equality for messages? do you know?
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.
Good point, it worked but I didn't check why it was working, perhaps we should force comparing by id to make this safer and more explicit?
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 think so, but does the messages Langchain passes as params contain any ids?
Also, we can optimize this a bit by querying with ids.
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.
The langchain ones receive a uuid id that is added in the built in add_messages
function that is called before calling this one and they are update here to the db ids a few lines bellow 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.
I've made the change to compare ids and optimized the query to only return the ids
assert ( | ||
response_message.content == "The current temperature in Recife today is 32 degrees Celsius." | ||
) | ||
assert response_message.id == str(messages_ids[1]) |
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 preferred the old approach for readability. If you had trouble with the diffs, it's possible to change pytest to include all the diff.
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.
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.
Got it! We could use something like this: https://kalnytskyi.com/posts/assert-str-matches-regex-in-pytest/
In this case, it would be a comparator that always returns true.
But that's a nitpick.
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.
Overall LGTM, but please check comments.
Can you also check the coverage decrease?
This PR sunsets the previous use of chains in favor of the more modern, more readable and simpler to use langgraph approach. The migration was done trying to keep the changes as minimal as possible and the both methods
as_chain
andas_graph
are still available. For nowas_chain
still the default approach but it can be changed by changing the settingAI_ASSISTANT_USE_LANGGRAPH
toTrue
. After this changes have been field tested we will sunset the oldas_chain
approach. Tests are already running withAI_ASSISTANT_USE_LANGGRAPH
set to true. During this migration only 5 tests broke because it was required rerunning the cassettes due to small changes in the setup of how messages are organized in the prompt.