mirror of
https://github.com/microsoft/autogen.git
synced 2026-02-08 12:34:54 -05:00
updates docstr + fix spelling
This commit is contained in:
@@ -1311,6 +1311,77 @@ def test_messages_with_carryover():
|
||||
assert len(generated_message["content"]) == 2
|
||||
|
||||
|
||||
def test_chat_history():
|
||||
alice = autogen.ConversableAgent(
|
||||
"alice",
|
||||
human_input_mode="NEVER",
|
||||
llm_config=False,
|
||||
default_auto_reply="This is alice speaking.",
|
||||
)
|
||||
|
||||
charlie = autogen.ConversableAgent(
|
||||
"charlie",
|
||||
human_input_mode="NEVER",
|
||||
llm_config=False,
|
||||
default_auto_reply="This is charlie speaking.",
|
||||
)
|
||||
|
||||
max_turns = 2
|
||||
|
||||
def bob_initiate_chat(agent: ConversableAgent, text: Literal["past", "future"]):
|
||||
_ = agent.initiate_chat(
|
||||
alice,
|
||||
message=f"This is bob from the {text} speaking.",
|
||||
max_turns=max_turns,
|
||||
clear_history=False,
|
||||
silent=True,
|
||||
)
|
||||
_ = agent.initiate_chat(
|
||||
charlie,
|
||||
message=f"This is bob from the {text} speaking.",
|
||||
max_turns=max_turns,
|
||||
clear_history=False,
|
||||
silent=True,
|
||||
)
|
||||
|
||||
bob = autogen.ConversableAgent(
|
||||
"bob",
|
||||
human_input_mode="NEVER",
|
||||
llm_config=False,
|
||||
default_auto_reply="This is bob from the past speaking.",
|
||||
)
|
||||
bob_initiate_chat(bob, "past")
|
||||
context = bob.chat_messages
|
||||
|
||||
del bob
|
||||
|
||||
# Test agent with chat history
|
||||
bob = autogen.ConversableAgent(
|
||||
"bob",
|
||||
human_input_mode="NEVER",
|
||||
llm_config=False,
|
||||
default_auto_reply="This is bob from the future speaking.",
|
||||
messages=context,
|
||||
)
|
||||
|
||||
assert bool(bob.chat_messages)
|
||||
assert bob.chat_messages == context
|
||||
|
||||
# two times the max turns due to bob replies
|
||||
assert len(bob.chat_messages[alice]) == 2 * max_turns
|
||||
assert len(bob.chat_messages[charlie]) == 2 * max_turns
|
||||
|
||||
bob_initiate_chat(bob, "future")
|
||||
assert len(bob.chat_messages[alice]) == 4 * max_turns
|
||||
assert len(bob.chat_messages[charlie]) == 4 * max_turns
|
||||
|
||||
assert bob.chat_messages[alice][0]["content"] == "This is bob from the past speaking."
|
||||
assert bob.chat_messages[charlie][0]["content"] == "This is bob from the past speaking."
|
||||
|
||||
assert bob.chat_messages[alice][-2]["content"] == "This is bob from the future speaking."
|
||||
assert bob.chat_messages[charlie][-2]["content"] == "This is bob from the future speaking."
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# test_trigger()
|
||||
# test_context()
|
||||
|
||||
Reference in New Issue
Block a user