Skip to content

Commit 97de75e

Browse files
WaelKarkoubsonichi
authored andcommitted
human input mode annotations fixed (#2864)
Co-authored-by: Chi Wang <[email protected]>
1 parent 921e616 commit 97de75e

11 files changed

+21
-31
lines changed

autogen/agentchat/assistant_agent.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(
3838
llm_config: Optional[Union[Dict, Literal[False]]] = None,
3939
is_termination_msg: Optional[Callable[[Dict], bool]] = None,
4040
max_consecutive_auto_reply: Optional[int] = None,
41-
human_input_mode: Optional[str] = "NEVER",
41+
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "NEVER",
4242
description: Optional[str] = None,
4343
**kwargs,
4444
):

autogen/agentchat/contrib/compressible_agent.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import asyncio
21
import copy
32
import inspect
43
import logging
5-
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
4+
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union
65
from warnings import warn
76

87
from autogen import Agent, ConversableAgent, OpenAIWrapper
@@ -60,7 +59,7 @@ def __init__(
6059
system_message: Optional[str] = DEFAULT_SYSTEM_MESSAGE,
6160
is_termination_msg: Optional[Callable[[Dict], bool]] = None,
6261
max_consecutive_auto_reply: Optional[int] = None,
63-
human_input_mode: Optional[str] = "NEVER",
62+
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "NEVER",
6463
function_map: Optional[Dict[str, Callable]] = None,
6564
code_execution_config: Optional[Union[Dict, bool]] = False,
6665
llm_config: Optional[Union[Dict, bool]] = None,

autogen/agentchat/contrib/math_user_proxy_agent.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import re
33
from time import sleep
4-
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
4+
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union
55

66
from pydantic import BaseModel, Extra, root_validator
77

@@ -136,7 +136,7 @@ def __init__(
136136
is_termination_msg: Optional[
137137
Callable[[Dict], bool]
138138
] = _is_termination_msg_mathchat, # terminate if \boxed{} in message
139-
human_input_mode: Optional[str] = "NEVER", # Fully automated
139+
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "NEVER", # Fully automated
140140
default_auto_reply: Optional[Union[str, Dict, None]] = DEFAULT_REPLY,
141141
max_invalid_q_per_step=3, # a parameter needed in MathChat
142142
**kwargs,

autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, Dict, List, Optional
1+
from typing import Callable, Dict, List, Literal, Optional
22

33
from autogen.agentchat.contrib.retrieve_user_proxy_agent import RetrieveUserProxyAgent
44
from autogen.agentchat.contrib.vectordb.utils import (
@@ -23,7 +23,7 @@ class QdrantRetrieveUserProxyAgent(RetrieveUserProxyAgent):
2323
def __init__(
2424
self,
2525
name="RetrieveChatAgent", # default set to RetrieveChatAgent
26-
human_input_mode: Optional[str] = "ALWAYS",
26+
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "ALWAYS",
2727
is_termination_msg: Optional[Callable[[Dict], bool]] = None,
2828
retrieve_config: Optional[Dict] = None, # config for the retrieve agent
2929
**kwargs,

autogen/agentchat/contrib/retrieve_user_proxy_agent.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import hashlib
22
import os
33
import re
4-
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
4+
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union
55

66
from IPython import get_ipython
77

@@ -92,7 +92,7 @@ class RetrieveUserProxyAgent(UserProxyAgent):
9292
def __init__(
9393
self,
9494
name="RetrieveChatAgent", # default set to RetrieveChatAgent
95-
human_input_mode: Optional[str] = "ALWAYS",
95+
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "ALWAYS",
9696
is_termination_msg: Optional[Callable[[Dict], bool]] = None,
9797
retrieve_config: Optional[Dict] = None, # config for the retrieve agent
9898
**kwargs,

autogen/agentchat/contrib/society_of_mind_agent.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# ruff: noqa: E722
22
import copy
3-
import json
43
import traceback
5-
from dataclasses import dataclass
64
from typing import Callable, Dict, List, Literal, Optional, Tuple, Union
75

86
from autogen import Agent, ConversableAgent, GroupChat, GroupChatManager, OpenAIWrapper
@@ -36,7 +34,7 @@ def __init__(
3634
response_preparer: Optional[Union[str, Callable]] = None,
3735
is_termination_msg: Optional[Callable[[Dict], bool]] = None,
3836
max_consecutive_auto_reply: Optional[int] = None,
39-
human_input_mode: Optional[str] = "TERMINATE",
37+
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "TERMINATE",
4038
function_map: Optional[Dict[str, Callable]] = None,
4139
code_execution_config: Union[Dict, Literal[False]] = False,
4240
llm_config: Optional[Union[Dict, Literal[False]]] = False,

autogen/agentchat/contrib/text_analyzer_agent.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
1+
from typing import Any, Dict, List, Literal, Optional, Tuple, Union
22

3-
from autogen import oai
43
from autogen.agentchat.agent import Agent
54
from autogen.agentchat.assistant_agent import ConversableAgent
65

@@ -17,7 +16,7 @@ def __init__(
1716
self,
1817
name="analyzer",
1918
system_message: Optional[str] = system_message,
20-
human_input_mode: Optional[str] = "NEVER",
19+
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "NEVER",
2120
llm_config: Optional[Union[Dict, bool]] = None,
2221
**kwargs,
2322
):

autogen/agentchat/contrib/web_surfer.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(
3434
description: Optional[str] = DEFAULT_DESCRIPTION,
3535
is_termination_msg: Optional[Callable[[Dict[str, Any]], bool]] = None,
3636
max_consecutive_auto_reply: Optional[int] = None,
37-
human_input_mode: Optional[str] = "TERMINATE",
37+
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "TERMINATE",
3838
function_map: Optional[Dict[str, Callable]] = None,
3939
code_execution_config: Union[Dict, Literal[False]] = False,
4040
llm_config: Optional[Union[Dict, Literal[False]]] = None,
@@ -111,7 +111,9 @@ def _create_summarizer_client(self, summarizer_llm_config: Dict[str, Any], llm_c
111111
self.summarizer_llm_config = summarizer_llm_config # type: ignore[assignment]
112112

113113
# Create the summarizer client
114-
self.summarization_client = None if self.summarizer_llm_config is False else OpenAIWrapper(**self.summarizer_llm_config) # type: ignore[arg-type]
114+
self.summarization_client = (
115+
None if self.summarizer_llm_config is False else OpenAIWrapper(**self.summarizer_llm_config)
116+
) # type: ignore[arg-type]
115117

116118
def _register_functions(self) -> None:
117119
"""Register the functions for the inner assistant and user proxy."""
@@ -250,7 +252,7 @@ def _answer_from_page(
250252
def _summarize_page(
251253
url: Annotated[
252254
Optional[str], "[Optional] The url of the page to summarize. (Defaults to current page)"
253-
] = None
255+
] = None,
254256
) -> str:
255257
return _answer_from_page(url=url, question=None)
256258

autogen/agentchat/groupchat.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,6 @@ def _auto_select_speaker(
609609

610610
# Registered reply function for checking_agent, checks the result of the response for agent names
611611
def validate_speaker_name(recipient, messages, sender, config) -> Tuple[bool, Union[str, Dict, None]]:
612-
613612
# The number of retries left, starting at max_retries_for_selecting_speaker
614613
nonlocal attempts_left
615614
nonlocal attempt
@@ -708,7 +707,6 @@ async def a_auto_select_speaker(
708707

709708
# Registered reply function for checking_agent, checks the result of the response for agent names
710709
def validate_speaker_name(recipient, messages, sender, config) -> Tuple[bool, Union[str, Dict, None]]:
711-
712710
# The number of retries left, starting at max_retries_for_selecting_speaker
713711
nonlocal attempts_left
714712
nonlocal attempt
@@ -782,7 +780,6 @@ def _validate_speaker_name(
782780
mentions = self._mentioned_agents(select_name, agents)
783781

784782
if len(mentions) == 1:
785-
786783
# Success on retry, we have just one name mentioned
787784
selected_agent_name = next(iter(mentions))
788785

@@ -864,17 +861,14 @@ def _process_speaker_selection_result(self, result, last_speaker: ConversableAge
864861
865862
Used by auto_select_speaker and a_auto_select_speaker."""
866863
if len(result.chat_history) > 0:
867-
868864
# Use the final message, which will have the selected agent or reason for failure
869865
final_message = result.chat_history[-1]["content"]
870866

871867
if "[AGENT SELECTED]" in final_message:
872-
873868
# Have successfully selected an agent, return it
874869
return self.agent_by_name(final_message.replace("[AGENT SELECTED]", ""))
875870

876871
else: # "[AGENT SELECTION FAILED]"
877-
878872
# Failed to select an agent, so we'll select the next agent in the list
879873
next_agent = self.next_agent(last_speaker, agents)
880874

@@ -945,7 +939,7 @@ def __init__(
945939
name: Optional[str] = "chat_manager",
946940
# unlimited consecutive auto reply by default
947941
max_consecutive_auto_reply: Optional[int] = sys.maxsize,
948-
human_input_mode: Optional[str] = "NEVER",
942+
human_input_mode: Literal["ALWAYS", "NEVER", "TERMINATE"] = "NEVER",
949943
system_message: Optional[Union[str, List]] = "Group chat manager.",
950944
silent: bool = False,
951945
**kwargs,
@@ -1207,7 +1201,6 @@ def resume(
12071201

12081202
# Load the messages into the group chat
12091203
for i, message in enumerate(messages):
1210-
12111204
if "name" in message:
12121205
message_speaker_agent = self._groupchat.agent_by_name(message["name"])
12131206
else:
@@ -1312,7 +1305,6 @@ async def a_resume(
13121305

13131306
# Load the messages into the group chat
13141307
for i, message in enumerate(messages):
1315-
13161308
if "name" in message:
13171309
message_speaker_agent = self._groupchat.agent_by_name(message["name"])
13181310
else:

notebook/agentchat_agentoptimizer.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"import copy\n",
3535
"import json\n",
3636
"import os\n",
37-
"from typing import Any, Callable, Dict, List, Optional, Tuple, Union\n",
37+
"from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union\n",
3838
"\n",
3939
"from openai import BadRequestError\n",
4040
"\n",
@@ -119,7 +119,7 @@
119119
" self,\n",
120120
" name: Optional[str] = \"MathChatAgent\",\n",
121121
" is_termination_msg: Optional[Callable[[Dict], bool]] = is_termination_msg_mathchat,\n",
122-
" human_input_mode: Optional[str] = \"NEVER\",\n",
122+
" human_input_mode: Literal[\"ALWAYS\", \"NEVER\", \"TERMINATE\"] = \"NEVER\",\n",
123123
" default_auto_reply: Optional[Union[str, Dict, None]] = DEFAULT_REPLY,\n",
124124
" max_invalid_q_per_step=3,\n",
125125
" **kwargs,\n",

website/docs/topics/task_decomposition.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@
17801780
" llm_config: Optional[Union[Dict, Literal[False]]] = None,\n",
17811781
" is_termination_msg: Optional[Callable[[Dict], bool]] = None,\n",
17821782
" max_consecutive_auto_reply: Optional[int] = None,\n",
1783-
" human_input_mode: Optional[str] = \"NEVER\",\n",
1783+
" human_input_mode: Literal[\"ALWAYS\", \"NEVER\", \"TERMINATE\"] = \"NEVER\",\n",
17841784
" code_execution_config: Optional[Union[Dict, Literal[False]]] = False,\n",
17851785
" description: Optional[\n",
17861786
" str\n",

0 commit comments

Comments
 (0)