updates docstr + fix spelling

This commit is contained in:
Wael Karkoub
2024-04-18 17:31:01 +01:00
parent 2df0f39b00
commit 549b5ac96d
2 changed files with 81 additions and 3 deletions

View File

@@ -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()