mirror of
https://github.com/microsoft/autogen.git
synced 2025-09-25 08:05:36 +00:00
Change last_n_messages to default to 'auto' (#1356)
* Change last_n_messages to default to 'auto' * Added last_n_messages validation, as per Eric's comment. --------- Co-authored-by: Davor Runje <davor@airt.ai>
This commit is contained in:
parent
c76dc2bbb0
commit
c05e212d15
@ -107,7 +107,7 @@ class ConversableAgent(Agent):
|
||||
If False, the code will be executed in the current environment.
|
||||
We strongly recommend using docker for code execution.
|
||||
- timeout (Optional, int): The maximum execution time in seconds.
|
||||
- last_n_messages (Experimental, Optional, int or str): The number of messages to look back for code execution. Default to 1. If set to 'auto', it will scan backwards through all messages arriving since the agent last spoke (typically this is the last time execution was attempted).
|
||||
- last_n_messages (Experimental, Optional, int or str): The number of messages to look back for code execution. If set to 'auto', it will scan backwards through all messages arriving since the agent last spoke, which is typically the last time execution was attempted. (Default: auto)
|
||||
llm_config (dict or False): llm inference configuration.
|
||||
Please refer to [OpenAIWrapper.create](/docs/reference/oai/client#create)
|
||||
for available options.
|
||||
@ -839,7 +839,10 @@ class ConversableAgent(Agent):
|
||||
return False, None
|
||||
if messages is None:
|
||||
messages = self._oai_messages[sender]
|
||||
last_n_messages = code_execution_config.pop("last_n_messages", 1)
|
||||
last_n_messages = code_execution_config.pop("last_n_messages", "auto")
|
||||
|
||||
if not (isinstance(last_n_messages, (int, float)) and last_n_messages >= 0) and last_n_messages != "auto":
|
||||
raise ValueError("last_n_messages must be either a non-negative integer, or the string 'auto'.")
|
||||
|
||||
messages_to_scan = last_n_messages
|
||||
if last_n_messages == "auto":
|
||||
|
@ -323,6 +323,15 @@ def test_generate_code_execution_reply():
|
||||
)
|
||||
assert agent._code_execution_config["last_n_messages"] == "auto"
|
||||
|
||||
# scenario 8: if last_n_messages is misconfigures, we expect to see an error
|
||||
with pytest.raises(ValueError):
|
||||
agent._code_execution_config = {"last_n_messages": -1, "use_docker": False}
|
||||
agent.generate_code_execution_reply([code_message])
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
agent._code_execution_config = {"last_n_messages": "hello world", "use_docker": False}
|
||||
agent.generate_code_execution_reply([code_message])
|
||||
|
||||
|
||||
def test_max_consecutive_auto_reply():
|
||||
agent = ConversableAgent("a0", max_consecutive_auto_reply=2, llm_config=False, human_input_mode="NEVER")
|
||||
@ -987,6 +996,6 @@ if __name__ == "__main__":
|
||||
# test_trigger()
|
||||
# test_context()
|
||||
# test_max_consecutive_auto_reply()
|
||||
# test_generate_code_execution_reply()
|
||||
test_generate_code_execution_reply()
|
||||
# test_conversable_agent()
|
||||
test_no_llm_config()
|
||||
# test_no_llm_config()
|
||||
|
Loading…
x
Reference in New Issue
Block a user