Fix type and default value of the code_execution_config parameter in UserProxyAgent (#1996)

* fix type and default value of the code_execution_config of UserProxAgent

* fix type and default value of the code_execution_config of UserProxAgent

* set default value of llm_config in UserProxyAgent to None

* fixed tests

* revert llm_config to False

---------

Co-authored-by: Chi Wang <wang.chi@microsoft.com>
This commit is contained in:
Davor Runje 2024-03-13 23:57:43 +01:00 committed by GitHub
parent 24418bd5d2
commit bf08856389
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 31 deletions

View File

@ -130,6 +130,12 @@ class ConversableAgent(LLMAgent):
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)

View File

@ -30,7 +30,7 @@ class UserProxyAgent(ConversableAgent):
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,
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]] = "",

View File

@ -16,17 +16,6 @@ else:
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)