Skip to content

Commit d6b0afe

Browse files
committed
refactor: various config cleanups
1 parent 5b40994 commit d6b0afe

File tree

11 files changed

+223
-213
lines changed

11 files changed

+223
-213
lines changed

samples/task_centric_memory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import asyncio
22
from autogen_agentchat.ui import Console
33
from autogen_ext.models.openai import OpenAIChatCompletionClient
4-
from magentic_ui import OrchestratorConfig, get_task_team
4+
from magentic_ui.teams.orchestrator.orchestrator_config import OrchestratorConfig
5+
from magentic_ui import get_task_team
56
from magentic_ui.types import Plan
67
from autogen_ext.experimental.task_centric_memory import MemoryController
78
from autogen_ext.experimental.task_centric_memory.utils import PageLogger

src/magentic_ui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .task_team import get_task_team
2-
from .orchestrator_config import OrchestratorConfig
2+
from .teams.orchestrator.orchestrator_config import OrchestratorConfig
33
from .input_func import AsyncInputFunc, InputFuncType, InputRequestType, SyncInputFunc
44
from .approval_guard import (
55
BaseApprovalGuard,

src/magentic_ui/_cli.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
from typing import Any, Optional, Literal, cast
1212
from autogen_core import EVENT_LOGGER_NAME, CancellationToken
1313
from autogen_agentchat.ui import Console
14-
from .orchestrator_config import OrchestratorConfig
1514
from .task_team import get_task_team
1615
from loguru import logger
1716
import logging
1817
from .utils import LLMCallFilter
1918
from .types import RunPaths
19+
from .magentic_ui_config import MagenticUIConfig
20+
from .endpoint_configs import EndpointConfigs
2021

2122
logging.basicConfig(level=logging.WARNING, handlers=[])
2223
logger_llm = logging.getLogger(EVENT_LOGGER_NAME)
@@ -84,16 +85,6 @@ async def get_team(
8485
print(f"Deleting state file: {state_file}")
8586
os.remove(state_file)
8687

87-
config = OrchestratorConfig(
88-
cooperative_planning=cooperative_planning,
89-
autonomous_execution=autonomous_execution,
90-
allow_for_replans=True,
91-
do_bing_search=False,
92-
allow_follow_up_input=False,
93-
final_answer_prompt=final_answer_prompt,
94-
model_context_token_limit=model_context_token_limit,
95-
)
96-
9788
if inside_docker:
9889
# Use environment variables as fallback if paths not provided
9990
if internal_workspace_root is None:
@@ -142,23 +133,36 @@ async def get_team(
142133
with open(client_config, "r") as f:
143134
client_config_dict = yaml.safe_load(f)
144135

145-
team = await get_task_team(
146-
orchestrator_config=config,
147-
input_func=cancellable_input,
148-
paths=paths,
136+
endpoint_configs = EndpointConfigs(
137+
orchestrator=client_config_dict.get("orchestrator_client", None),
138+
web_surfer=client_config_dict.get("web_surfer_client", None),
139+
coder=client_config_dict.get("coder_client", None),
140+
file_surfer=client_config_dict.get("file_surfer_client", None),
141+
)
142+
143+
magentic_ui_config = MagenticUIConfig(
144+
endpoint_configs=endpoint_configs,
145+
approval_policy=action_policy,
146+
cooperative_planning=cooperative_planning,
147+
autonomous_execution=autonomous_execution,
148+
allow_for_replans=True,
149+
do_bing_search=False,
150+
model_context_token_limit=model_context_token_limit,
151+
allow_follow_up_input=False,
152+
final_answer_prompt=final_answer_prompt,
149153
playwright_port=playwright_port,
150154
novnc_port=novnc_port,
151-
inside_docker=inside_docker,
152-
model_context_token_limit=model_context_token_limit,
153-
endpoint_config_orch=client_config_dict.get("orchestrator_client", None),
154-
endpoint_config_websurfer=client_config_dict.get("web_surfer_client", None),
155-
endpoint_config_coder=client_config_dict.get("coder_client", None),
156-
endpoint_config_file_surfer=client_config_dict.get("file_surfer_client", None),
157-
approval_policy=action_policy,
158155
user_proxy_type=user_proxy_type,
159156
task=task_metadata,
160157
hints=hints,
161158
answer=answer,
159+
inside_docker=inside_docker,
160+
)
161+
162+
team = await get_task_team(
163+
magentic_ui_config=magentic_ui_config,
164+
input_func=cancellable_input,
165+
paths=paths,
162166
)
163167

164168
try:

src/magentic_ui/backend/teammanager/teammanager.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
from autogen_core.logging import LLMCallEvent
2727
from ...task_team import get_task_team
2828
from ...teams import GroupChat
29-
from ...types import SimplifiedConfig, RunPaths
29+
from ...types import RunPaths
30+
from ...endpoint_configs import EndpointConfigs
31+
from ...magentic_ui_config import MagenticUIConfig
3032
from ...input_func import InputFuncType
3133
from ...agents import WebSurfer
3234

@@ -161,46 +163,42 @@ async def _create_team(
161163
logger.error(f"Failed to parse model configurations: {e}")
162164

163165
# Use model configs from settings if available, otherwise fall back to config
164-
endpoint_configs = {
165-
"orchestrator_client": model_configs.get(
166+
endpoint_configs = EndpointConfigs(
167+
orchestrator=model_configs.get(
166168
"orchestrator_client",
167169
self.config.get("orchestrator_client", None),
168170
),
169-
"web_surfer_client": model_configs.get(
171+
web_surfer=model_configs.get(
170172
"web_surfer_client",
171173
self.config.get("web_surfer_client", None),
172174
),
173-
"coder_client": model_configs.get(
175+
coder=model_configs.get(
174176
"coder_client", self.config.get("coder_client", None)
175177
),
176-
"file_surfer_client": model_configs.get(
178+
file_surfer=model_configs.get(
177179
"file_surfer_client",
178180
self.config.get("file_surfer_client", None),
179181
),
180-
"action_guard_client": model_configs.get(
182+
action_guard=model_configs.get(
181183
"action_guard_client",
182184
self.config.get("action_guard_client", None),
183185
),
184-
}
186+
)
187+
188+
magentic_ui_config = MagenticUIConfig(
189+
**(settings_config or {}),
190+
endpoint_configs=endpoint_configs,
191+
playwright_port=playwright_port,
192+
novnc_port=novnc_port,
193+
inside_docker=self.inside_docker,
194+
)
185195

186196
self.team = cast(
187197
Team,
188198
await get_task_team(
199+
magentic_ui_config=magentic_ui_config,
189200
input_func=input_func,
190-
simplified_config=SimplifiedConfig(**(settings_config or {})),
191201
paths=paths,
192-
inside_docker=self.inside_docker,
193-
playwright_port=playwright_port,
194-
novnc_port=novnc_port,
195-
endpoint_config_orch=endpoint_configs["orchestrator_client"],
196-
endpoint_config_websurfer=endpoint_configs["web_surfer_client"],
197-
endpoint_config_coder=endpoint_configs["coder_client"],
198-
endpoint_config_file_surfer=endpoint_configs[
199-
"file_surfer_client"
200-
],
201-
endpoint_config_action_guard=endpoint_configs[
202-
"action_guard_client"
203-
],
204202
),
205203
)
206204
if hasattr(self.team, "_participants"):
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from dataclasses import dataclass
2+
from typing import Optional, Union, Dict, Any
3+
4+
from autogen_core import ComponentModel
5+
6+
7+
@dataclass
8+
class EndpointConfigs:
9+
"""Configuration class for Magentic UI endpoints.
10+
Attributes:
11+
orchestrator (Optional[Union[ComponentModel, Dict[str, Any]]]): Configuration for the orchestrator component. Default: None.
12+
web_surfer (Optional[Union[ComponentModel, Dict[str, Any]]]): Configuration for the web surfer component. Default: None.
13+
coder (Optional[Union[ComponentModel, Dict[str, Any]]]): Configuration for the coder component. Default: None.
14+
file_surfer (Optional[Union[ComponentModel, Dict[str, Any]]]): Configuration for the file surfer component. Default: None.
15+
action_guard (Optional[Union[ComponentModel, Dict[str, Any]]]): Configuration for the action guard component. Default: None.
16+
"""
17+
18+
orchestrator: Optional[Union[ComponentModel, Dict[str, Any]]] = None
19+
web_surfer: Optional[Union[ComponentModel, Dict[str, Any]]] = None
20+
coder: Optional[Union[ComponentModel, Dict[str, Any]]] = None
21+
file_surfer: Optional[Union[ComponentModel, Dict[str, Any]]] = None
22+
action_guard: Optional[Union[ComponentModel, Dict[str, Any]]] = None
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from pydantic import BaseModel
2+
from typing import Optional, List, Literal
3+
from .types import Plan
4+
from .endpoint_configs import EndpointConfigs
5+
from pydantic import Field
6+
7+
8+
class MagenticUIConfig(BaseModel):
9+
"""
10+
A simplified set of configuration options for Magentic-UI.
11+
12+
Attributes:
13+
endpoint_configs (EndpointConfigs): Configuration for various endpoints.
14+
cooperative_planning (bool): Disable co-planning mode (default: enabled), user will not be involved in the planning process. Default: True.
15+
autonomous_execution (bool): Enable autonomous execution mode (default: disabled), user will not be involved in the execution. Default: False.
16+
allowed_websites (List[str], optional): List of websites that are permitted.
17+
max_actions_per_step (int): Maximum number of actions allowed per step. Default: 5.
18+
multiple_tools_per_call (bool): Allow multiple tools to be called in a single step. Default: False.
19+
max_turns (int): Maximum number of operational turns allowed. Default: 20.
20+
plan (Plan, optional): A pre-defined plan. In cooperative planning mode, the plan will be enhanced with user feedback.
21+
approval_policy (str, optional): Policy for action approval. Default: "auto-conservative".
22+
allow_for_replans (bool): Whether to allow the orchestrator to create a new plan when needed. Default: True.
23+
do_bing_search (bool): Flag to determine if Bing search should be used to come up with information for the plan. Default: False.
24+
websurfer_loop (bool): Flag to determine if the websurfer should loop through the plan. Default: False.
25+
retrieve_relevant_plans (Literal["never", "hint", "reuse"]): Determines if the orchestrator should retrieve relevant plans from memory. Default: `never`.
26+
memory_controller_key (str, optional): The key to retrieve the memory_controller for a particular user. Default: None.
27+
model_context_token_limit (int, optional): The maximum number of tokens the model can use. Default: 110000.
28+
allow_follow_up_input (bool): Flag to determine if new input should be requested after a final answer is given. Default: False.
29+
final_answer_prompt (str, optional): Prompt for the final answer. Should be a string that can be formatted with the {task} variable. Default: None.
30+
playwright_port (int, optional): Port for the Playwright browser. Default: -1 (auto-assign).
31+
novnc_port (int, optional): Port for the noVNC server. Default: -1 (auto-assign).
32+
user_proxy_type (str, optional): Type of user proxy agent to use ("dummy", "metadata", or None for default). Default: None.
33+
task (str, optional): Task to be performed by the agents. Default: None.
34+
hints (str, optional): Helpful hints for the task. Default: None.
35+
answer (str, optional): Answer to the task. Default: None.
36+
inside_docker (bool, optional): Whether to run inside a docker container. Default: True.
37+
"""
38+
39+
endpoint_configs: EndpointConfigs = Field(default_factory=EndpointConfigs)
40+
cooperative_planning: bool = True
41+
autonomous_execution: bool = False
42+
allowed_websites: Optional[List[str]] = None
43+
max_actions_per_step: int = 5
44+
multiple_tools_per_call: bool = False
45+
max_turns: int = 20
46+
plan: Optional[Plan] = None
47+
approval_policy: Literal[
48+
"always", "never", "auto-conservative", "auto-permissive"
49+
] = "auto-conservative"
50+
allow_for_replans: bool = True
51+
do_bing_search: bool = False
52+
websurfer_loop: bool = False
53+
retrieve_relevant_plans: Literal["never", "hint", "reuse"] = "never"
54+
memory_controller_key: Optional[str] = None
55+
model_context_token_limit: int = 110000
56+
allow_follow_up_input: bool = True
57+
final_answer_prompt: str | None = None
58+
playwright_port: int = -1
59+
novnc_port: int = -1
60+
user_proxy_type: Optional[str] = None
61+
task: Optional[str] = None
62+
hints: Optional[str] = None
63+
answer: Optional[str] = None
64+
inside_docker: bool = True

0 commit comments

Comments
 (0)