-
Notifications
You must be signed in to change notification settings - Fork 45
/
task_config.py
54 lines (43 loc) · 1.49 KB
/
task_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import re
from argparse import ArgumentParser
from typing import List, Optional, Tuple
from pydantic import BaseModel
class AgentConfig(BaseModel):
verbose: bool = False
gsite: Optional[str] = None
do_reflect: bool = False
@classmethod
def from_input(cls, input_str: str) -> Tuple[str, "AgentConfig"]:
"""
parse input string into AgentConfig. The configurations are
at the end of the string
"""
parts = re.split(r"(?=--)", input_str)
configs = []
for part in parts[1:]:
part = part.strip()
configs.extend(part.split())
return parts[0].strip(), cls.from_config(configs)
@classmethod
def from_config(cls, configs: List[str]) -> "AgentConfig":
parser = ArgumentParser()
parser.add_argument(
"--verbose",
action="store_true",
help="enable verbose messaging during agent execution",
)
parser.add_argument(
"--gsite",
type=str,
default=None,
help="site to be used for the Google search tool.",
)
parser.add_argument(
"--do-reflect",
action="store_true",
help="enable performing the reflection step for each agent.",
)
args, unknown = parser.parse_known_args(configs)
if len(unknown) > 0:
raise ValueError(f"Invalid configuration, check your input: {unknown}")
return AgentConfig(**args.__dict__)