-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Adds Message History to a ConversableAgent
#2437
Conversation
Some build failures. |
Thanks! |
While this is great PR, I have a few thoughts here
I would expect something like below
While something like this can be achieved using assistant = ConversableAgent(
name="Assistant",
system_message="Your are a friendly Q&A Bot"
"You may use the previous messages to understand the context of current Query"
"Return 'TERMINATE' when the task is done.",
llm_config=self.llm_config,
human_input_mode="NEVER",
default_auto_reply="Reply with 'TERMINATE' if the task is done.",
is_termination_msg=is_termination_msg
)
def my_message(sender: ConversableAgent,
recipient: ConversableAgent,
context: dict) -> Union[str, Dict]:
message = context.get("user_query", "")
last_chats = context.get("last_chats", [])
prelude = [f"Query: {x.get('query')}. Answer: {x.get('answer')}" for x in last_chats]
curr_msg = f"CURRENT QUERY: {message}"
final_msg = f"Previous Messages: {' '.join(prelude)}. {curr_msg}"
return final_msg
user_proxy.initiate_chat(
assistant,
message=my_message,
user_query=query,
last_chats=last_chats,
verbose=True
) In another example from the blog mentioned here, people are replaying the chat in GroupChat and broadcasting it to all other agents. I believe this need can also be eliminated if only the user's query & response are passed onto while initiating group chat |
Are you thinking about a stateful agent? For now ConversableAgent is typically created for a task and thrown out once the task is completed -- the state is managed by the application. The choice is made here is we believe application has the best understanding of end user experience and how state should be handled, e.g., long running chat or utility functions.
This is a great idea. We have a roadmap issue on persistence and this is a work item. Would you be interested in contributing? See #2358 |
No. I don't think that serves any practical purpose. I am more interested in having some way to inject previous history into a stateless agent.
@ekzhu - Sure, I will try and open a PR |
* updates docstr + fix spelling * fix docstr * maybe a lfs fix? * Revert "maybe a lfs fix?" This reverts commit 2ea2dad. * revert * rename arg to chat_messages * minor fix
Why are these changes needed?
Part of Persistence and state management roadmap. Adds
messages
to the constructor of aConversableAgent
. This will allow the agent to pick up the conversation from where it left off.NOTE: User needs to reconstruct the
messages
if the references of those agents have changed (e.g. the python script was restarted or new agents formed).Related issue number
Checks