Skip to content

Commit bf08856

Browse files
davorrunjesonichi
andauthored
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 <[email protected]>
1 parent 24418bd commit bf08856

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

autogen/agentchat/conversable_agent.py

+6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ def __init__(
130130
description (str): a short description of the agent. This description is used by other agents
131131
(e.g. the GroupChatManager) to decide when to call upon this agent. (Default: system_message)
132132
"""
133+
# we change code_execution_config below and we have to make sure we don't change the input
134+
# in case of UserProxyAgent, without this we could even change the default value {}
135+
code_execution_config = (
136+
code_execution_config.copy() if hasattr(code_execution_config, "copy") else code_execution_config
137+
)
138+
133139
self._name = name
134140
# a dictionary of conversations, default value is list
135141
self._oai_messages = defaultdict(list)

autogen/agentchat/user_proxy_agent.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(
3030
max_consecutive_auto_reply: Optional[int] = None,
3131
human_input_mode: Literal["ALWAYS", "TERMINATE", "NEVER"] = "ALWAYS",
3232
function_map: Optional[Dict[str, Callable]] = None,
33-
code_execution_config: Optional[Union[Dict, Literal[False]]] = None,
33+
code_execution_config: Union[Dict, Literal[False]] = {},
3434
default_auto_reply: Optional[Union[str, Dict, None]] = "",
3535
llm_config: Optional[Union[Dict, Literal[False]]] = False,
3636
system_message: Optional[Union[str, List]] = "",

test/agentchat/test_agent_setup_with_use_docker_settings.py

+15-30
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@
1616
skip = False or skip_openai
1717

1818

19-
def get_current_autogen_env_var():
20-
return os.environ.get("AUTOGEN_USE_DOCKER", None)
21-
22-
23-
def restore_autogen_env_var(current_env_value):
24-
if current_env_value is None:
25-
del os.environ["AUTOGEN_USE_DOCKER"]
26-
else:
27-
os.environ["AUTOGEN_USE_DOCKER"] = current_env_value
28-
29-
3019
def docker_running():
3120
return is_docker_running() or in_docker_container()
3221

@@ -54,32 +43,36 @@ def test_agent_setup_with_use_docker_false():
5443

5544

5645
@pytest.mark.skipif(skip, reason="openai not installed")
57-
def test_agent_setup_with_env_variable_false_and_docker_running():
58-
current_env_value = get_current_autogen_env_var()
46+
def test_agent_setup_with_env_variable_false_and_docker_running(monkeypatch):
47+
monkeypatch.setenv("AUTOGEN_USE_DOCKER", "False")
5948

60-
os.environ["AUTOGEN_USE_DOCKER"] = "False"
6149
user_proxy = UserProxyAgent(
6250
name="test_agent",
6351
human_input_mode="NEVER",
6452
)
6553

6654
assert user_proxy._code_execution_config["use_docker"] is False
6755

68-
restore_autogen_env_var(current_env_value)
69-
7056

7157
@pytest.mark.skipif(skip or (not docker_running()), reason="openai not installed OR docker not running")
72-
def test_agent_setup_with_default_and_docker_running():
58+
def test_agent_setup_with_default_and_docker_running(monkeypatch):
59+
monkeypatch.delenv("AUTOGEN_USE_DOCKER", raising=False)
60+
61+
assert os.getenv("AUTOGEN_USE_DOCKER") is None
62+
7363
user_proxy = UserProxyAgent(
7464
name="test_agent",
7565
human_input_mode="NEVER",
7666
)
7767

68+
assert os.getenv("AUTOGEN_USE_DOCKER") is None
69+
7870
assert user_proxy._code_execution_config["use_docker"] is True
7971

8072

8173
@pytest.mark.skipif(skip or (docker_running()), reason="openai not installed OR docker running")
82-
def test_raises_error_agent_setup_with_default_and_docker_not_running():
74+
def test_raises_error_agent_setup_with_default_and_docker_not_running(monkeypatch):
75+
monkeypatch.delenv("AUTOGEN_USE_DOCKER", raising=False)
8376
with pytest.raises(RuntimeError):
8477
UserProxyAgent(
8578
name="test_agent",
@@ -88,31 +81,23 @@ def test_raises_error_agent_setup_with_default_and_docker_not_running():
8881

8982

9083
@pytest.mark.skipif(skip or (docker_running()), reason="openai not installed OR docker running")
91-
def test_raises_error_agent_setup_with_env_variable_true_and_docker_not_running():
92-
current_env_value = get_current_autogen_env_var()
93-
94-
os.environ["AUTOGEN_USE_DOCKER"] = "True"
84+
def test_raises_error_agent_setup_with_env_variable_true_and_docker_not_running(monkeypatch):
85+
monkeypatch.setenv("AUTOGEN_USE_DOCKER", "True")
9586

9687
with pytest.raises(RuntimeError):
9788
UserProxyAgent(
9889
name="test_agent",
9990
human_input_mode="NEVER",
10091
)
10192

102-
restore_autogen_env_var(current_env_value)
103-
10493

10594
@pytest.mark.skipif(skip or (not docker_running()), reason="openai not installed OR docker not running")
106-
def test_agent_setup_with_env_variable_true_and_docker_running():
107-
current_env_value = get_current_autogen_env_var()
108-
109-
os.environ["AUTOGEN_USE_DOCKER"] = "True"
95+
def test_agent_setup_with_env_variable_true_and_docker_running(monkeypatch):
96+
monkeypatch.setenv("AUTOGEN_USE_DOCKER", "True")
11097

11198
user_proxy = UserProxyAgent(
11299
name="test_agent",
113100
human_input_mode="NEVER",
114101
)
115102

116103
assert user_proxy._code_execution_config["use_docker"] is True
117-
118-
restore_autogen_env_var(current_env_value)

0 commit comments

Comments
 (0)