-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Unexpected Behavior with Agent Memory in FastAPI using OpenWebUI Pipelines #1669
Comments
Hello @NTTLuke ! Memory Retrieval Without History Parameters: Yes, this is expected behaviour. By default we do not add any prior chat history to an Agent. Adding Chat History: Can you please confirm if The |
Hello @ysolanky Regarding your question: Yes, a new The use case works using only Use Case:Scenario: Starting from scratch
To address this in different ways, I modified the approach by moving the agent to the Based on this scenario, it seems that during the creation of a new chat, the agent retrieves all historical messages from the latest instance before saving them to PostgreSQL even if the agent has the empty memory ( Please let me know your thoughts—unless I’m starting to hallucinate worse than an LLM. 😂 |
I just want to share even this to understand better the flow. Specifically, when I remove read_chat_history=True and num_history_responses=3, the agent sometimes fails to incorporate the correct historical chat context. This behavior appears to occur at the following point in the code:
At step 2, messages retrieved from Postgres are correctly stored in self.memory.messages However, at step 3, these stored messages are not included in the messages_for_model variable or in the user_messages. As a result, models receives only the system prompt and the latest user message, without references to the storage data. I tested a quick and admittedly "dirty" workaround by appending the stored messages manually at runtime:
or
With this change, the agent successfully incorporates the historical context. I don't know if it's correct and I'm pointing to the wrong part but I just wanted to share with you because this was the reason of adding the read_chat_history and num_history_responses parameters. thank you |
@NTTLuke thank you for sharing the use cases. I see now that the issue is due to the use of the same instance of Agent. I was able to replicate scenarios 2 and 3 by using the same instance and just updating the session_id. For a fix, for each new |
I am looking into the |
Thank you @ysolanky ... I will try in this way ! |
I’m experiencing an issue with the memory behavior of an agent set up in a FastAPI OpenWebUI pipeline. While I suspect I may be missing something, the behavior is inconsistent, and I’m unsure how to resolve it.
Here’s the relevant portion of my agent setup and chat handling code (sensitive information removed):
Observed Issues
Memory Retrieval Without History Parameters
When I remove
add_history_to_messages=True
andnum_history_responses=3
as documented here](https://docs.phidata.com/agents/storage), the agent’s memory does not function correctly. It seems unable to retrieve old messages from the history.Adding Chat History
Adding
add_history_to_messages=True
andnum_history_responses=3
resolves the memory issue. However, I expect the agent to retrieve history only from the current chat session, not from the entire user history (all the user chats).Additional Notes
print_response
method; in that case, the history is restricted to the current chat session as expected.Could someone clarify if I’m configuring the agent correctly in this scenario? Are there additional steps or tricks to ensure that the history retrieval is limited to the session context that in my case corresponds to the single chat?
Thank u :)
The text was updated successfully, but these errors were encountered: