From a4377d8d966f58f4b19b8aa823231a6814458b4d Mon Sep 17 00:00:00 2001 From: Davor Runje Date: Wed, 13 Mar 2024 10:51:43 +0000 Subject: [PATCH 1/5] fix type and default value of the code_execution_config of UserProxAgent --- autogen/agentchat/user_proxy_agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autogen/agentchat/user_proxy_agent.py b/autogen/agentchat/user_proxy_agent.py index a92d58cfde1..fba930782eb 100644 --- a/autogen/agentchat/user_proxy_agent.py +++ b/autogen/agentchat/user_proxy_agent.py @@ -29,8 +29,8 @@ def __init__( is_termination_msg: Optional[Callable[[Dict], bool]] = None, max_consecutive_auto_reply: Optional[int] = None, human_input_mode: Literal["ALWAYS", "TERMINATE", "NEVER"] = "ALWAYS", - function_map: Optional[Dict[str, Callable]] = None, - code_execution_config: Optional[Union[Dict, Literal[False]]] = None, + function_map: Dict[str, Callable] = {}, + code_execution_config: Union[Dict, Literal[False]] = {}, default_auto_reply: Optional[Union[str, Dict, None]] = "", llm_config: Optional[Union[Dict, Literal[False]]] = False, system_message: Optional[Union[str, List]] = "", From 0e55327011015f29dff531a8de45611e7227856d Mon Sep 17 00:00:00 2001 From: Davor Runje Date: Wed, 13 Mar 2024 10:57:44 +0000 Subject: [PATCH 2/5] fix type and default value of the code_execution_config of UserProxAgent --- autogen/agentchat/user_proxy_agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogen/agentchat/user_proxy_agent.py b/autogen/agentchat/user_proxy_agent.py index fba930782eb..980ca12c633 100644 --- a/autogen/agentchat/user_proxy_agent.py +++ b/autogen/agentchat/user_proxy_agent.py @@ -29,7 +29,7 @@ def __init__( is_termination_msg: Optional[Callable[[Dict], bool]] = None, max_consecutive_auto_reply: Optional[int] = None, human_input_mode: Literal["ALWAYS", "TERMINATE", "NEVER"] = "ALWAYS", - function_map: Dict[str, Callable] = {}, + function_map: Optional[Dict[str, Callable]] = None, code_execution_config: Union[Dict, Literal[False]] = {}, default_auto_reply: Optional[Union[str, Dict, None]] = "", llm_config: Optional[Union[Dict, Literal[False]]] = False, From 6d2953d1b02dbb0cb7a975d6b69cd1ef8624c3bd Mon Sep 17 00:00:00 2001 From: Davor Runje Date: Wed, 13 Mar 2024 19:22:44 +0000 Subject: [PATCH 3/5] set default value of llm_config in UserProxyAgent to None --- autogen/agentchat/user_proxy_agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogen/agentchat/user_proxy_agent.py b/autogen/agentchat/user_proxy_agent.py index 980ca12c633..5614879ad87 100644 --- a/autogen/agentchat/user_proxy_agent.py +++ b/autogen/agentchat/user_proxy_agent.py @@ -32,7 +32,7 @@ def __init__( function_map: Optional[Dict[str, Callable]] = None, code_execution_config: Union[Dict, Literal[False]] = {}, default_auto_reply: Optional[Union[str, Dict, None]] = "", - llm_config: Optional[Union[Dict, Literal[False]]] = False, + llm_config: Optional[Union[Dict, Literal[False]]] = None, system_message: Optional[Union[str, List]] = "", description: Optional[str] = None, ): From 6d1a646fbc78b53c78eb9dfdd7b048bf7c8cb68d Mon Sep 17 00:00:00 2001 From: Davor Runje Date: Wed, 13 Mar 2024 20:16:46 +0000 Subject: [PATCH 4/5] fixed tests --- autogen/agentchat/conversable_agent.py | 6 +++ ...st_agent_setup_with_use_docker_settings.py | 45 +++++++------------ 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/autogen/agentchat/conversable_agent.py b/autogen/agentchat/conversable_agent.py index 609a72b4768..0c6d4c8128e 100644 --- a/autogen/agentchat/conversable_agent.py +++ b/autogen/agentchat/conversable_agent.py @@ -130,6 +130,12 @@ def __init__( description (str): a short description of the agent. This description is used by other agents (e.g. the GroupChatManager) to decide when to call upon this agent. (Default: system_message) """ + # we change code_execution_config below and we have to make sure we don't change the input + # in case of UserProxyAgent, without this we could even change the default value {} + code_execution_config = ( + code_execution_config.copy() if hasattr(code_execution_config, "copy") else code_execution_config + ) + self._name = name # a dictionary of conversations, default value is list self._oai_messages = defaultdict(list) diff --git a/test/agentchat/test_agent_setup_with_use_docker_settings.py b/test/agentchat/test_agent_setup_with_use_docker_settings.py index 8cda4466e16..4ec05ae1a75 100644 --- a/test/agentchat/test_agent_setup_with_use_docker_settings.py +++ b/test/agentchat/test_agent_setup_with_use_docker_settings.py @@ -16,17 +16,6 @@ skip = False or skip_openai -def get_current_autogen_env_var(): - return os.environ.get("AUTOGEN_USE_DOCKER", None) - - -def restore_autogen_env_var(current_env_value): - if current_env_value is None: - del os.environ["AUTOGEN_USE_DOCKER"] - else: - os.environ["AUTOGEN_USE_DOCKER"] = current_env_value - - def docker_running(): return is_docker_running() or in_docker_container() @@ -54,10 +43,9 @@ def test_agent_setup_with_use_docker_false(): @pytest.mark.skipif(skip, reason="openai not installed") -def test_agent_setup_with_env_variable_false_and_docker_running(): - current_env_value = get_current_autogen_env_var() +def test_agent_setup_with_env_variable_false_and_docker_running(monkeypatch): + monkeypatch.setenv("AUTOGEN_USE_DOCKER", "False") - os.environ["AUTOGEN_USE_DOCKER"] = "False" user_proxy = UserProxyAgent( name="test_agent", human_input_mode="NEVER", @@ -65,21 +53,26 @@ def test_agent_setup_with_env_variable_false_and_docker_running(): assert user_proxy._code_execution_config["use_docker"] is False - restore_autogen_env_var(current_env_value) - @pytest.mark.skipif(skip or (not docker_running()), reason="openai not installed OR docker not running") -def test_agent_setup_with_default_and_docker_running(): +def test_agent_setup_with_default_and_docker_running(monkeypatch): + monkeypatch.delenv("AUTOGEN_USE_DOCKER", raising=False) + + assert os.getenv("AUTOGEN_USE_DOCKER") is None + user_proxy = UserProxyAgent( name="test_agent", human_input_mode="NEVER", ) + assert os.getenv("AUTOGEN_USE_DOCKER") is None + assert user_proxy._code_execution_config["use_docker"] is True @pytest.mark.skipif(skip or (docker_running()), reason="openai not installed OR docker running") -def test_raises_error_agent_setup_with_default_and_docker_not_running(): +def test_raises_error_agent_setup_with_default_and_docker_not_running(monkeypatch): + monkeypatch.delenv("AUTOGEN_USE_DOCKER", raising=False) with pytest.raises(RuntimeError): UserProxyAgent( name="test_agent", @@ -88,10 +81,8 @@ def test_raises_error_agent_setup_with_default_and_docker_not_running(): @pytest.mark.skipif(skip or (docker_running()), reason="openai not installed OR docker running") -def test_raises_error_agent_setup_with_env_variable_true_and_docker_not_running(): - current_env_value = get_current_autogen_env_var() - - os.environ["AUTOGEN_USE_DOCKER"] = "True" +def test_raises_error_agent_setup_with_env_variable_true_and_docker_not_running(monkeypatch): + monkeypatch.setenv("AUTOGEN_USE_DOCKER", "True") with pytest.raises(RuntimeError): UserProxyAgent( @@ -99,14 +90,10 @@ def test_raises_error_agent_setup_with_env_variable_true_and_docker_not_running( human_input_mode="NEVER", ) - restore_autogen_env_var(current_env_value) - @pytest.mark.skipif(skip or (not docker_running()), reason="openai not installed OR docker not running") -def test_agent_setup_with_env_variable_true_and_docker_running(): - current_env_value = get_current_autogen_env_var() - - os.environ["AUTOGEN_USE_DOCKER"] = "True" +def test_agent_setup_with_env_variable_true_and_docker_running(monkeypatch): + monkeypatch.setenv("AUTOGEN_USE_DOCKER", "True") user_proxy = UserProxyAgent( name="test_agent", @@ -114,5 +101,3 @@ def test_agent_setup_with_env_variable_true_and_docker_running(): ) assert user_proxy._code_execution_config["use_docker"] is True - - restore_autogen_env_var(current_env_value) From 7e2d6f57accc2628a3482eaa8e8ae8b128178e1f Mon Sep 17 00:00:00 2001 From: Davor Runje Date: Wed, 13 Mar 2024 20:30:08 +0000 Subject: [PATCH 5/5] revert llm_config to False --- autogen/agentchat/user_proxy_agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogen/agentchat/user_proxy_agent.py b/autogen/agentchat/user_proxy_agent.py index 5614879ad87..980ca12c633 100644 --- a/autogen/agentchat/user_proxy_agent.py +++ b/autogen/agentchat/user_proxy_agent.py @@ -32,7 +32,7 @@ def __init__( function_map: Optional[Dict[str, Callable]] = None, code_execution_config: Union[Dict, Literal[False]] = {}, default_auto_reply: Optional[Union[str, Dict, None]] = "", - llm_config: Optional[Union[Dict, Literal[False]]] = None, + llm_config: Optional[Union[Dict, Literal[False]]] = False, system_message: Optional[Union[str, List]] = "", description: Optional[str] = None, ):