Skip to content

Limit historical messages with Agent and Redis #20831

Answered by dosubot bot
lorerave85 asked this question in Q&A
Discussion options

You must be logged in to vote

To limit the history messages loaded by the Agent to the last 5 saved messages, you'll need to adjust the logic that handles the retrieval and storage of chat history in Redis. This involves modifying how messages are added to and retrieved from the Redis database to ensure only the last 5 messages are considered for each session.

For the retrieval part, when fetching messages from Redis to load into the chat history, you can use Redis' LRANGE command to get only the last 5 messages. Here's a conceptual adjustment you might make in the part of your code that retrieves chat history:

def get_last_messages(session_id, count=5):
    messages = redis_client.lrange(session_id, -count, -1)
    r…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by lorerave85
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants