A programming framework for agentic AI
Autogenstudio Updates [Upload/Dowload of Skills/Workflows, Streaming Agent Replies, Agent Message Summarization] (#1801)
Victor Dibia4429d4d19f80
diff --git a/.gitignore b/.gitignoreindex 6bed53f7c..49a41e9ed 100644--- a/.gitignore+++ b/.gitignore@@ -182,3 +182,4 @@ test/agentchat/test_agent_scripts/*notebook/result.png+samples/apps/autogen-studio/autogenstudio/models/test/diff --git a/samples/apps/autogen-studio/Dockerfile b/samples/apps/autogen-studio/Dockerfilenew file mode 100644index 000000000..bb475db71--- /dev/null+++ b/samples/apps/autogen-studio/Dockerfile@@ -0,0 +1,17 @@+FROM python:3.10++WORKDIR /code++RUN pip install -U gunicorn autogenstudio++RUN useradd -m -u 1000 user+USER user+ENV HOME=/home/user \+ PATH=/home/user/.local/bin:$PATH \+ AUTOGENSTUDIO_APPDIR=/home/user/app++WORKDIR $HOME/app++COPY --chown=user . $HOME/app++CMD gunicorn -w $((2 * $(getconf _NPROCESSORS_ONLN) + 1)) --timeout 12600 -k uvicorn.workers.UvicornWorker autogenstudio.web.app:app --bind "0.0.0.0:8081"diff --git a/samples/apps/autogen-studio/README.md b/samples/apps/autogen-studio/README.mdindex 72dc2b9a4..28d95cd3e 100644--- a/samples/apps/autogen-studio/README.md+++ b/samples/apps/autogen-studio/README.md@@ -14,6 +14,9 @@ Code for AutoGen Studio is on GitHub at [microsoft/autogen](https://github.com/m> [!WARNING]> AutoGen Studio is currently under active development and we are iterating quickly. Kindly consider that we may introduce breaking changes in the releases during the upcoming weeks, and also the `README` might be outdated. We'll update the `README` as soon as we stabilize the API.+> [!NOTE] Updates+> March 12: Default directory for AutoGen Studio is now /home/<user>/.autogenstudio. You can also specify this directory using the `--appdir` argument when running the application. For example, `autogenstudio ui --appdir /path/to/folder`. This will store the database and other files in the specified directory e.g. `/path/to/folder/database.sqlite`. `.env` files in that directory will be used to set environment variables for the app.+### Capabilities / RoadmapSome of the capabilities supported by the app frontend include the following:diff --git a/samples/apps/autogen-studio/autogenstudio/chatmanager.py b/samples/apps/autogen-studio/autogenstudio/chatmanager.pyindex ee6d51d9d..222e7951e 100644--- a/samples/apps/autogen-studio/autogenstudio/chatmanager.py+++ b/samples/apps/autogen-studio/autogenstudio/chatmanager.py@@ -1,63 +1,225 @@+import asyncio+from datetime import datetimeimport json+from queue import Queueimport time-from typing import List-from .datamodel import AgentWorkFlowConfig, Message-from .utils import extract_successful_code_blocks, get_default_agent_config, get_modified_files-from .workflowmanager import AutoGenWorkFlowManager+from typing import Any, List, Dict, Optional, Tupleimport os+from fastapi import WebSocket, WebSocketDisconnect+import websockets+from .datamodel import AgentWorkFlowConfig, Message, SocketMessage+from .utils import extract_successful_code_blocks, get_modified_files, summarize_chat_history+from .workflowmanager import AutoGenWorkFlowManagerclass AutoGenChatManager:- def __init__(self) -> None:- pass+ """+ This class handles the automated generation and management of chat interactions+ using an automated workflow configuration and message queue.+ """++ def __init__(self, message_queue: Queue) -> None:+ """+ Initializes the AutoGenChatManager with a message queue.++ :param message_queue: A queue to use for sending messages asynchronously.+ """+ self.message_queue = message_queue++ def send(self, message: str) -> None:+ """+ Sends a message by putting it into the message queue.++ :param message: The message string to be sent.+ """+ if self.message_queue is not None:+ self.message_queue.put_nowait(message)++ def chat(+ self,+ message: Message,+ history: List[Dict[str, Any]],+ flow_config: Optional[AgentWorkFlowConfig] = None,+ connection_id: Optional[str] = None,+ user_dir: Optional[str] = None,+ **kwargs,+ ) -> Message:+ """+ Processes an incoming message according to the agent's workflow configuration+ and generates a response.- def chat(self, message: Message, history: List, flow_config: AgentWorkFlowConfig = None, **kwargs) -> None:- work_dir = kwargs.get("work_dir", None)- scratch_dir = os.path.join(work_dir, "scratch")+ :param message: An instance of `Message` representing an incoming message.+ :param history: A list of dictionaries, each representing a past interaction.+ :param flow_config: An instance of `AgentWorkFlowConfig`. If None, defaults to a standard configuration.+ :param connection_id: An optional connection identifier.+ :param kwargs: Additional keyword arguments.+ :return: An instance of `Message` representing a response.+ """++ # create a working director for workflow based on user_dir/session_id/time_hash+ work_dir = os.path.join(user_dir, message.session_id, datetime.now().strftime("%Y%m%d_%H-%M-%S"))+ os.makedirs(work_dir, exist_ok=True)# if no flow config is provided, use the defaultif flow_config is None:- flow_config = get_default_agent_config(scratch_dir)+ raise ValueError("flow_config must be specified")++ flow = AutoGenWorkFlowManager(+ config=flow_config,+ history=history,+ work_dir=work_dir,+ send_message_function=self.send,+ connection_id=connection_id,+ )- flow = AutoGenWorkFlowManager(config=flow_config, history=history, work_dir=scratch_dir)message_text = message.content.strip()- output = ""start_time = time.time()-- metadata = {}flow.run(message=f"{message_text}", clear_history=False)+ end_time = time.time()- metadata["messages"] = flow.agent_history+ metadata = {+ "messages": flow.agent_history,+ "summary_method": flow_config.summary_method,+ "time": end_time - start_time,+ "files": get_modified_files(start_time, end_time, source_dir=work_dir),+ }- output = ""+ print("Modified files: ", len(metadata["files"]))++ output = self._generate_output(message_text, flow, flow_config)++ output_message = Message(+ user_id=message.user_id,+ root_msg_id=message.root_msg_id,+ role="assistant",+ content=output,+ metadata=json.dumps(metadata),+ session_id=message.session_id,+ )++ return output_message+ def _generate_output(+ self, message_text: str, flow: AutoGenWorkFlowManager, flow_config: AgentWorkFlowConfig+ ) -> str:+ """+ Generates the output response based on the workflow configuration and agent history.++ :param message_text: The text of the incoming message.+ :param flow: An instance of `AutoGenWorkFlowManager`.+ :param flow_config: An instance of `AgentWorkFlowConfig`.+ :return: The output response as a string.+ """++ output = ""if flow_config.summary_method == "last":successful_code_blocks = extract_successful_code_blocks(flow.agent_history)last_message = flow.agent_history[-1]["message"]["content"] if flow.agent_history else ""successful_code_blocks = "\n\n".join(successful_code_blocks)output = (last_message + "\n" + successful_code_blocks) if successful_code_blocks else last_messageelif flow_config.summary_method == "llm":- output = ""+ model = flow.config.receiver.config.llm_config.config_list[0]+ status_message = SocketMessage(+ type="agent_status",+ data={"status": "summarizing", "message": "Generating summary of agent dialogue"},+ connection_id=flow.connection_id,+ )+ self.send(status_message.dict())+ output = summarize_chat_history(task=message_text, messages=flow.agent_history, model=model)+elif flow_config.summary_method == "none":output = ""+ return output- metadata["code"] = ""- metadata["summary_method"] = flow_config.summary_method- end_time = time.time()- metadata["time"] = end_time - start_time- modified_files = get_modified_files(start_time, end_time, scratch_dir, dest_dir=work_dir)- metadata["files"] = modified_files- print("Modified files: ", len(modified_files))+class WebSocketConnectionManager:+ """+ Manages WebSocket connections including sending, broadcasting, and managing the lifecycle of connections.+ """- output_message = Message(- user_id=message.user_id,- root_msg_id=message.root_msg_id,- role="assistant",- content=output,- metadata=json.dumps(metadata),- session_id=message.session_id,- )+ def __init__(+ self, active_connections: List[Tuple[WebSocket, str]] = None, active_connections_lock: asyncio.Lock = None+ ) -> None:+ """+ Initializes WebSocketConnectionManager with an optional list of active WebSocket connections.- return output_message+ :param active_connections: A list of tuples, each containing a WebSocket object and its corresponding client_id.+ """+ if active_connections is None:+ active_connections = []+ self.active_connections_lock = active_connections_lock+ self.active_connections: List[Tuple[WebSocket, str]] = active_connections++ async def connect(self, websocket: WebSocket, client_id: str) -> None:+ """+ Accepts a new WebSocket connection and appends it to the active connections list.++ :param websocket: The WebSocket instance representing a client connection.+ :param client_id: A string representing the unique identifier of the client.+ """+ await websocket.accept()+ async with self.active_connections_lock:+ self.active_connections.append((websocket, client_id))+ print(f"New Connection: {client_id}, Total: {len(self.active_connections)}")++ async def disconnect(self, websocket: WebSocket) -> None:+ """+ Disconnects and removes a WebSocket connection from the active connections list.++ :param websocket: The WebSocket instance to remove.+ """+ async with self.active_connections_lock:+ try:+ self.active_connections = [conn for conn in self.active_connections if conn[0] != websocket]+ print(f"Connection Closed. Total: {len(self.active_connections)}")+ except ValueError:+ print("Error: WebSocket connection not found")++ async def disconnect_all(self) -> None:+ """+ Disconnects all active WebSocket connections.+ """+ for connection, _ in self.active_connections[:]:+ await self.disconnect(connection)++ async def send_message(self, message: Dict, websocket: WebSocket) -> None:+ """+ Sends a JSON message to a single WebSocket connection.++ :param message: A JSON serializable dictionary containing the message to send.+ :param websocket: The WebSocket instance through which to send the message.+ """+ try:+ async with self.active_connections_lock:+ await websocket.send_json(message)+ except WebSocketDisconnect:+ print("Error: Tried to send a message to a closed WebSocket")+ await self.disconnect(websocket)+ except websockets.exceptions.ConnectionClosedOK:+ print("Error: WebSocket connection closed normally")+ await self.disconnect(websocket)+ except Exception as e:+ print(f"Error in sending message: {str(e)}")+ await self.disconnect(websocket)++ async def broadcast(self, message: Dict) -> None:+ """+ Broadcasts a JSON message to all active WebSocket connections.++ :param message: A JSON serializable dictionary containing the message to broadcast.+ """+ # Create a message dictionary with the desired format+ message_dict = {"message": message}++ for connection, _ in self.active_connections[:]:+ try:+ if connection.client_state == websockets.protocol.State.OPEN:+ # Call send_message method with the message dictionary and current WebSocket connection+ await self.send_message(message_dict, connection)+ else:+ print("Error: WebSocket connection is closed")+ await self.disconnect(connection)+ except (WebSocketDisconnect, websockets.exceptions.ConnectionClosedOK) as e:+ print(f"Error: WebSocket disconnected or closed({str(e)})")+ await self.disconnect(connection)diff --git a/samples/apps/autogen-studio/autogenstudio/datamodel.py b/samples/apps/autogen-studio/autogenstudio/datamodel.pyindex cd8d5a40f..8bebdb63e 100644--- a/samples/apps/autogen-studio/autogenstudio/datamodel.py+++ b/samples/apps/autogen-studio/autogenstudio/datamodel.py@@ -113,6 +113,7 @@ class AgentConfig:is_termination_msg: Optional[Union[bool, str, Callable]] = Nonecode_execution_config: Optional[Union[bool, str, Dict[str, Any]]] = Nonedefault_auto_reply: Optional[str] = ""+ description: Optional[str] = Nonedef dict(self):result = asdict(self)@@ -131,7 +132,6 @@ class AgentFlowSpec:timestamp: Optional[str] = Noneuser_id: Optional[str] = Noneskills: Optional[Union[None, List[Skill]]] = None- description: Optional[str] = Nonedef __post_init__(self):if self.timestamp is None:@@ -175,7 +175,6 @@ class GroupChatFlowSpec:id: Optional[str] = Nonetimestamp: Optional[str] = Noneuser_id: Optional[str] = None- description: Optional[str] = Noneskills: Optional[Union[None, List[Skill]]] = Nonedef __post_init__(self):@@ -303,3 +302,16 @@ class DBWebRequestModel(object):agent: Optional[AgentFlowSpec] = Noneworkflow: Optional[AgentWorkFlowConfig] = Nonemodel: Optional[Model] = None+ message: Optional[Message] = None+ connection_id: Optional[str] = None+++@dataclass+class SocketMessage(object):+ connection_id: str+ data: Dict[str, Any]+ type: str++ def dict(self):+ result = asdict(self)+ return resultdiff --git a/samples/apps/autogen-studio/autogenstudio/utils/dbdefaults.json b/samples/apps/autogen-studio/autogenstudio/utils/dbdefaults.jsonindex 9359a05af..7f3632526 100644--- a/samples/apps/autogen-studio/autogenstudio/utils/dbdefaults.json+++ b/samples/apps/autogen-studio/autogenstudio/utils/dbdefaults.json@@ -22,7 +22,7 @@"agents": [{"type": "userproxy",- "description": "A user proxy agent that executes code.",+"config": {"name": "userproxy","human_input_mode": "NEVER",@@ -33,12 +33,12 @@"code_execution_config": {"work_dir": null,"use_docker": false- }+ },+ "description": "A user proxy agent that executes code."}},{"type": "assistant",- "description": "A primary assistant agent that writes plans and code to solve tasks.","skills": [{"title": "find_papers_arxiv",@@ -54,6 +54,7 @@],"config": {"name": "primary_assistant",+ "description": "A primary assistant agent that writes plans and code to solve tasks.","llm_config": {"config_list": [{@@ -138,7 +139,7 @@},"human_input_mode": "NEVER","max_consecutive_auto_reply": 8,- "system_message": "You are a helpful assistant that can suggest a travel plan for a user. You are the primary cordinator who will receive suggestions or advice from other agents (local_assistant, language_assistant). You must ensure that the finally plan integrates the suggestions from other agents or team members. YOUR FINAL RESPONSE MUST BE THE COMPLETE PLAN that ends with the word TERMINATE. "+ "system_message": "You are a helpful assistant that can suggest a travel plan for a user. You are the primary cordinator who will receive suggestions or advice from other agents (local_assistant, language_assistant). You must ensure that the finally plan integrates the suggestions from other agents or team members. YOUR FINAL RESPONSE MUST BE THE COMPLETE PLAN. When the plan is complete and all perspectives are integrated, you can respond with TERMINATE."}},{@@ -188,9 +189,9 @@"description": "This workflow is used for general purpose tasks.","sender": {"type": "userproxy",- "description": "A user proxy agent that executes code.","config": {"name": "userproxy",+ "description": "A user proxy agent that executes code.","human_input_mode": "NEVER","max_consecutive_auto_reply": 10,"system_message": "You are a helpful assistant.",@@ -204,7 +205,7 @@},"receiver": {"type": "assistant",- "description": "Default assistant to generate plans and write code to solve tasks.",+"skills": [{"title": "find_papers_arxiv",@@ -218,6 +219,7 @@}],"config": {+ "description": "Default assistant to generate plans and write code to solve tasks.","name": "primary_assistant","llm_config": {"config_list": [diff --git a/samples/apps/autogen-studio/autogenstudio/utils/dbutils.py b/samples/apps/autogen-studio/autogenstudio/utils/dbutils.pyindex 92893c01c..a7c4b7d4c 100644--- a/samples/apps/autogen-studio/autogenstudio/utils/dbutils.py+++ b/samples/apps/autogen-studio/autogenstudio/utils/dbutils.py@@ -51,6 +51,7 @@ SESSIONS_TABLE_SQL = """id TEXT NOT NULL,user_id TEXT NOT NULL,timestamp DATETIME NOT NULL,+ name TEXT,flow_config TEXT,UNIQUE (user_id, id))@@ -76,7 +77,6 @@ AGENTS_TABLE_SQL = """config TEXT,type TEXT,skills TEXT,- description TEXT,UNIQUE (id, user_id))"""@@ -136,10 +136,40 @@ class DBManager:try:self.conn = sqlite3.connect(self.path, check_same_thread=False, **kwargs)self.cursor = self.conn.cursor()+ self.migrate()except Exception as e:logger.error("Error connecting to database: %s", e)raise e+ def migrate(self):+ """+ Run migrations to update the database schema.+ """+ self.add_column_if_not_exists("sessions", "name", "TEXT")+ self.add_column_if_not_exists("models", "description", "TEXT")++ def add_column_if_not_exists(self, table: str, column: str, column_type: str):+ """+ Adds a new column to the specified table if it does not exist.++ Args:+ table (str): The table name where the column should be added.+ column (str): The column name that should be added.+ column_type (str): The data type of the new column.+ """+ try:+ self.cursor.execute(f"PRAGMA table_info({table})")+ column_names = [row[1] for row in self.cursor.fetchall()]+ if column not in column_names:+ self.cursor.execute(f"ALTER TABLE {table} ADD COLUMN {column} {column_type}")+ self.conn.commit()+ logger.info(f"Migration: New '{column}' column has been added to the '{table}' table.")+ else:+ logger.info(f"'{column}' column already exists in the '{table}' table.")++ except Exception as e:+ print(f"Error while checking and updating '{table}' table: {e}")+def reset_db(self):"""Reset the database by deleting the database file and creating a new one.@@ -149,13 +179,6 @@ class DBManager:os.remove(self.path)self.init_db(path=self.path)- def run_migrations(self):- """- Run migrations to update the database schema.- """-- pass-def init_db(self, path: str = "database.sqlite", **kwargs: Any) -> None:"""Initializes the database by creating necessary tables.@@ -228,7 +251,7 @@ class DBManager:agent = AgentFlowSpec(**agent)agent.skills = [skill.dict() for skill in agent.skills] if agent.skills else Noneself.cursor.execute(- "INSERT INTO agents (id, user_id, timestamp, config, type, skills, description) VALUES (?, ?, ?, ?, ?, ?, ?)",+ "INSERT INTO agents (id, user_id, timestamp, config, type, skills) VALUES (?, ?, ?, ?, ?, ?)",(agent.id,"default",@@ -236,7 +259,6 @@ class DBManager:json.dumps(agent.config.dict()),agent.type,json.dumps(agent.skills),- agent.description,),)@@ -387,7 +409,7 @@ def delete_model(model: Model, dbmanager: DBManager) -> List[dict]:return models-def create_message(message: Message, dbmanager: DBManager) -> None:+def create_message(message: Message, dbmanager: DBManager) -> List[dict]:"""Save a message in the database using the provided database manager.@@ -406,6 +428,8 @@ def create_message(message: Message, dbmanager: DBManager) -> None:message.session_id,)dbmanager.query(query=query, args=args)+ messages = get_messages(user_id=message.user_id, session_id=message.session_id, dbmanager=dbmanager)+ return messagesdef get_messages(user_id: str, session_id: str, dbmanager: DBManager) -> List[dict]:@@ -460,6 +484,24 @@ def create_session(user_id: str, session: Session, dbmanager: DBManager) -> Listreturn sessions+def rename_session(name: str, session: Session, dbmanager: DBManager) -> List[dict]:+ """+ Edit a session for a specific user in the database.++ :param name: The new name of the session+ :param session: The Session object containing session data+ :param dbmanager: The DBManager instance to interact with the database+ :return: A list of dictionaries, each representing a session+ """++ query = "UPDATE sessions SET name = ? WHERE id = ?"+ args = (name, session.id)+ dbmanager.query(query=query, args=args)+ sessions = get_sessions(user_id=session.user_id, dbmanager=dbmanager)++ return sessions++def delete_session(session: Session, dbmanager: DBManager) -> List[dict]:"""Delete a specific session and all messages for that session in the database.@@ -674,12 +716,11 @@ def upsert_agent(agent_flow_spec: AgentFlowSpec, dbmanager: DBManager) -> List[D"timestamp": agent_flow_spec.timestamp,"config": json.dumps(agent_flow_spec.config.dict()),"type": agent_flow_spec.type,- "description": agent_flow_spec.description,"skills": json.dumps([x.dict() for x in agent_flow_spec.skills] if agent_flow_spec.skills else []),}update_item("agents", agent_flow_spec.id, updated_data, dbmanager)else:- query = "INSERT INTO agents (id, user_id, timestamp, config, type, description, skills) VALUES (?, ?, ?, ?, ?, ?, ?)"+ query = "INSERT INTO agents (id, user_id, timestamp, config, type, skills) VALUES (?, ?, ?, ?, ?,?)"config_json = json.dumps(agent_flow_spec.config.dict())args = (agent_flow_spec.id,@@ -687,7 +728,6 @@ def upsert_agent(agent_flow_spec: AgentFlowSpec, dbmanager: DBManager) -> List[Dagent_flow_spec.timestamp,config_json,agent_flow_spec.type,- agent_flow_spec.description,json.dumps([x.dict() for x in agent_flow_spec.skills] if agent_flow_spec.skills else []),)dbmanager.query(query=query, args=args)diff --git a/samples/apps/autogen-studio/autogenstudio/utils/utils.py b/samples/apps/autogen-studio/autogenstudio/utils/utils.pyindex b604fb30d..8795037cf 100644--- a/samples/apps/autogen-studio/autogenstudio/utils/utils.py+++ b/samples/apps/autogen-studio/autogenstudio/utils/utils.py@@ -8,6 +8,8 @@ import reimport autogenfrom autogen.oai.client import OpenAIWrapperfrom ..datamodel import AgentConfig, AgentFlowSpec, AgentWorkFlowConfig, LLMConfig, Model, Skill+from dotenv import load_dotenv+from ..version import APP_NAMEdef md5_hash(text: str) -> str:@@ -145,21 +147,17 @@ def serialize_file(file_path: str) -> Tuple[str, str]:return base64_encoded_content, file_type-def get_modified_files(- start_timestamp: float, end_timestamp: float, source_dir: str, dest_dir: str-) -> List[Dict[str, str]]:+def get_modified_files(start_timestamp: float, end_timestamp: float, source_dir: str) -> List[Dict[str, str]]:"""- Copy files from source_dir that were modified within a specified timestamp range- to dest_dir, renaming files if they already exist there. The function excludes- files with certain file extensions and names.+ Identify files from source_dir that were modified within a specified timestamp range.+ The function excludes files with certain file extensions and names.- :param start_timestamp: The start timestamp to filter modified files.- :param end_timestamp: The end timestamp to filter modified files.+ :param start_timestamp: The floating-point number representing the start timestamp to filter modified files.+ :param end_timestamp: The floating-point number representing the end timestamp to filter modified files.:param source_dir: The directory to search for modified files.- :param dest_dir: The destination directory to copy modified files to.- :return: A list of dictionaries with details of file paths in dest_dir that were modified and copied over.- Dictionary format: {path: "", name: "", extension: ""}+ :return: A list of dictionaries with details of relative file paths that were modified.+ Dictionary format: {path: "", name: "", extension: "", type: ""}Files with extensions "__pycache__", "*.pyc", "__init__.py", and "*.cache"are ignored."""@@ -167,63 +165,63 @@ def get_modified_files(ignore_extensions = {".pyc", ".cache"}ignore_files = {"__pycache__", "__init__.py"}+ # Walk through the directory treefor root, dirs, files in os.walk(source_dir):- # Excluding the directory "__pycache__" if present+ # Update directories and files to exclude those to be ignoreddirs[:] = [d for d in dirs if d not in ignore_files]+ files[:] = [f for f in files if f not in ignore_files and os.path.splitext(f)[1] not in ignore_extensions]for file in files:file_path = os.path.join(root, file)- file_ext = os.path.splitext(file)[1]- file_name = os.path.basename(file)-- if file_ext in ignore_extensions or file_name in ignore_files:- continue-file_mtime = os.path.getmtime(file_path)- if start_timestamp < file_mtime < end_timestamp:- dest_file_path = os.path.join(dest_dir, file)- copy_idx = 1- while os.path.exists(dest_file_path):- base, extension = os.path.splitext(file)- # Handling potential name conflicts by appending a number- dest_file_path = os.path.join(dest_dir, f"{base}_{copy_idx}{extension}")- copy_idx += 1-- # Copying the modified file to the destination directory- shutil.copy2(file_path, dest_file_path)- # Extract user id from the dest_dir and file path+ # Verify if the file was modified within the given timestamp range+ if start_timestamp <= file_mtime <= end_timestamp:+ file_relative_path = (+ "files/user" + file_path.split("files/user", 1)[1] if "files/user" in file_path else ""+ )+ file_type = get_file_type(file_path)- dest_dir_as_path = Path(dest_dir)- uid = dest_dir_as_path.name-- relative_file_path = os.path.relpath(dest_file_path, start=dest_dir)- file_type = get_file_type(dest_file_path)file_dict = {- "path": f"files/user/{uid}/{relative_file_path}",- "name": file_name,- "extension": file_ext.replace(".", ""),+ "path": file_relative_path,+ "name": os.path.basename(file),+ # Remove the dot+ "extension": os.path.splitext(file)[1].lstrip("."),"type": file_type,}modified_files.append(file_dict)- # sort by extension++ # Sort the modified files by extensionmodified_files.sort(key=lambda x: x["extension"])return modified_files-def init_webserver_folders(root_file_path: str) -> Dict[str, str]:+def init_app_folders(app_file_path: str) -> Dict[str, str]:"""Initialize folders needed for a web server, such as static file directories- and user-specific data directories.+ and user-specific data directories. Also load any .env file if it exists.:param root_file_path: The root directory where webserver folders will be created:return: A dictionary with the path of each created folder"""- if not os.path.exists(root_file_path):- os.makedirs(root_file_path, exist_ok=True)- files_static_root = os.path.join(root_file_path, "files/")- static_folder_root = os.path.join(root_file_path, "ui")+ app_name = f".{APP_NAME}"+ default_app_root = os.path.join(os.path.expanduser("~"), app_name)+ if not os.path.exists(default_app_root):+ os.makedirs(default_app_root, exist_ok=True)+ app_root = os.environ.get("AUTOGENSTUDIO_APPDIR") or default_app_root++ if not os.path.exists(app_root):+ os.makedirs(app_root, exist_ok=True)++ # load .env file if it exists+ env_file = os.path.join(app_root, ".env")+ if os.path.exists(env_file):+ print(f"Loading environment variables from {env_file}")+ load_dotenv(env_file)++ files_static_root = os.path.join(app_root, "files/")+ static_folder_root = os.path.join(app_file_path, "ui")os.makedirs(files_static_root, exist_ok=True)os.makedirs(os.path.join(files_static_root, "user"), exist_ok=True)@@ -231,7 +229,9 @@ def init_webserver_folders(root_file_path: str) -> Dict[str, str]:folders = {"files_static_root": files_static_root,"static_folder_root": static_folder_root,+ "app_root": app_root,}+ print(f"Initialized application data folder: {app_root}")return folders@@ -268,9 +268,6 @@ install via pip and use --quiet option.os.makedirs(work_dir)# overwrite skills.py in work_dir- with open(os.path.join(work_dir, "skills.py"), "w", encoding="utf-8") as f:- f.write(prompt)- # overwrite skills.py in work_dirwith open(os.path.join(work_dir, "skills.py"), "w", encoding="utf-8") as f:f.write(prompt)@@ -408,3 +405,36 @@ def test_model(model: Model):client = OpenAIWrapper(config_list=[sanitized_model])response = client.create(messages=[{"role": "user", "content": "2+2="}], cache_seed=None)return response.choices[0].message.content+++# summarize_chat_history (messages, model) .. returns a summary of the chat history+++def summarize_chat_history(task: str, messages: List[Dict[str, str]], model: Model):+ """+ Summarize the chat history using the model endpoint and returning the response.+ """++ sanitized_model = sanitize_model(model)+ client = OpenAIWrapper(config_list=[sanitized_model])+ summarization_system_prompt = f"""+ You are a helpful assistant that is able to review the chat history between a set of agents (userproxy agents, assistants etc) as they try to address a given TASK and provide a summary. Be SUCCINCT but also comprehensive enough to allow others (who cannot see the chat history) understand and recreate the solution.++ The task requested by the user is:+ ===+ {task}+ ===+ The summary should focus on extracting the actual solution to the task from the chat history (assuming the task was addressed) such that any other agent reading the summary will understand what the actual solution is. Use a neutral tone and DO NOT directly mention the agents. Instead only focus on the actions that were carried out (e.g. do not say 'assistant agent generated some code visualization code ..' instead say say 'visualization code was generated ..' ).+ """+ summarization_prompt = [+ {+ "role": "system",+ "content": summarization_system_prompt,+ },+ {+ "role": "user",+ "content": f"Summarize the following chat history. {str(messages)}",+ },+ ]+ response = client.create(messages=summarization_prompt, cache_seed=None)+ return response.choices[0].message.contentdiff --git a/samples/apps/autogen-studio/autogenstudio/version.py b/samples/apps/autogen-studio/autogenstudio/version.pyindex 0b52beb9e..18b7f42aa 100644--- a/samples/apps/autogen-studio/autogenstudio/version.py+++ b/samples/apps/autogen-studio/autogenstudio/version.py@@ -1,3 +1,3 @@-VERSION = "0.0.43a"+VERSION = "0.0.54"__version__ = VERSIONAPP_NAME = "autogenstudio"diff --git a/samples/apps/autogen-studio/autogenstudio/web/app.py b/samples/apps/autogen-studio/autogenstudio/web/app.pyindex c069623af..48c29ac38 100644--- a/samples/apps/autogen-studio/autogenstudio/web/app.py+++ b/samples/apps/autogen-studio/autogenstudio/web/app.py@@ -1,26 +1,64 @@+import asyncio+from contextlib import asynccontextmanagerimport jsonimport os+import queue+import threadingimport traceback-from fastapi import FastAPI+from fastapi import FastAPI, WebSocket, WebSocketDisconnectfrom fastapi.middleware.cors import CORSMiddlewarefrom fastapi.staticfiles import StaticFilesfrom fastapi import HTTPExceptionfrom openai import OpenAIError-from ..version import VERSION+from ..version import VERSION, APP_NAMEfrom ..datamodel import (- ChatWebRequestModel,DBWebRequestModel,DeleteMessageWebRequestModel,Message,Session,)-from ..utils import md5_hash, init_webserver_folders, DBManager, dbutils, test_model+from ..utils import md5_hash, init_app_folders, DBManager, dbutils, test_model+from ..chatmanager import AutoGenChatManager, WebSocketConnectionManager-from ..chatmanager import AutoGenChatManager+managers = {"chat": None} # manage calls to autogen+# Create thread-safe queue for messages between api thread and autogen threads+message_queue = queue.Queue()+active_connections = []+active_connections_lock = asyncio.Lock()+websocket_manager = WebSocketConnectionManager(+ active_connections=active_connections, active_connections_lock=active_connections_lock+)+++def message_handler():+ while True:+ message = message_queue.get()+ print("Active Connections: ", [client_id for _, client_id in websocket_manager.active_connections])+ print("Current message connection id: ", message["connection_id"])+ for connection, socket_client_id in websocket_manager.active_connections:+ if message["connection_id"] == socket_client_id:+ asyncio.run(websocket_manager.send_message(message, connection))+ message_queue.task_done()+++message_handler_thread = threading.Thread(target=message_handler, daemon=True)+message_handler_thread.start()+++@asynccontextmanager+async def lifespan(app: FastAPI):+ print("***** App started *****")+ managers["chat"] = AutoGenChatManager(message_queue=message_queue)++ yield+ # Close all active connections+ await websocket_manager.disconnect_all()+ print("***** App stopped *****")-app = FastAPI()++app = FastAPI(lifespan=lifespan)# allow cross origin requests for testing on localhost:800* ports only@@ -38,9 +76,9 @@ app.add_middleware()-root_file_path = os.environ.get("AUTOGENSTUDIO_APPDIR") or os.path.dirname(os.path.abspath(__file__))+app_file_path = os.path.dirname(os.path.abspath(__file__))# init folders skills, workdir, static, files etc-folders = init_webserver_folders(root_file_path)+folders = init_app_folders(app_file_path)ui_folder_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ui")api = FastAPI(root_path="/api")@@ -51,13 +89,13 @@ app.mount("/", StaticFiles(directory=ui_folder_path, html=True), name="ui")api.mount("/files", StaticFiles(directory=folders["files_static_root"], html=True), name="files")-db_path = os.path.join(root_file_path, "database.sqlite")+db_path = os.path.join(folders["app_root"], "database.sqlite")dbmanager = DBManager(path=db_path) # manage database operations-chatmanager = AutoGenChatManager() # manage calls to autogen+# manage websocket connections@api.post("/messages")-async def add_message(req: ChatWebRequestModel):+async def add_message(req: DBWebRequestModel):message = Message(**req.message.dict())user_history = dbutils.get_messages(user_id=message.user_id, session_id=req.message.session_id, dbmanager=dbmanager)@@ -67,19 +105,21 @@ async def add_message(req: ChatWebRequestModel):os.makedirs(user_dir, exist_ok=True)try:- response_message: Message = chatmanager.chat(+ response_message: Message = managers["chat"].chat(message=message,history=user_history,- work_dir=user_dir,- flow_config=req.flow_config,+ user_dir=user_dir,+ flow_config=req.workflow,+ connection_id=req.connection_id,)- # save assistant response to db- dbutils.create_message(message=response_message, dbmanager=dbmanager)+ # save agent's response to db+ messages = dbutils.create_message(message=response_message, dbmanager=dbmanager)response = {"status": True,- "message": response_message.content,- "metadata": json.loads(response_message.metadata),+ "message": "Message processed successfully",+ "data": messages,+ # "metadata": json.loads(response_message.metadata),}return responseexcept Exception as ex_error:@@ -157,6 +197,7 @@ async def create_user_session(req: DBWebRequestModel):try:session = Session(user_id=req.session.user_id, flow_config=req.session.flow_config)user_sessions = dbutils.create_session(user_id=req.user_id, session=session, dbmanager=dbmanager)+return {"status": True,"message": "Session created successfully",@@ -170,6 +211,26 @@ async def create_user_session(req: DBWebRequestModel):}[email protected]("/sessions/rename")+async def rename_user_session(name: str, req: DBWebRequestModel):+ """Rename a session for a user"""+ print("Rename: " + name)+ print("renaming session for user: " + req.user_id + " to: " + name)+ try:+ session = dbutils.rename_session(name=name, session=req.session, dbmanager=dbmanager)+ return {+ "status": True,+ "message": "Session renamed successfully",+ "data": session,+ }+ except Exception as ex_error:+ print(traceback.format_exc())+ return {+ "status": False,+ "message": "Error occurred while renaming session: " + str(ex_error),+ }++@api.post("/sessions/publish")async def publish_user_session_to_gallery(req: DBWebRequestModel):"""Create a new session for a user"""@@ -496,3 +557,28 @@ async def get_version():"message": "Version retrieved successfully","data": {"version": VERSION},}+++async def process_socket_message(data: dict, websocket: WebSocket, client_id: str):+ print(f"Client says: {data['type']}")+ if data["type"] == "user_message":+ user_request_body = DBWebRequestModel(**data["data"])+ response = await add_message(user_request_body)+ response_socket_message = {+ "type": "agent_response",+ "data": response,+ "connection_id": client_id,+ }+ await websocket_manager.send_message(response_socket_message, websocket)++[email protected]("/ws/{client_id}")+async def websocket_endpoint(websocket: WebSocket, client_id: str):+ await websocket_manager.connect(websocket, client_id)+ try:+ while True:+ data = await websocket.receive_json()+ await process_socket_message(data, websocket, client_id)+ except WebSocketDisconnect:+ print(f"Client #{client_id} is disconnected")+ await websocket_manager.disconnect(websocket)diff --git a/samples/apps/autogen-studio/autogenstudio/workflowmanager.py b/samples/apps/autogen-studio/autogenstudio/workflowmanager.pyindex 37a539f13..628c7f9f7 100644--- a/samples/apps/autogen-studio/autogenstudio/workflowmanager.py+++ b/samples/apps/autogen-studio/autogenstudio/workflowmanager.py@@ -1,7 +1,10 @@import os-from typing import List, Optional+from typing import List, Optional, Union, Dict++from requests import Session+import autogen-from .datamodel import AgentConfig, AgentFlowSpec, AgentWorkFlowConfig, Message+from .datamodel import AgentConfig, AgentFlowSpec, AgentWorkFlowConfig, Message, SocketMessagefrom .utils import get_skills_from_prompt, clear_folder, sanitize_modelfrom datetime import datetime@@ -17,6 +20,8 @@ class AutoGenWorkFlowManager:history: Optional[List[Message]] = None,work_dir: str = None,clear_work_dir: bool = True,+ send_message_function: Optional[callable] = None,+ connection_id: Optional[str] = None,) -> None:"""Initializes the AutoGenFlow with agents specified in the config and optional@@ -27,43 +32,59 @@ class AutoGenWorkFlowManager:history: An optional list of previous messages to populate the agents' history."""+ self.send_message_function = send_message_function+ self.connection_id = connection_idself.work_dir = work_dir or "work_dir"if clear_work_dir:clear_folder(self.work_dir)-+ self.config = config# given the config, return an AutoGen agent objectself.sender = self.load(config.sender)# given the config, return an AutoGen agent objectself.receiver = self.load(config.receiver)-- if config.receiver.type == "groupchat":- # append self.sender to the list of agents- self.receiver._groupchat.agents.append(self.sender)- print(self.receiver)self.agent_history = []if history:self.populate_history(history)- def process_reply(self, recipient, messages, sender, config):- if "callback" in config and config["callback"] is not None:- callback = config["callback"]- callback(sender, recipient, messages[-1])- last_message = messages[-1]-- sender = sender.name- recipient = recipient.name- if "name" in last_message:- sender = last_message["name"]-- iteration = {- "recipient": recipient,- "sender": sender,- "message": last_message,+ def process_message(+ self,+ sender: autogen.Agent,+ receiver: autogen.Agent,+ message: Dict,+ request_reply: bool = False,+ silent: bool = False,+ sender_type: str = "agent",+ ) -> None:+ """+ Processes the message and adds it to the agent history.++ Args:++ sender: The sender of the message.+ receiver: The receiver of the message.+ message: The message content.+ request_reply: If set to True, the message will be added to agent history.+ silent: determining verbosity.+ sender_type: The type of the sender of the message.+ """++ message = message if isinstance(message, dict) else {"content": message, "role": "user"}+ message_payload = {+ "recipient": receiver.name,+ "sender": sender.name,+ "message": message,"timestamp": datetime.now().isoformat(),+ "sender_type": sender_type,+ "connection_id": self.connection_id,+ "message_type": "agent_message",}- self.agent_history.append(iteration)- return False, None+ # if the agent will respond to the message, or the message is sent by a groupchat agent. This avoids adding groupchat broadcast messages to the history (which are sent with request_reply=False), or when agent populated from history+ if request_reply is not False or sender_type == "groupchat":+ self.agent_history.append(message_payload) # add to history+ if self.send_message_function: # send over the message queue+ socket_msg = SocketMessage(type="agent_message", data=message_payload, connection_id=self.connection_id)+ self.send_message_function(socket_msg.dict())def _sanitize_history_message(self, message: str) -> str:"""@@ -95,12 +116,14 @@ class AutoGenWorkFlowManager:msg.content,self.receiver,request_reply=False,+ silent=True,)elif msg.role == "assistant":self.receiver.send(msg.content,self.sender,request_reply=False,+ silent=True,)def sanitize_agent_spec(self, agent_spec: AgentFlowSpec) -> AgentFlowSpec:@@ -144,14 +167,17 @@ class AutoGenWorkFlowManager:# tbd check if docker is installedcode_execution_config["use_docker"] = Falseagent_spec.config.code_execution_config = code_execution_config- if agent_spec.skills:- # get skill prompt, also write skills to a file named skills.py- skills_prompt = ""- skills_prompt = get_skills_from_prompt(agent_spec.skills, self.work_dir)- if agent_spec.config.system_message:- agent_spec.config.system_message = agent_spec.config.system_message + "\n\n" + skills_prompt- else:- agent_spec.config.system_message = get_default_system_message(agent_spec.type) + "\n\n" + skills_prompt++ if agent_spec.skills:+ # get skill prompt, also write skills to a file named skills.py+ skills_prompt = ""+ skills_prompt = get_skills_from_prompt(agent_spec.skills, self.work_dir)+ if agent_spec.config.system_message:+ agent_spec.config.system_message = agent_spec.config.system_message + "\n\n" + skills_prompt+ else:+ agent_spec.config.system_message = (+ get_default_system_message(agent_spec.type) + "\n\n" + skills_prompt+ )return agent_spec@@ -173,8 +199,9 @@ class AutoGenWorkFlowManager:group_chat_config = agent_spec.groupchat_config.dict()group_chat_config["agents"] = agentsgroupchat = autogen.GroupChat(**group_chat_config)- agent = autogen.GroupChatManager(groupchat=groupchat, **agent_spec.config.dict())- agent.register_reply([autogen.Agent, None], reply_func=self.process_reply, config={"callback": None})+ agent = ExtendedGroupChatManager(+ groupchat=groupchat, **agent_spec.config.dict(), message_processor=self.process_message+ )return agentelse:@@ -193,12 +220,12 @@ class AutoGenWorkFlowManager:An instance of the loaded agent."""if agent_type == "assistant":- agent = autogen.AssistantAgent(**agent_config.dict())+ agent = ExtendedConversableAgent(**agent_config.dict(), message_processor=self.process_message)elif agent_type == "userproxy":- agent = autogen.UserProxyAgent(**agent_config.dict())+ agent = ExtendedConversableAgent(**agent_config.dict(), message_processor=self.process_message)else:raise ValueError(f"Unknown agent type: {agent_type}")- agent.register_reply([autogen.Agent, None], reply_func=self.process_reply, config={"callback": None})+return agentdef run(self, message: str, clear_history: bool = False) -> None:@@ -215,4 +242,37 @@ class AutoGenWorkFlowManager:message=message,clear_history=clear_history,)- # pass+++class ExtendedConversableAgent(autogen.ConversableAgent):+ def __init__(self, message_processor=None, *args, **kwargs):+ super().__init__(*args, **kwargs)+ self.message_processor = message_processor++ def receive(+ self,+ message: Union[Dict, str],+ sender: autogen.Agent,+ request_reply: Optional[bool] = None,+ silent: Optional[bool] = False,+ ):+ if self.message_processor:+ self.message_processor(sender, self, message, request_reply, silent, sender_type="agent")+ super().receive(message, sender, request_reply, silent)+++class ExtendedGroupChatManager(autogen.GroupChatManager):+ def __init__(self, message_processor=None, *args, **kwargs):+ super().__init__(*args, **kwargs)+ self.message_processor = message_processor++ def receive(+ self,+ message: Union[Dict, str],+ sender: autogen.Agent,+ request_reply: Optional[bool] = None,+ silent: Optional[bool] = False,+ ):+ if self.message_processor:+ self.message_processor(sender, self, message, request_reply, silent, sender_type="groupchat")+ super().receive(message, sender, request_reply, silent)diff --git a/samples/apps/autogen-studio/frontend/package.json b/samples/apps/autogen-studio/frontend/package.jsonindex 80975bab0..da33db850 100644--- a/samples/apps/autogen-studio/frontend/package.json+++ b/samples/apps/autogen-studio/frontend/package.json@@ -11,7 +11,7 @@"develop": "gatsby clean && gatsby develop","dev": "npm run develop","start": "gatsby clean && gatsby develop",- "build": "gatsby clean && rm -rf ../autogenstudio/web/ui && PREFIX_PATH_VALUE='' gatsby build --prefix-paths && cp -r public/ ../autogenstudio/web/ui",+ "build": "gatsby clean && rm -rf ../autogenstudio/web/ui && PREFIX_PATH_VALUE='' gatsby build --prefix-paths && rsync -a --delete public/ ../autogenstudio/web/ui/","serve": "gatsby serve","clean": "gatsby clean","typecheck": "tsc --noEmit"@@ -54,6 +54,7 @@"remark-gfm": "^3.0.1","sass": "^1.51.0","tailwindcss": "^3.0.24",+ "uuid": "^9.0.1","zustand": "^4.4.6"},"devDependencies": {@@ -63,6 +64,7 @@"@types/react-dom": "^18.2.15","@types/react-inner-image-zoom": "^3.0.0","@types/react-resizable": "^3.0.2",+ "@types/uuid": "^9.0.8","gh-pages": "^4.0.0","typescript": "^4.6.4"}diff --git a/samples/apps/autogen-studio/frontend/src/components/atoms.tsx b/samples/apps/autogen-studio/frontend/src/components/atoms.tsxindex 59d5c3e4b..8bc70f89a 100644--- a/samples/apps/autogen-studio/frontend/src/components/atoms.tsx+++ b/samples/apps/autogen-studio/frontend/src/components/atoms.tsx@@ -33,7 +33,13 @@ import remarkGfm from "remark-gfm";import ReactMarkdown from "react-markdown";import { atomDark } from "react-syntax-highlighter/dist/esm/styles/prism";import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";-import { fetchJSON, getServerUrl, obscureString, truncateText } from "./utils";+import {+ checkAndSanitizeInput,+ fetchJSON,+ getServerUrl,+ obscureString,+ truncateText,+} from "./utils";import {IAgentFlowSpec,IFlowConfig,@@ -242,7 +248,7 @@ export const LoadBox = ({export const LoadingBar = ({ children }: IProps) => {return (<>- <div className="rounded bg-secondary mt-4 p-3">+ <div className="rounded bg-secondary p-3"><span className="inline-block h-6 w-6 relative mr-2"><Cog8ToothIcon className="animate-ping text-accent absolute inline-flex h-full w-full rounded-ful opacity-75" /><Cog8ToothIcon className="relative text-accent animate-spin inline-flex rounded-full h-6 w-6" />@@ -901,7 +907,7 @@ export const BounceLoader = ({title?: string;}) => {return (- <div>+ <div className="inline-block"><div className="inline-flex gap-2"><span className=" rounded-full bg-accent h-2 w-2 inline-block"></span><span className="animate-bounce rounded-full bg-accent h-3 w-3 inline-block"></span>@@ -951,6 +957,7 @@ export const CsvLoader = ({const [data, setData] = useState<DataRow[]>([]);const [columns, setColumns] = useState<any[]>([]);const [isLoading, setIsLoading] = useState<boolean>(true);+ const [pageSize, setPageSize] = useState<number>(50);useEffect(() => {const fetchData = async () => {@@ -1000,8 +1007,11 @@ export const CsvLoader = ({dataSource={data}columns={columns}loading={isLoading}- pagination={{ pageSize: 50 }}+ pagination={{ pageSize: pageSize }}scroll={{ y: 450, x: scrollX }}+ onChange={(pagination) => {+ setPageSize(pagination.pageSize || 50);+ }}/></div>);@@ -1103,52 +1113,57 @@ export const AgentFlowSpecView = ({setFlowSpec(updatedFlowSpec);};- const llm_config: ILLMConfig = localFlowSpec.config.llm_config || {+ const llm_config: ILLMConfig = localFlowSpec?.config?.llm_config || {config_list: [],temperature: 0.1,};+ const nameValidation = checkAndSanitizeInput(flowSpec?.config?.name);+return (<><div className="text-accent ">{title}</div><GroupView- title=<div className="px-2">{flowSpec.config.name}</div>+ title=<div className="px-2">{flowSpec?.config?.name}</div>className="mb-4 bg-primary "><ControlRowViewtitle="Agent Name"className="mt-4"description="Name of the agent"- value={flowSpec.config.name}+ value={flowSpec?.config?.name}control={- <Input- className="mt-2"- placeholder="Agent Name"- value={flowSpec.config.name}- onChange={(e) => {- onControlChange(e.target.value, "name");- }}- />+ <>+ <Input+ className="mt-2"+ placeholder="Agent Name"+ value={flowSpec?.config?.name}+ onChange={(e) => {+ onControlChange(e.target.value, "name");+ }}+ />+ {!nameValidation.status && (+ <div className="text-xs text-red-500 mt-2">+ {nameValidation.message}+ </div>+ )}+ </>}/><ControlRowViewtitle="Agent Description"className="mt-4"- description="Description of the agent"- value={flowSpec.description || ""}+ description="Description of the agent, used by other agents+ (e.g. the GroupChatManager) to decide when to call upon this agent. (Default: system_message)"+ value={flowSpec.config.description || ""}control={<InputclassName="mt-2"placeholder="Agent Description"- value={flowSpec.description}+ value={flowSpec.config.description || ""}onChange={(e) => {- const updatedFlowSpec = {- ...localFlowSpec,- description: e.target.value,- };- setLocalFlowSpec(updatedFlowSpec);- setFlowSpec(updatedFlowSpec);+ onControlChange(e.target.value, "description");}}/>}@@ -1158,11 +1173,11 @@ export const AgentFlowSpecView = ({title="Max Consecutive Auto Reply"className="mt-4"description="Max consecutive auto reply messages before termination."- value={flowSpec.config.max_consecutive_auto_reply}+ value={flowSpec.config?.max_consecutive_auto_reply}control={<Slidermin={1}- max={30}+ max={flowSpec.type === "groupchat" ? 600 : 30}defaultValue={flowSpec.config.max_consecutive_auto_reply}step={1}onChange={(value: any) => {@@ -1223,7 +1238,6 @@ export const AgentFlowSpecView = ({value={flowSpec.config.system_message}rows={3}onChange={(e) => {- // onDebouncedControlChange(e.target.value, "system_message");onControlChange(e.target.value, "system_message");}}/>@@ -1864,7 +1878,7 @@ export const AgentSelector = ({{flowSpec.config.name}<div className="mt-2 text-secondary text-sm">{" "}- {flowSpec.description || flowSpec.config.name}+ {flowSpec.config.description || flowSpec.config.name}</div><div className="mt-2 text-secondary text-sm">{" "}@@ -2048,3 +2062,55 @@ export const MonacoEditor = ({</div>);};++export const CardHoverBar = ({+ items,+}: {+ items: {+ title: string;+ icon: any;+ hoverText: string;+ onClick: (e: any) => void;+ }[];+}) => {+ const itemRows = items.map((item, i) => {+ return (+ <div+ key={"cardhoverrow" + i}+ role="button"+ className="text-accent text-xs inline-block hover:bg-primary p-2 rounded"+ onClick={item.onClick}+ >+ <Tooltip title={item.hoverText}>+ <item.icon className=" w-5, h-5 cursor-pointer inline-block" />+ </Tooltip>+ </div>+ );+ });+ return (+ <div+ onMouseEnter={(e) => {+ e.stopPropagation();+ }}+ className=" mt-2 text-right opacity-0 group-hover:opacity-100 "+ >+ {itemRows}+ </div>+ );+};++export const AgentRow = ({ message }: { message: any }) => {+ return (+ <GroupView+ title={+ <div className="rounded p-1 px-2 inline-block text-xs bg-secondary">+ <span className="font-semibold">{message.sender}</span> ( to{" "}+ {message.recipient} )+ </div>+ }+ className="m"+ >+ <MarkdownView data={message.message?.content} className="text-sm" />+ </GroupView>+ );+};diff --git a/samples/apps/autogen-studio/frontend/src/components/layout.tsx b/samples/apps/autogen-studio/frontend/src/components/layout.tsxindex 13e83f131..914247053 100644--- a/samples/apps/autogen-studio/frontend/src/components/layout.tsx+++ b/samples/apps/autogen-studio/frontend/src/components/layout.tsx@@ -24,7 +24,10 @@ const Layout = ({restricted = false,}: Props) => {const layoutContent = (- <div className={` h-full flex flex-col`}>+ <div+ // style={{ height: "calc(100vh - 64px)" }}+ className={` h-full flex flex-col`}+ >{showHeader && <Header meta={meta} link={link} />}<div className="flex-1 text-primary "><title>{meta?.title + " | " + title}</title>diff --git a/samples/apps/autogen-studio/frontend/src/components/types.ts b/samples/apps/autogen-studio/frontend/src/components/types.tsindex c01f6ac79..522682a48 100644--- a/samples/apps/autogen-studio/frontend/src/components/types.ts+++ b/samples/apps/autogen-studio/frontend/src/components/types.ts@@ -41,6 +41,7 @@ export interface IAgentConfig {is_termination_msg?: boolean | string;default_auto_reply?: string | null;code_execution_config?: boolean | string | { [key: string]: any } | null;+ description?: string;}export interface IAgentFlowSpec {@@ -49,7 +50,6 @@ export interface IAgentFlowSpec {timestamp?: string;id?: string;skills?: Array<ISkill>;- description?: string;user_id?: string;}@@ -93,6 +93,7 @@ export interface IModelConfig {user_id?: string;timestamp?: string;description?: string;+ id?: string;}export interface IMetadataFile {@@ -108,6 +109,7 @@ export interface IChatSession {user_id: string;timestamp: string;flow_config: IFlowConfig;+ name: string;}export interface IGalleryItem {diff --git a/samples/apps/autogen-studio/frontend/src/components/utils.ts b/samples/apps/autogen-studio/frontend/src/components/utils.tsindex 83096eda8..73b9f4220 100644--- a/samples/apps/autogen-studio/frontend/src/components/utils.ts+++ b/samples/apps/autogen-studio/frontend/src/components/utils.ts@@ -243,6 +243,33 @@ export const formatDuration = (seconds: number) => {return parts.length > 0 ? parts.join(" ") : "0 sec";};+export const sampleAgentConfig = (user_id: string = "[email protected]") => {+ const sampleAgent: IAgentFlowSpec = {+ type: "assistant",+ user_id: user_id,+ config: {+ name: "sample_assistant",+ description: "Sample assistant",+ llm_config: {+ config_list: [+ {+ model: "gpt-4-1106-preview",+ },+ ],+ temperature: 0.1,+ timeout: 600,+ cache_seed: null,+ },+ human_input_mode: "NEVER",+ code_execution_config: false,+ max_consecutive_auto_reply: 8,+ system_message:+ "You are a helpful AI assistant. Solve tasks using your coding and language skills. In the following cases, suggest python code (in a python coding block) or shell script (in a sh coding block) for the user to execute. 1. When you need to collect info, use the code to output the info you need, for example, browse or search the web, download/read a file, print the content of a webpage or a file, get the current date/time, check the operating system. After sufficient info is printed and the task is ready to be solved based on your language skill, you can solve the task by yourself. 2. When you need to perform some task with code, use the code to perform the task and output the result. Finish the task smartly. Solve the task step by step if you need to. If a plan is not provided, explain your plan first. Be clear which step uses code, and which step uses your language skill. When using code, you must indicate the script type in the code block. The user cannot provide any other feedback or perform any other action beyond executing the code you suggest. The user can't modify your code. So do not suggest incomplete code which requires users to modify. Don't use a code block if it's not intended to be executed by the user. If you want the user to save the code in a file before executing it, put # filename: <filename> inside the code block as the first line. Don't include multiple code blocks in one response. Do not ask users to copy and paste the result. Instead, use 'print' function for the output when relevant. Check the execution result returned by the user. If the result indicates there is an error, fix the error and output the code again. Suggest the full code instead of partial code or code changes. If the error can't be fixed or if the task is not solved even after the code is executed successfully, analyze the problem, revisit your assumption, collect additional info you need, and think of a different approach to try. When you find an answer, verify the answer carefully. Include verifiable evidence in your response if possible. Reply 'TERMINATE' in the end when everything is done.",+ },+ };+ return sampleAgent;+};+export const sampleWorkflowConfig = (type = "twoagents") => {const llm_model_config: IModelConfig[] = [{@@ -279,6 +306,7 @@ export const sampleWorkflowConfig = (type = "twoagents") => {llm_config: llm_config,human_input_mode: "NEVER",max_consecutive_auto_reply: 8,+ code_execution_config: false,system_message:"You are a helpful AI assistant. Solve tasks using your coding and language skills. In the following cases, suggest python code (in a python coding block) or shell script (in a sh coding block) for the user to execute. 1. When you need to collect info, use the code to output the info you need, for example, browse or search the web, download/read a file, print the content of a webpage or a file, get the current date/time, check the operating system. After sufficient info is printed and the task is ready to be solved based on your language skill, you can solve the task by yourself. 2. When you need to perform some task with code, use the code to perform the task and output the result. Finish the task smartly. Solve the task step by step if you need to. If a plan is not provided, explain your plan first. Be clear which step uses code, and which step uses your language skill. When using code, you must indicate the script type in the code block. The user cannot provide any other feedback or perform any other action beyond executing the code you suggest. The user can't modify your code. So do not suggest incomplete code which requires users to modify. Don't use a code block if it's not intended to be executed by the user. If you want the user to save the code in a file before executing it, put # filename: <filename> inside the code block as the first line. Don't include multiple code blocks in one response. Do not ask users to copy and paste the result. Instead, use 'print' function for the output when relevant. Check the execution result returned by the user. If the result indicates there is an error, fix the error and output the code again. Suggest the full code instead of partial code or code changes. If the error can't be fixed or if the task is not solved even after the code is executed successfully, analyze the problem, revisit your assumption, collect additional info you need, and think of a different approach to try. When you find an answer, verify the answer carefully. Include verifiable evidence in your response if possible. Reply 'TERMINATE' in the end when everything is done.",};@@ -404,6 +432,10 @@ export const getSampleSkill = () => {};export const timeAgo = (dateString: string): string => {+ // if dateStr is empty, return empty string+ if (!dateString) {+ return "";+ }// Parse the date string into a Date objectconst timestamp = new Date(dateString);@@ -466,6 +498,11 @@ export const examplePrompts = [prompt:"paint a picture of a glass of ethiopian coffee, freshly brewed in a tall glass cup, on a table right in front of a lush green forest scenery",},+ {+ title: "Travel",+ prompt:+ "Plan a 2 day trip to hawaii. Limit to 3 activities per day, be as brief as possible!",+ },];export const fetchVersion = () => {@@ -490,19 +527,118 @@ export const fetchVersion = () => {*/export const sanitizeConfig = (data: any,- keys: string[] = ["api_key"],- replacement: string = "********"+ keys: string[] = ["api_key", "id"]): any => {if (Array.isArray(data)) {- return data.map((item) => sanitizeConfig(item, keys, replacement));+ return data.map((item) => sanitizeConfig(item, keys));} else if (typeof data === "object" && data !== null) {Object.keys(data).forEach((key) => {if (keys.includes(key)) {- data[key] = replacement;+ delete data[key];} else {- data[key] = sanitizeConfig(data[key], keys, replacement);+ data[key] = sanitizeConfig(data[key], keys);}});}return data;};++/**+ * Checks the input text against the regex '^[a-zA-Z0-9_-]{1,64}$' and returns an object with+ * status, message, and sanitizedText. Status is boolean indicating whether input text is valid,+ * message provides information about the outcome, and sanitizedText contains a valid version+ * of the input text or the original text if it was already valid.+ *+ * @param text - The input string to be checked and sanitized.+ * @returns An object containing a status, a message, and sanitizedText.+ */+export const checkAndSanitizeInput = (+ text: string+): { status: boolean; message: string; sanitizedText: string } => {+ // Create a regular expression pattern to match valid characters+ const regexPattern: RegExp = /^[a-zA-Z0-9_-]{1,64}$/;+ let status: boolean = true;+ let message: string;+ let sanitizedText: string;++ // Check if the input text matches the pattern+ if (regexPattern.test(text)) {+ // Text already adheres to the pattern+ message = `The text '${text}' is valid.`;+ sanitizedText = text;+ } else {+ // The text does not match; sanitize the input+ status = false;+ sanitizedText = text.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);+ message = `'${text}' is invalid. Consider using '${sanitizedText}' instead.`;+ }++ return { status, message, sanitizedText };+};++export const isValidConfig = (+ jsonObj: any,+ templateObj: any,+ diffThreshold: number = 4+): {+ status: boolean;+ message: string;+} => {+ // Check if both parameters are indeed objects and not null+ if (+ typeof jsonObj !== "object" ||+ jsonObj === null ||+ Array.isArray(jsonObj) ||+ typeof templateObj !== "object" ||+ templateObj === null ||+ Array.isArray(templateObj)+ ) {+ return {+ status: false,+ message:+ "Invalid input: One or both parameters are not objects, or are null or arrays.",+ };+ }++ const jsonKeys = new Set(Object.keys(jsonObj));+ const templateKeys = new Set(Object.keys(templateObj));++ if (jsonKeys.size !== templateKeys.size) {+ if (Math.abs(jsonKeys.size - templateKeys.size) > diffThreshold) {+ return {+ status: false,+ message:+ "Configuration does not match template: Number of keys differ.",+ };+ }+ }++ for (const key of templateKeys) {+ if (!jsonKeys.has(key)) {+ return {+ status: false,+ message: `Configuration does not match template: Missing key '${key}' in configuration.`,+ };+ }++ // If the value is an object, recursively validate+ if (+ typeof templateObj[key] === "object" &&+ templateObj[key] !== null &&+ !Array.isArray(templateObj[key])+ ) {+ const result = isValidConfig(jsonObj[key], templateObj[key]);+ if (!result.status) {+ return {+ status: false,+ message: `Configuration error in nested key '${key}': ${result.message}`,+ };+ }+ }+ }++ return {+ status: true,+ message: "Configuration is valid.",+ };+};diff --git a/samples/apps/autogen-studio/frontend/src/components/views/builder/agents.tsx b/samples/apps/autogen-studio/frontend/src/components/views/builder/agents.tsxindex ac2a08f11..be8a30f72 100644--- a/samples/apps/autogen-studio/frontend/src/components/views/builder/agents.tsx+++ b/samples/apps/autogen-studio/frontend/src/components/views/builder/agents.tsx@@ -1,19 +1,29 @@import {+ ArrowDownTrayIcon,+ ArrowUpTrayIcon,+ DocumentDuplicateIcon,InformationCircleIcon,PlusIcon,TrashIcon,} from "@heroicons/react/24/outline";-import { Modal, message } from "antd";+import { Dropdown, MenuProps, Modal, message } from "antd";import * as React from "react";import { IAgentFlowSpec, IStatus } from "../../types";import { appContext } from "../../../hooks/provider";-import { fetchJSON, getServerUrl, timeAgo, truncateText } from "../../utils";+import {+ fetchJSON,+ getServerUrl,+ sampleAgentConfig,+ sanitizeConfig,+ timeAgo,+ truncateText,+} from "../../utils";import {AgentFlowSpecView,BounceLoader,Card,+ CardHoverBar,LaunchButton,- LoadBox,LoadingOverlay,} from "../../atoms";@@ -38,27 +48,7 @@ const AgentsView = ({}: any) => {const [showAgentModal, setShowAgentModal] = React.useState(false);- const sampleAgent: IAgentFlowSpec = {- type: "assistant",- description: "Sample assistant",- user_id: user?.email,- config: {- name: "sample_assistant",- llm_config: {- config_list: [- {- model: "gpt-4-1106-preview",- },- ],- temperature: 0.1,- timeout: 600,- cache_seed: null,- },- human_input_mode: "NEVER",- max_consecutive_auto_reply: 8,- system_message: " ..",- },- };+ const sampleAgent = sampleAgentConfig(user?.email || "");const [newAgent, setNewAgent] = React.useState<IAgentFlowSpec | null>(sampleAgent);@@ -168,6 +158,53 @@ const AgentsView = ({}: any) => {}, []);const agentRows = (agents || []).map((agent: IAgentFlowSpec, i: number) => {+ const cardItems = [+ {+ title: "Download",+ icon: ArrowDownTrayIcon,+ onClick: (e: any) => {+ e.stopPropagation();+ // download workflow as workflow.name.json+ const element = document.createElement("a");+ const sanitizedAgent = sanitizeConfig(agent);+ const file = new Blob([JSON.stringify(sanitizedAgent)], {+ type: "application/json",+ });+ element.href = URL.createObjectURL(file);+ element.download = `agent_${agent.config.name}.json`;+ document.body.appendChild(element); // Required for this to work in FireFox+ element.click();+ },+ hoverText: "Download",+ },+ {+ title: "Make a Copy",+ icon: DocumentDuplicateIcon,+ onClick: (e: any) => {+ e.stopPropagation();+ let newAgent = { ...agent };+ newAgent.config.name = `${agent.config.name}_copy`;+ newAgent.user_id = user?.email;+ newAgent.timestamp = new Date().toISOString();+ if (newAgent.id) {+ delete newAgent.id;+ }++ setNewAgent(newAgent);+ setShowNewAgentModal(true);+ },+ hoverText: "Make a Copy",+ },+ {+ title: "Delete",+ icon: TrashIcon,+ onClick: (e: any) => {+ e.stopPropagation();+ deleteAgent(agent);+ },+ hoverText: "Delete",+ },+ ];return (<div key={"agentrow" + i} className=" " style={{ width: "200px" }}><div className="">@@ -183,28 +220,10 @@ const AgentsView = ({}: any) => {><div style={{ minHeight: "65px" }} className="my-2 break-words">{" "}- {truncateText(agent.description || "", 70)}+ {truncateText(agent.config.description || "", 70)}</div><div className="text-xs">{timeAgo(agent.timestamp || "")}</div>- <div- onMouseEnter={(e) => {- e.stopPropagation();- }}- className=" mt-2 text-right opacity-0 group-hover:opacity-100 "- >- {" "}- <div- role="button"- className="text-accent text-xs inline-block hover:bg-primary p-2 rounded"- onClick={(e) => {- e.stopPropagation();- deleteAgent(agent);- }}- >- <TrashIcon className=" w-5, h-5 cursor-pointer inline-block" />- <span className="text-xs hidden"> delete</span>- </div>- </div>+ <CardHoverBar items={cardItems} /></Card></div></div>@@ -234,7 +253,7 @@ const AgentsView = ({}: any) => {<>Agent Specification{" "}<span className="text-accent font-normal">- {agent?.config.name}+ {agent?.config?.name || ""}</span>{" "}</>}@@ -264,6 +283,60 @@ const AgentsView = ({}: any) => {);};+ const uploadAgent = () => {+ const input = document.createElement("input");+ input.type = "file";+ input.accept = ".json";+ input.onchange = (e: any) => {+ const file = e.target.files[0];+ const reader = new FileReader();+ reader.onload = (e: any) => {+ const contents = e.target.result;+ if (contents) {+ try {+ const agent = JSON.parse(contents);+ // TBD validate that it is a valid agent+ if (!agent.config) {+ throw new Error(+ "Invalid agent file. An agent must have a config"+ );+ }+ setNewAgent(agent);+ setShowNewAgentModal(true);+ } catch (err) {+ message.error(+ "Invalid agent file. Please upload a valid agent file."+ );+ }+ }+ };+ reader.readAsText(file);+ };+ input.click();+ };++ const agentsMenuItems: MenuProps["items"] = [+ // {+ // type: "divider",+ // },+ {+ key: "uploadagent",+ label: (+ <div>+ <ArrowUpTrayIcon className="w-5 h-5 inline-block mr-2" />+ Upload Agent+ </div>+ ),+ },+ ];++ const agentsMenuItemOnClick: MenuProps["onClick"] = ({ key }) => {+ if (key === "uploadagent") {+ uploadAgent();+ return;+ }+ };+return (<div className="text-primary "><AgentModal@@ -297,16 +370,23 @@ const AgentsView = ({}: any) => {{" "}Agents ({agentRows.length}){" "}</div>- <LaunchButton- className="text-sm p-2 px-3"- onClick={() => {- setShowNewAgentModal(true);- }}- >- {" "}- <PlusIcon className="w-5 h-5 inline-block mr-1" />- New Agent- </LaunchButton>+ <div>+ <Dropdown.Button+ type="primary"+ menu={{+ items: agentsMenuItems,+ onClick: agentsMenuItemOnClick,+ }}+ placement="bottomRight"+ trigger={["click"]}+ onClick={() => {+ setShowNewAgentModal(true);+ }}+ >+ <PlusIcon className="w-5 h-5 inline-block mr-1" />+ New Agent+ </Dropdown.Button>+ </div></div><div className="text-xs mb-2 pb-1 ">diff --git a/samples/apps/autogen-studio/frontend/src/components/views/builder/models.tsx b/samples/apps/autogen-studio/frontend/src/components/views/builder/models.tsxindex d3e2f5b59..be2c11099 100644--- a/samples/apps/autogen-studio/frontend/src/components/views/builder/models.tsx+++ b/samples/apps/autogen-studio/frontend/src/components/views/builder/models.tsx@@ -1,15 +1,24 @@import {+ ArrowDownTrayIcon,+ ArrowUpTrayIcon,+ DocumentDuplicateIcon,ExclamationTriangleIcon,InformationCircleIcon,PlusIcon,TrashIcon,} from "@heroicons/react/24/outline";-import { Button, Input, Modal, message } from "antd";+import { Button, Dropdown, Input, MenuProps, Modal, message } from "antd";import * as React from "react";import { IModelConfig, IStatus } from "../../types";import { appContext } from "../../../hooks/provider";-import { fetchJSON, getServerUrl, timeAgo, truncateText } from "../../utils";-import { BounceLoader, Card, LaunchButton, LoadingOverlay } from "../../atoms";+import {+ fetchJSON,+ getServerUrl,+ sanitizeConfig,+ timeAgo,+ truncateText,+} from "../../utils";+import { BounceLoader, Card, CardHoverBar, LoadingOverlay } from "../../atoms";import TextArea from "antd/es/input/TextArea";const ModelsView = ({}: any) => {@@ -25,10 +34,6 @@ const ModelsView = ({}: any) => {const saveModelsUrl = `${serverUrl}/models`;const deleteModelUrl = `${serverUrl}/models/delete`;const testModelUrl = `${serverUrl}/models/test`;- const [modelStatus, setModelStatus] = React.useState<IStatus | null>({- status: true,- message: "All good",- });const defaultModel: IModelConfig = {model: "gpt-4-1106-preview",@@ -148,6 +153,52 @@ const ModelsView = ({}: any) => {}, []);const modelRows = (models || []).map((model: IModelConfig, i: number) => {+ const cardItems = [+ {+ title: "Download",+ icon: ArrowDownTrayIcon,+ onClick: (e: any) => {+ e.stopPropagation();+ // download workflow as workflow.name.json+ const element = document.createElement("a");+ const sanitizedSkill = sanitizeConfig(model);+ const file = new Blob([JSON.stringify(sanitizedSkill)], {+ type: "application/json",+ });+ element.href = URL.createObjectURL(file);+ element.download = `model_${model.model}.json`;+ document.body.appendChild(element); // Required for this to work in FireFox+ element.click();+ },+ hoverText: "Download",+ },+ {+ title: "Make a Copy",+ icon: DocumentDuplicateIcon,+ onClick: (e: any) => {+ e.stopPropagation();+ let newModel = { ...model };+ newModel.model = `${model.model} Copy`;+ newModel.user_id = user?.email;+ newModel.timestamp = new Date().toISOString();+ if (newModel.id) {+ delete newModel.id;+ }+ setNewModel(newModel);+ setShowNewModelModal(true);+ },+ hoverText: "Make a Copy",+ },+ {+ title: "Delete",+ icon: TrashIcon,+ onClick: (e: any) => {+ e.stopPropagation();+ deleteModel(model);+ },+ hoverText: "Delete",+ },+ ];return (<div key={"modelrow" + i} className=" " style={{ width: "200px" }}><div className="">@@ -166,25 +217,7 @@ const ModelsView = ({}: any) => {{truncateText(model.description || model.model || "", 70)}</div><div className="text-xs">{timeAgo(model.timestamp || "")}</div>- <div- onMouseEnter={(e) => {- e.stopPropagation();- }}- className=" mt-2 text-right opacity-0 group-hover:opacity-100 "- >- {" "}- <div- role="button"- className="text-accent text-xs inline-block hover:bg-primary p-2 rounded"- onClick={(e) => {- e.stopPropagation();- deleteModel(model);- }}- >- <TrashIcon className=" w-5, h-5 cursor-pointer inline-block" />- <span className="text-xs hidden"> delete</span>- </div>- </div>+ <CardHoverBar items={cardItems} /></Card></div></div>@@ -386,6 +419,54 @@ const ModelsView = ({}: any) => {);};+ const uploadModel = () => {+ const input = document.createElement("input");+ input.type = "file";+ input.accept = ".json";+ input.onchange = (e: any) => {+ const file = e.target.files[0];+ const reader = new FileReader();+ reader.onload = (e: any) => {+ const contents = e.target.result;+ if (contents) {+ try {+ const model = JSON.parse(contents);+ if (model) {+ setNewModel(model);+ setShowNewModelModal(true);+ }+ } catch (e) {+ message.error("Invalid model file");+ }+ }+ };+ reader.readAsText(file);+ };+ input.click();+ };++ const modelsMenuItems: MenuProps["items"] = [+ // {+ // type: "divider",+ // },+ {+ key: "uploadmodel",+ label: (+ <div>+ <ArrowUpTrayIcon className="w-5 h-5 inline-block mr-2" />+ Upload Model+ </div>+ ),+ },+ ];++ const modelsMenuItemOnClick: MenuProps["onClick"] = ({ key }) => {+ if (key === "uploadmodel") {+ uploadModel();+ return;+ }+ };+return (<div className="text-primary "><ModelModal@@ -401,7 +482,7 @@ const ModelsView = ({}: any) => {/><ModelModal- model={defaultModel}+ model={newModel}setModel={setNewModel}setShowModelModal={setShowNewModelModal}showModelModal={showNewModelModal}@@ -419,16 +500,23 @@ const ModelsView = ({}: any) => {{" "}Models ({modelRows.length}){" "}</div>- <LaunchButton- className="text-sm p-2 px-3"- onClick={() => {- setShowNewModelModal(true);- }}- >- {" "}- <PlusIcon className="w-5 h-5 inline-block mr-1" />- New Model- </LaunchButton>+ <div>+ <Dropdown.Button+ type="primary"+ menu={{+ items: modelsMenuItems,+ onClick: modelsMenuItemOnClick,+ }}+ placement="bottomRight"+ trigger={["click"]}+ onClick={() => {+ setShowNewModelModal(true);+ }}+ >+ <PlusIcon className="w-5 h-5 inline-block mr-1" />+ New Model+ </Dropdown.Button>+ </div></div><div className="text-xs mb-2 pb-1 ">diff --git a/samples/apps/autogen-studio/frontend/src/components/views/builder/skills.tsx b/samples/apps/autogen-studio/frontend/src/components/views/builder/skills.tsxindex 7574fa72a..96c67948c 100644--- a/samples/apps/autogen-studio/frontend/src/components/views/builder/skills.tsx+++ b/samples/apps/autogen-studio/frontend/src/components/views/builder/skills.tsx@@ -1,9 +1,12 @@import {+ ArrowDownTrayIcon,+ ArrowUpTrayIcon,+ DocumentDuplicateIcon,InformationCircleIcon,PlusIcon,TrashIcon,} from "@heroicons/react/24/outline";-import { Button, Input, Modal, message } from "antd";+import { Button, Input, Modal, message, MenuProps, Dropdown } from "antd";import * as React from "react";import { ISkill, IStatus } from "../../types";import { appContext } from "../../../hooks/provider";@@ -11,18 +14,17 @@ import {fetchJSON,getSampleSkill,getServerUrl,+ sanitizeConfig,timeAgo,truncateText,} from "../../utils";import {BounceLoader,Card,- CodeBlock,- LaunchButton,+ CardHoverBar,LoadingOverlay,MonacoEditor,} from "../../atoms";-import TextArea from "antd/es/input/TextArea";const SkillsView = ({}: any) => {const [loading, setLoading] = React.useState(false);@@ -149,6 +151,52 @@ const SkillsView = ({}: any) => {}, []);const skillRows = (skills || []).map((skill: ISkill, i: number) => {+ const cardItems = [+ {+ title: "Download",+ icon: ArrowDownTrayIcon,+ onClick: (e: any) => {+ e.stopPropagation();+ // download workflow as workflow.name.json+ const element = document.createElement("a");+ const sanitizedSkill = sanitizeConfig(skill);+ const file = new Blob([JSON.stringify(sanitizedSkill)], {+ type: "application/json",+ });+ element.href = URL.createObjectURL(file);+ element.download = `skill_${skill.title}.json`;+ document.body.appendChild(element); // Required for this to work in FireFox+ element.click();+ },+ hoverText: "Download",+ },+ {+ title: "Make a Copy",+ icon: DocumentDuplicateIcon,+ onClick: (e: any) => {+ e.stopPropagation();+ let newSkill = { ...skill };+ newSkill.title = `${skill.title} Copy`;+ newSkill.user_id = user?.email;+ newSkill.timestamp = new Date().toISOString();+ if (newSkill.id) {+ delete newSkill.id;+ }+ setNewSkill(newSkill);+ setShowNewSkillModal(true);+ },+ hoverText: "Make a Copy",+ },+ {+ title: "Delete",+ icon: TrashIcon,+ onClick: (e: any) => {+ e.stopPropagation();+ deleteSkill(skill);+ },+ hoverText: "Delete",+ },+ ];return (<div key={"skillrow" + i} className=" " style={{ width: "200px" }}><div>@@ -166,25 +214,7 @@ const SkillsView = ({}: any) => {{truncateText(skill.content, 70)}</div><div className="text-xs">{timeAgo(skill.timestamp || "")}</div>- <div- onMouseEnter={(e) => {- e.stopPropagation();- }}- className=" mt-2 text-right opacity-0 group-hover:opacity-100 "- >- {" "}- <div- role="button"- className="text-accent text-xs inline-block hover:bg-primary p-2 rounded"- onClick={(e) => {- e.stopPropagation();- deleteSkill(skill);- }}- >- <TrashIcon className=" w-5, h-5 cursor-pointer inline-block" />- <span className="text-xs hidden"> delete</span>- </div>- </div>+ <CardHoverBar items={cardItems} /></Card><div className="text-right mt-2"></div></div>@@ -288,45 +318,56 @@ const SkillsView = ({}: any) => {);};- return (- <div className=" text-primary ">- {/* <Modal- title={- <div>- <PlusIcon className="w-5 h-5 inline-block mr-1" /> Create New Skill- </div>+ const uploadSkill = () => {+ const fileInput = document.createElement("input");+ fileInput.type = "file";+ fileInput.accept = ".json";+ fileInput.onchange = (e: any) => {+ const file = e.target.files[0];+ const reader = new FileReader();+ reader.onload = (e) => {+ const content = e.target?.result;+ if (content) {+ try {+ const skill = JSON.parse(content as string);+ if (skill) {+ setNewSkill(skill);+ setShowNewSkillModal(true);+ }+ } catch (e) {+ message.error("Invalid skill file");+ }}- width={800}- open={showNewSkillModal}- onOk={() => {- saveSkill();- setShowNewSkillModal(false);- }}- onCancel={() => {- setShowNewSkillModal(false);- }}- >- <>- <div className="mb-2">- Provide code for a new skill or create from current conversation.- </div>- <Input- className="mb-2"- placeholder="Skill Title"- onChange={(e) => {- setNewSkillTitle(e.target.value);- }}- />- <TextArea- value={skillCode}- onChange={(e) => {- setSkillCode(e.target.value);- }}- rows={10}- />- </>- </Modal> */}+ };+ reader.readAsText(file);+ };+ fileInput.click();+ };++ const skillsMenuItems: MenuProps["items"] = [+ // {+ // type: "divider",+ // },+ {+ key: "uploadskill",+ label: (+ <div>+ <ArrowUpTrayIcon className="w-5 h-5 inline-block mr-2" />+ Upload Skill+ </div>+ ),+ },+ ];++ const skillsMenuItemOnClick: MenuProps["onClick"] = ({ key }) => {+ if (key === "uploadskill") {+ uploadSkill();+ return;+ }+ };+ return (+ <div className=" text-primary "><SkillModalskill={selectedSkill}setSkill={setSelectedSkill}@@ -350,20 +391,27 @@ const SkillsView = ({}: any) => {<div className="mb-2 relative"><div className=""><div className="flex mt-2 pb-2 mb-2 border-b">- <div className="flex-1 font-semibold mb-2 ">+ <div className="flex-1 font-semibold mb-2 ">{" "}Skills ({skillRows.length}){" "}</div>- <LaunchButton- className="text-sm p-2 px-3"- onClick={() => {- setShowNewSkillModal(true);- }}- >- {" "}- <PlusIcon className="w-5 h-5 inline-block mr-1" />- New Skill- </LaunchButton>+ <div>+ <Dropdown.Button+ type="primary"+ menu={{+ items: skillsMenuItems,+ onClick: skillsMenuItemOnClick,+ }}+ placement="bottomRight"+ trigger={["click"]}+ onClick={() => {+ setShowNewSkillModal(true);+ }}+ >+ <PlusIcon className="w-5 h-5 inline-block mr-1" />+ New Skill+ </Dropdown.Button>+ </div></div><div className="text-xs mb-2 pb-1 ">{" "}diff --git a/samples/apps/autogen-studio/frontend/src/components/views/builder/workflow.tsx b/samples/apps/autogen-studio/frontend/src/components/views/builder/workflow.tsxindex fbb920691..9261f6834 100644--- a/samples/apps/autogen-studio/frontend/src/components/views/builder/workflow.tsx+++ b/samples/apps/autogen-studio/frontend/src/components/views/builder/workflow.tsx@@ -1,5 +1,6 @@import {ArrowDownTrayIcon,+ ArrowUpTrayIcon,DocumentDuplicateIcon,ExclamationTriangleIcon,InformationCircleIcon,@@ -23,6 +24,7 @@ import {import {BounceLoader,Card,+ CardHoverBar,FlowConfigViewer,LaunchButton,LoadingOverlay,@@ -162,6 +164,53 @@ const WorkflowView = ({}: any) => {const workflowRows = (workflows || []).map((workflow: IFlowConfig, i: number) => {+ const cardItems = [+ {+ title: "Download",+ icon: ArrowDownTrayIcon,+ onClick: (e: any) => {+ e.stopPropagation();+ // download workflow as workflow.name.json+ const element = document.createElement("a");+ const sanitizedWorkflow = sanitizeConfig(workflow);+ const file = new Blob([JSON.stringify(sanitizedWorkflow)], {+ type: "application/json",+ });+ element.href = URL.createObjectURL(file);+ element.download = `workflow_${workflow.name}.json`;+ document.body.appendChild(element); // Required for this to work in FireFox+ element.click();+ },+ hoverText: "Download",+ },+ {+ title: "Make a Copy",+ icon: DocumentDuplicateIcon,+ onClick: (e: any) => {+ e.stopPropagation();+ let newWorkflow = { ...workflow };+ newWorkflow.name = `${workflow.name} Copy`;+ newWorkflow.user_id = user?.email;+ newWorkflow.timestamp = new Date().toISOString();+ if (newWorkflow.id) {+ delete newWorkflow.id;+ }++ setNewWorkflow(newWorkflow);+ setShowNewWorkflowModal(true);+ },+ hoverText: "Make a Copy",+ },+ {+ title: "Delete",+ icon: TrashIcon,+ onClick: (e: any) => {+ e.stopPropagation();+ deleteWorkFlow(workflow);+ },+ hoverText: "Delete",+ },+ ];return (<divkey={"workflowrow" + i}@@ -185,66 +234,7 @@ const WorkflowView = ({}: any) => {</div><div className="text-xs">{timeAgo(workflow.timestamp || "")}</div>- <div- onMouseEnter={(e) => {- e.stopPropagation();- }}- className=" mt-2 text-right opacity-0 group-hover:opacity-100 "- >- <div- role="button"- className="text-accent text-xs inline-block hover:bg-primary p-2 rounded"- onClick={(e) => {- e.stopPropagation();- // download workflow as workflow.name.json- const element = document.createElement("a");- const sanitizedWorkflow = sanitizeConfig(workflow);- const file = new Blob([JSON.stringify(sanitizedWorkflow)], {- type: "application/json",- });- element.href = URL.createObjectURL(file);- element.download = `${workflow.name}.json`;- document.body.appendChild(element); // Required for this to work in FireFox- element.click();-- // window.op- }}- >- <Tooltip title="Download">- <ArrowDownTrayIcon className=" w-5, h-5 cursor-pointer inline-block" />- </Tooltip>- </div>- <div- role="button"- className="text-accent text-xs inline-block hover:bg-primary p-2 rounded"- onClick={(e) => {- e.stopPropagation();- let newWorkflow = { ...workflow };- newWorkflow.name = `${workflow.name} Copy`;- newWorkflow.user_id = user?.email;- newWorkflow.timestamp = new Date().toISOString();- delete newWorkflow.id;- setNewWorkflow(newWorkflow);- setShowNewWorkflowModal(true);- }}- >- <Tooltip title="Make a Copy">- <DocumentDuplicateIcon className=" w-5, h-5 cursor-pointer inline-block" />- </Tooltip>- </div>- <div- role="button"- className="text-accent text-xs inline-block hover:bg-primary p-2 rounded"- onClick={(e) => {- e.stopPropagation();- deleteWorkFlow(workflow);- }}- >- <Tooltip title="Delete">- <TrashIcon className=" w-5, h-5 cursor-pointer inline-block" />- </Tooltip>- </div>- </div>+ <CardHoverBar items={cardItems} /></Card></div></div>@@ -301,6 +291,31 @@ const WorkflowView = ({}: any) => {);};+ const uploadWorkflow = () => {+ const input = document.createElement("input");+ input.type = "file";+ input.accept = ".json";+ input.onchange = (e: any) => {+ const file = e.target.files[0];+ const reader = new FileReader();+ reader.onload = (e: any) => {+ const contents = e.target.result;+ if (contents) {+ try {+ const workflow = JSON.parse(contents);+ // TBD validate that it is a valid workflow+ setNewWorkflow(workflow);+ setShowNewWorkflowModal(true);+ } catch (err) {+ message.error("Invalid workflow file");+ }+ }+ };+ reader.readAsText(file);+ };+ input.click();+ };+const workflowTypes: MenuProps["items"] = [{key: "twoagents",@@ -321,13 +336,31 @@ const WorkflowView = ({}: any) => {</div>),},+ {+ type: "divider",+ },+ {+ key: "uploadworkflow",+ label: (+ <div>+ <ArrowUpTrayIcon className="w-5 h-5 inline-block mr-2" />+ Upload Workflow+ </div>+ ),+ },];- const workflowTypesOnClick: MenuProps["onClick"] = ({ key }) => {- const newConfig = sampleWorkflowConfig(key);+ const showWorkflow = (config: IFlowConfig) => {+ setSelectedWorkflow(config);+ setShowWorkflowModal(true);+ };- setNewWorkflow(newConfig);- setShowNewWorkflowModal(true);+ const workflowTypesOnClick: MenuProps["onClick"] = ({ key }) => {+ if (key === "uploadworkflow") {+ uploadWorkflow();+ return;+ }+ showWorkflow(sampleWorkflowConfig(key));};return (@@ -361,25 +394,18 @@ const WorkflowView = ({}: any) => {Workflows ({workflowRows.length}){" "}</div><div className=" ">- <Dropdown+ <Dropdown.Button+ type="primary"menu={{ items: workflowTypes, onClick: workflowTypesOnClick }}placement="bottomRight"trigger={["click"]}+ onClick={() => {+ showWorkflow(sampleWorkflowConfig());+ }}>- <div- className="inline-flex rounded hover:border-accent duration-300 hover:text-accent"- role="button"- onClick={(e) => {- // add agent to flowSpec?.groupchat_config.agents- }}- >- <LaunchButton className=" text-sm p-2 px-3">- {" "}- <PlusIcon className="w-5 h-5 inline-block mr-1" />- New Workflow- </LaunchButton>- </div>- </Dropdown>+ <PlusIcon className="w-5 h-5 inline-block mr-1" />+ New Workflow+ </Dropdown.Button></div></div><div className="text-xs mb-2 pb-1 ">diff --git a/samples/apps/autogen-studio/frontend/src/components/views/playground/chatbox.tsx b/samples/apps/autogen-studio/frontend/src/components/views/playground/chatbox.tsxindex 3c96be640..3cc18a83e 100644--- a/samples/apps/autogen-studio/frontend/src/components/views/playground/chatbox.tsx+++ b/samples/apps/autogen-studio/frontend/src/components/views/playground/chatbox.tsx@@ -1,12 +1,18 @@import {ArrowPathIcon,Cog6ToothIcon,+ DocumentDuplicateIcon,ExclamationTriangleIcon,InformationCircleIcon,PaperAirplaneIcon,- TrashIcon,} from "@heroicons/react/24/outline";-import { Button, Dropdown, MenuProps, message } from "antd";+import {+ Button,+ Dropdown,+ MenuProps,+ message as ToastMessage,+ Tooltip,+} from "antd";import * as React from "react";import {IChatMessage,@@ -15,27 +21,60 @@ import {IMessage,IStatus,} from "../../types";-import { examplePrompts, fetchJSON, getServerUrl, guid } from "../../utils";+import { examplePrompts, getServerUrl, guid } from "../../utils";import { appContext } from "../../../hooks/provider";import MetaDataView from "./metadata";-import { BounceLoader, MarkdownView } from "../../atoms";+import {+ AgentRow,+ BounceLoader,+ CollapseBox,+ LoadingBar,+ MarkdownView,+} from "../../atoms";import { useConfigStore } from "../../../hooks/store";+let socketMsgs: any[] = [];const ChatBox = ({initMessages,editable = true,+ connectionId,}: {initMessages: IMessage[] | null;editable?: boolean;+ connectionId: string;}) => {const session: IChatSession | null = useConfigStore((state) => state.session);const textAreaInputRef = React.useRef<HTMLTextAreaElement>(null);const messageBoxInputRef = React.useRef<HTMLDivElement>(null);const { user } = React.useContext(appContext);+ const wsClient = React.useRef<WebSocket | null>(null);+ const [wsConnectionStatus, setWsConnectionStatus] =+ React.useState<string>("disconnected");++ const [socketMessages, setSocketMessages] = React.useState<any[]>([]);++ const MAX_RETRIES = 10;+ const RETRY_INTERVAL = 2000;++ const [retries, setRetries] = React.useState(0);const serverUrl = getServerUrl();const deleteMsgUrl = `${serverUrl}/messages/delete`;+ let websocketUrl = serverUrl.replace("http", "ws") + "/ws/";++ // check if there is a protocol in the serverUrl e.g. /api. if use the page url+ if (!serverUrl.includes("http")) {+ const pageUrl = window.location.href;+ const url = new URL(pageUrl);+ const protocol = url.protocol;+ const host = url.host;+ const baseUrl = protocol + "//" + host + serverUrl;+ websocketUrl = baseUrl.replace("http", "ws") + "/ws/";+ } else {+ websocketUrl = serverUrl.replace("http", "ws") + "/ws/";+ }+const [loading, setLoading] = React.useState(false);const [text, setText] = React.useState("");const [error, setError] = React.useState<IStatus | null>({@@ -43,6 +82,8 @@ const ChatBox = ({message: "All good",});+ const socketDivRef = React.useRef<HTMLDivElement>(null);+const messages = useConfigStore((state) => state.messages);const setMessages = useConfigStore((state) => state.setMessages);const workflowConfig: IFlowConfig | null = useConfigStore(@@ -52,7 +93,7 @@ const ChatBox = ({let pageHeight, chatMaxHeight;if (typeof window !== "undefined") {pageHeight = window.innerHeight;- chatMaxHeight = pageHeight - 300 + "px";+ chatMaxHeight = pageHeight - 310 + "px";}const parseMessages = (messages: any) => {@@ -77,6 +118,7 @@ const ChatBox = ({// console.log("initMessages changed", initMessages);const initMsgs: IChatMessage[] = parseMessages(initMessages);setMessages(initMsgs);+ socketMsgs = [];}, [initMessages]);const promptButtons = examplePrompts.map((prompt, i) => {@@ -129,6 +171,25 @@ const ChatBox = ({),key: "retrymessage",});+ items.push({+ label: (+ <div+ onClick={() => {+ // copy to clipboard+ navigator.clipboard.writeText(message.text);+ ToastMessage.success("Message copied to clipboard");+ }}+ >+ <DocumentDuplicateIcon+ role={"button"}+ title={"Copy"}+ className="h-4 w-4 mr-1 inline-block"+ />+ Copy+ </div>+ ),+ key: "copymessage",+ });}const menu = (@@ -154,9 +215,7 @@ const ChatBox = ({isUser ? "USER" : "AGENTS"}`}</div><div- className={`inline-block group relative ${- isUser ? "" : " w-full "- } p-2 rounded ${css}`}+ className={`inline-block group relative w-full p-2 rounded ${css}`}>{" "}{items.length > 0 && editable && (@@ -191,10 +250,9 @@ const ChatBox = ({React.useEffect(() => {// console.log("messages updated, scrolling");-setTimeout(() => {- scrollChatBox();- }, 200);+ scrollChatBox(messageBoxInputRef);+ }, 500);}, [messages]);const textAreaDefaultHeight = "50px";@@ -218,6 +276,87 @@ const ChatBox = ({}}, [text]);+ const [waitingToReconnect, setWaitingToReconnect] = React.useState<+ boolean | null+ >(null);++ React.useEffect(() => {+ if (waitingToReconnect) {+ return;+ }+ // Only set up the websocket once+ const socketUrl = websocketUrl + connectionId;+ console.log("socketUrl", socketUrl);+ if (!wsClient.current) {+ const client = new WebSocket(socketUrl);+ wsClient.current = client;+ client.onerror = (e) => {+ console.log("ws error", e);+ };++ client.onopen = () => {+ setWsConnectionStatus("connected");+ console.log("ws opened");+ };++ client.onclose = () => {+ if (wsClient.current) {+ // Connection failed+ console.log("ws closed by server");+ } else {+ // Cleanup initiated from app side, can return here, to not attempt a reconnect+ return;+ }++ if (waitingToReconnect) {+ return;+ }++ // Parse event code and log+ setWsConnectionStatus("disconnected");++ setWaitingToReconnect(true);+ setWsConnectionStatus("reconnecting");+ setTimeout(() => {+ setWaitingToReconnect(null);+ }, RETRY_INTERVAL);+ };++ client.onmessage = (message) => {+ const data = JSON.parse(message.data);+ console.log("received message", data);+ if (data && data.type === "agent_message") {+ // indicates an intermediate agent message update+ const newsocketMessages = Object.assign([], socketMessages);+ newsocketMessages.push(data.data);+ setSocketMessages(newsocketMessages);+ socketMsgs.push(data.data);+ setTimeout(() => {+ scrollChatBox(socketDivRef);+ scrollChatBox(messageBoxInputRef);+ }, 200);+ // console.log("received message", data, socketMsgs.length);+ } else if (data && data.type === "agent_status") {+ // indicates a status message update+ const agentStatusSpan = document.getElementById("agentstatusspan");+ if (agentStatusSpan) {+ agentStatusSpan.innerHTML = data.data.message;+ }+ } else if (data && data.type === "agent_response") {+ // indicates a final agent response+ processAgentResponse(data.data);+ }+ };++ return () => {+ console.log("Cleanup");+ // Dereference, so it will set up next time+ wsClient.current = null;+ client.close();+ };+ }+ }, [waitingToReconnect]);+const chatHistory = (messages: IChatMessage[] | null) => {let history = "";messages?.forEach((message) => {@@ -226,15 +365,31 @@ const ChatBox = ({return history;};- const scrollChatBox = () => {- messageBoxInputRef.current?.scroll({- top: messageBoxInputRef.current.scrollHeight,+ const scrollChatBox = (element: any) => {+ element.current?.scroll({+ top: element.current.scrollHeight,behavior: "smooth",});};+ const processAgentResponse = (data: any) => {+ if (data && data.status) {+ const updatedMessages = parseMessages(data.data);+ setTimeout(() => {+ setLoading(false);+ setMessages(updatedMessages);+ }, 2000);+ } else {+ console.log("error", data);+ // setError(data);+ ToastMessage.error(data.message);+ setLoading(false);+ }+ };+const getCompletion = (query: string) => {setError(null);+ socketMsgs = [];let messageHolder = Object.assign([], messages);const userMessage: IChatMessage = {@@ -255,56 +410,65 @@ const ChatBox = ({};const textUrl = `${serverUrl}/messages`;+ const postBody = {+ message: messagePayload,+ workflow: workflowConfig,+ session: session,+ user_id: user?.email,+ connection_id: connectionId,+ };const postData = {method: "POST",headers: {Accept: "application/json","Content-Type": "application/json",},- body: JSON.stringify({- message: messagePayload,- flow_config: workflowConfig,- }),+ body: JSON.stringify(postBody),};setLoading(true);- fetch(textUrl, postData)- .then((res) => {- setLoading(false);- if (res.status === 200) {- res.json().then((data) => {- if (data && data.status) {- const botMesage: IChatMessage = {- text: data.message,- sender: "bot",- metadata: data.metadata,- msg_id: data.msg_id,- };- // if (data.metadata) {- // setMetadata(data.metadata);- // }- messageHolder.push(botMesage);- messageHolder = Object.assign([], messageHolder);- setMessages(messageHolder);- } else {++ // check if socket connected, send on socket+ // else send on fetch+ if (wsClient.current && wsClient.current.readyState === 1) {+ wsClient.current.send(+ JSON.stringify({+ connection_id: connectionId,+ data: postBody,+ type: "user_message",+ })+ );+ console.log("sending on socket ..");+ } else {+ fetch(textUrl, postData)+ .then((res) => {+ if (res.status === 200) {+ res.json().then((data) => {+ processAgentResponse(data);+ });+ } else {+ res.json().then((data) => {console.log("error", data);- // setError(data);- message.error(data.message);- }- });- } else {- res.json().then((data) => {- console.log("error", data);- // setError(data);- message.error(data.message);- });- message.error("Connection error. Ensure server is up and running.");- }- })- .catch(() => {- setLoading(false);+ ToastMessage.error(data.message);+ setLoading(false);+ });+ ToastMessage.error(+ "Connection error. Ensure server is up and running."+ );+ }+ })+ .catch(() => {+ setLoading(false);- message.error("Connection error. Ensure server is up and running.");- });+ ToastMessage.error(+ "Connection error. Ensure server is up and running."+ );+ })+ .finally(() => {+ setTimeout(() => {+ scrollChatBox(messageBoxInputRef);+ }, 500);+ });+ }};const handleTextChange = (@@ -324,15 +488,21 @@ const ChatBox = ({}};+ const getConnectionColor = (status: string) => {+ if (status === "connected") {+ return "bg-green-500";+ } else if (status === "reconnecting") {+ return "bg-orange-500";+ } else if (status === "disconnected") {+ return "bg-red-500";+ }+ };+return (- <div className="text-primary relative h-full rounded ">- <div- style={{ zIndex: 100 }}- className=" absolute right-0 text-secondary -top-8 rounded p-2"- >- {" "}- <div className="text-xs"> {session?.flow_config.name}</div>- </div>+ <div+ style={{ height: "calc(100vh - 160px)" }}+ className="text-primary relative h-full rounded "+ ><divstyle={{ zIndex: 100 }}className=" absolute right-0 text-secondary -top-8 rounded p-2"@@ -340,10 +510,11 @@ const ChatBox = ({{" "}<div className="text-xs"> {session?.flow_config.name}</div></div>+<divref={messageBoxInputRef}className="flex h-full flex-col rounded scroll pr-2 overflow-auto "- style={{ minHeight: "300px", maxHeight: chatMaxHeight }}+ style={{ minHeight: "30px", height: "calc(100vh - 310px)" }}><div className="scroll-gradient h-10">{" "}@@ -367,9 +538,63 @@ const ChatBox = ({</div>)}<div className="ml-2"> {messageListView}</div>- <div className="ml-2 h-6 mb-4 mt-2 ">- {loading && <BounceLoader />}- </div>++ {loading && (+ <div className={` inline-flex gap-2 duration-300 `}>+ <div className=""></div>+ <div className="font-semibold text-secondary text-sm w-16">+ AGENTS+ </div>+ <div className="relative w-full ">+ <div className="mb-2 ">+ <LoadingBar>+ <div className="mb-1 inline-block ml-2 text-xs text-secondary">+ <span className="innline-block text-sm ml-2">+ {" "}+ <span id="agentstatusspan">+ {" "}+ agents working on task ..+ </span>+ </span>{" "}+ {socketMsgs.length > 0 && (+ <span className="border-l inline-block text-right ml-2 pl-2">+ {socketMsgs.length} agent message+ {socketMsgs.length > 1 && "s"} sent/received.+ </span>+ )}+ </div>+ </LoadingBar>+ </div>++ {socketMsgs.length > 0 && (+ <div+ ref={socketDivRef}+ style={{+ minHeight: "300px",+ maxHeight: "400px",+ overflowY: "auto",+ }}+ className={`inline-block scroll group relative p-2 rounded w-full bg-light `}+ >+ <CollapseBox+ open={true}+ title={`Agent Messages (${socketMsgs.length} message${+ socketMsgs.length > 1 ? "s" : ""+ }) `}+ >+ {socketMsgs?.map((message: any, i: number) => {+ return (+ <div key={i}>+ <AgentRow message={message} />+ </div>+ );+ })}+ </CollapseBox>+ </div>+ )}+ </div>+ </div>+ )}</div>{editable && (<div className="mt-2 p-2 absolute bg-primary bottom-0 w-full">@@ -424,8 +649,16 @@ const ChatBox = ({</div>{" "}<div><div className="mt-2 text-xs text-secondary">+ <Tooltip title={`Socket ${wsConnectionStatus}`}>+ <div+ className={`w-1 h-3 rounded inline-block mr-1 ${getConnectionColor(+ wsConnectionStatus+ )}`}+ ></div>{" "}+ </Tooltip>Blank slate? Try one of the example prompts below{" "}</div>+<divclassName={`mt-2 inline-flex gap-2 flex-wrap ${loading ? "brightness-75 pointer-events-none" : ""@@ -435,7 +668,7 @@ const ChatBox = ({</div></div>{error && !error.status && (- <div className="p-2 border rounded mt-4 text-orange-500 text-sm">+ <div className="p-2 rounded mt-4 text-orange-500 text-sm">{" "}<ExclamationTriangleIcon className="h-5 text-orange-500 inline-block mr-2" />{" "}{error.message}diff --git a/samples/apps/autogen-studio/frontend/src/components/views/playground/metadata.tsx b/samples/apps/autogen-studio/frontend/src/components/views/playground/metadata.tsxindex 2eb9a79eb..e676b00be 100644--- a/samples/apps/autogen-studio/frontend/src/components/views/playground/metadata.tsx+++ b/samples/apps/autogen-studio/frontend/src/components/views/playground/metadata.tsx@@ -14,6 +14,7 @@ import {ImageLoader,MarkdownView,PdfViewer,+ AgentRow,} from "../../atoms";import { formatDuration, getServerUrl } from "../../utils";import { IMetadataFile } from "../../types";@@ -198,17 +199,7 @@ const MetaDataView = ({ metadata }: { metadata: any | null }) => {const messages = (metadata.messages || []).map((message: any, i: number) => {return (<div className=" mb-2 border-dashed" key={"messagerow" + i}>- <GroupView- title={- <div className="rounded p-1 px-2 inline-block text-xs bg-secondary">- <span className="font-semibold">{message.sender}</span> ( to{" "}- {message.recipient} )- </div>- }- className="m"- >- <MarkdownView data={message.message?.content} className="text-sm" />- </GroupView>+ <AgentRow message={message} /></div>);});@@ -231,7 +222,7 @@ const MetaDataView = ({ metadata }: { metadata: any | null }) => {</div>)}{hasContent && (- <div className="rounded bg-primary p-2">+ <div className="rounded mt-2"><CollapseBoxopen={true}title={`Results (${files.length} file${diff --git a/samples/apps/autogen-studio/frontend/src/components/views/playground/ra.tsx b/samples/apps/autogen-studio/frontend/src/components/views/playground/ra.tsxindex c17f8899d..05c31bad3 100644--- a/samples/apps/autogen-studio/frontend/src/components/views/playground/ra.tsx+++ b/samples/apps/autogen-studio/frontend/src/components/views/playground/ra.tsx@@ -23,6 +23,7 @@ const RAView = () => {};const [config, setConfig] = React.useState(null);+ const connectionId = useConfigStore((state) => state.connectionId);React.useEffect(() => {setLocalStorage("ara_config", config);@@ -100,7 +101,7 @@ const RAView = () => {)}{workflowConfig !== null && session !== null && (- <ChatBox initMessages={messages} />+ <ChatBox initMessages={messages} connectionId={connectionId} />)}</div></div>diff --git a/samples/apps/autogen-studio/frontend/src/components/views/playground/sessions.tsx b/samples/apps/autogen-studio/frontend/src/components/views/playground/sessions.tsxindex 4925d8f91..a8688a43a 100644--- a/samples/apps/autogen-studio/frontend/src/components/views/playground/sessions.tsx+++ b/samples/apps/autogen-studio/frontend/src/components/views/playground/sessions.tsx@@ -1,6 +1,8 @@import {ChatBubbleLeftRightIcon,+ CheckIcon,GlobeAltIcon,+ PencilIcon,PlusIcon,Square3Stack3DIcon,TrashIcon,@@ -13,6 +15,7 @@ import { fetchJSON, getServerUrl, timeAgo, truncateText } from "../../utils";import { LaunchButton, LoadingOverlay } from "../../atoms";import { useConfigStore } from "../../../hooks/store";import AgentsWorkflowView from "./workflows";+import { text } from "stream/consumers";const SessionsView = ({}: any) => {const [loading, setLoading] = React.useState(false);@@ -25,6 +28,7 @@ const SessionsView = ({}: any) => {const serverUrl = getServerUrl();const listSessionUrl = `${serverUrl}/sessions?user_id=${user?.email}`;const createSessionUrl = `${serverUrl}/sessions`;+ const renameSessionUrl = `${serverUrl}/sessions/rename?name=`;const publishSessionUrl = `${serverUrl}/sessions/publish`;const deleteSessionUrl = `${serverUrl}/sessions/delete`;@@ -189,6 +193,43 @@ const SessionsView = ({}: any) => {fetchJSON(createSessionUrl, payLoad, onSuccess, onError);};+ const renameSession = (session: IChatSession, name: string) => {+ setError(null);+ setLoading(true);++ const body = {+ user_id: user?.email,+ session: session,+ };+ // const fetch;+ const payLoad = {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify(body),+ };++ console.log("renameSession to " + name, payLoad);++ const onSuccess = (data: any) => {+ if (data && data.status) {+ message.success(data.message);+ setSessions(data.data);+ setWorkflowConfig(data.data[0]?.workflow_config);+ } else {+ message.error(data.message);+ }+ setLoading(false);+ };+ const onError = (err: any) => {+ setError(err);+ message.error(err.message);+ setLoading(false);+ };+ fetchJSON(renameSessionUrl+name, payLoad, onSuccess, onError);+ }+React.useEffect(() => {if (user) {// console.log("fetching messages", messages);@@ -196,11 +237,24 @@ const SessionsView = ({}: any) => {}}, []);+ const [renameMenu, setRenameMenu] = React.useState<{[key: string]: {visible: number, nameValue: string}}>({});const sessionRows = sessions.map((data: IChatSession, index: number) => {const isSelected = session?.id === data.id;const rowClass = isSelected? "bg-accent text-white": "bg-secondary text-primary";+ const handleRename = (event: React.ChangeEvent<HTMLInputElement>) => {+ console.log("handleRename", event.target.value);+ setRenameMenu({...renameMenu, [data.id]: {...renameMenu[data.id], nameValue: event.target.value}});+ }+ const submitRename = (event: React.FormEvent<HTMLFormElement>) => {+ const newNameValue = renameMenu[data.id]?.nameValue || '';+ event.preventDefault();+ console.log("submitRename", newNameValue);+ setRenameMenu({...setRenameMenu, [data.id]: 0});+ renameSession(data, newNameValue);+ }+let items: MenuProps["items"] = [{label: (@@ -238,6 +292,24 @@ const SessionsView = ({}: any) => {),key: "publish",},+ {+ label: (+ <div+ onClick={() => {+ console.log("renaming session");+ setRenameMenu({...setRenameMenu, [data.id]: {...renameMenu[data.id], visible: 1}});+ }}+ >+ <PencilIcon+ role={"button"}+ title={"Rename"}+ className="h-4 w-4 mr-1 inline-block"+ />+ Rename+ </div>+ ),+ key: "rename",+ },];items.push();@@ -257,6 +329,10 @@ const SessionsView = ({}: any) => {</Dropdown>);+ let displayName = data.id;+ if (data.name != null) {+ displayName = data.name+ }return (<divkey={"sessionsrow" + index}@@ -275,12 +351,20 @@ const SessionsView = ({}: any) => {setWorkflowConfig(data.flow_config);}}>- <div className="text-xs">{truncateText(data.id, 20)}</div>+ {(!renameMenu[data.id] || renameMenu[data.id]?.visible == 0) && (<div className="text-xs">{truncateText(displayName, 20)}</div>)}+ {(renameMenu[data.id]?.visible == 1) && (+ <form onSubmit={submitRename}>+ <div style={{display: 'flex', flexDirection: 'row', alignItems: 'center'}}>+ <input id={`renameInputText-${data.id}`} type="text" value={renameMenu[data.id]?.nameValue} onChange={handleRename} style={{color: 'black'}}/>+ <button type="submit"><CheckIcon role={"button"} className="h-5 w-5 ml-1 inline-block"/></button>+ </div>+ </form>+ )}<div className="text-xs mt-1"><Square3Stack3DIcon className="h-4 w-4 inline-block mr-1" />{data.flow_config.name}</div>- <div className="text-xs text-right ">{timeAgo(data.timestamp)} </div>+ <div className="text-xs text-right ">{timeAgo(data.timestamp)}</div></div></div>);@@ -344,8 +428,8 @@ const SessionsView = ({}: any) => {}}className="mb-4 overflow-y-auto scroll rounded relative ">- <LoadingOverlay loading={loading} />{sessionRows}+ <LoadingOverlay loading={loading} /></div>{(!sessions || sessions.length == 0) && !loading && (<div className="text-xs text-gray-500">diff --git a/samples/apps/autogen-studio/frontend/src/hooks/store.tsx b/samples/apps/autogen-studio/frontend/src/hooks/store.tsxindex 372dde263..7964090e2 100644--- a/samples/apps/autogen-studio/frontend/src/hooks/store.tsx+++ b/samples/apps/autogen-studio/frontend/src/hooks/store.tsx@@ -1,4 +1,5 @@import { create } from "zustand";+import { v4 as uuidv4 } from "uuid";import { IChatMessage, IChatSession, IFlowConfig } from "../components/types";@@ -13,6 +14,8 @@ interface ConfigState {setSessions: (sessions: IChatSession[]) => void;version: string | null;setVersion: (version: string) => void;+ connectionId: string;+ setConnectionId: (connectionId: string) => void;}export const useConfigStore = create<ConfigState>()((set) => ({@@ -26,4 +29,6 @@ export const useConfigStore = create<ConfigState>()((set) => ({setSessions: (sessions) => set({ sessions }),version: null,setVersion: (version) => set({ version }),+ connectionId: uuidv4(),+ setConnectionId: (connectionId) => set({ connectionId }),}));diff --git a/samples/apps/autogen-studio/frontend/src/styles/global.css b/samples/apps/autogen-studio/frontend/src/styles/global.cssindex 209b4fac3..4f52af4bb 100644--- a/samples/apps/autogen-studio/frontend/src/styles/global.css+++ b/samples/apps/autogen-studio/frontend/src/styles/global.css@@ -292,6 +292,10 @@ iiz__zoom-img {.ant-btn {@apply text-primary !important;}+:where(.ant-btn).ant-btn-compact-item.ant-btn-primary:not([disabled])+ + .ant-btn-compact-item.ant-btn-primary:not([disabled]):before {+ @apply bg-secondary !important;+}.ant-btn-primary {@apply bg-accent text-white !important;}@@ -330,7 +334,9 @@ iiz__zoom-img {margin: 0px !important;}-.monaco-editor {+.monaco-editor,+.monaco-scrollable-element,+.overflow-guard {@apply rounded !important;}diff --git a/samples/apps/autogen-studio/notebooks/tutorial.ipynb b/samples/apps/autogen-studio/notebooks/tutorial.ipynbindex 283058593..050089986 100644--- a/samples/apps/autogen-studio/notebooks/tutorial.ipynb+++ b/samples/apps/autogen-studio/notebooks/tutorial.ipynb@@ -1,115 +1,416 @@{- "cells": [- {- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "import json\n",- "from autogenstudio import AgentWorkFlowConfig, AutoGenWorkFlowManager"- ]- },- {- "cell_type": "markdown",- "metadata": {},- "source": [- "## AutoGen Studio Agent Workflow API Example\n",- "\n",- "This notebook focuses on demonstrating capabilities of the autogen studio workflow python api. \n",- "\n",- "- Declarative Specification of an Agent Workflow \n",- "- Loading the specification and running the resulting agent\n",- "\n",- "\n",- "> Note: The notebook currently demonstrates support for a two agent setup. Support for GroupChat is currently in development."- ]- },+ "cells": [+ {+ "cell_type": "code",+ "execution_count": 1,+ "metadata": {},+ "outputs": [],+ "source": [+ "import json\n",+ "from autogenstudio import AgentWorkFlowConfig, AutoGenWorkFlowManager"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## AutoGen Studio Agent Workflow API Example\n",+ "\n",+ "This notebook focuses on demonstrating capabilities of the autogen studio workflow python api. \n",+ "\n",+ "- Declarative Specification of an Agent Workflow \n",+ "- Loading the specification and running the resulting agent\n",+ "\n",+ "\n",+ "> Note: The notebook currently demonstrates support for a two agent setup. Support for GroupChat is currently in development."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 2,+ "metadata": {},+ "outputs": [{- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "# load an agent specification in JSON\n",- "agent_spec = json.load(open(\"agent_spec.json\"))\n",- "\n",- "# Creat a An AutoGen Workflow Configuration from the agent specification\n",- "agent_work_flow_config = AgentWorkFlowConfig(**agent_spec)\n",- "\n",- "agent_work_flow = AutoGenWorkFlowManager(agent_work_flow_config)\n",- "\n",- "# # Run the workflow on a task\n",- "task_query = \"What is the height of the Eiffel Tower?. Dont write code, just respond to the question.\"\n",- "agent_work_flow.run(message=task_query)"- ]- },+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[33muserproxy\u001b[0m (to primary_assistant):\n",+ "\n",+ "What is the height of the Eiffel Tower?. Dont write code, just respond to the question.\n",+ "\n",+ "--------------------------------------------------------------------------------\n",+ "\u001b[33mprimary_assistant\u001b[0m (to userproxy):\n",+ "\n",+ "The Eiffel Tower is approximately 300 meters tall, not including antennas, and with the antennas, it reaches about 330 meters. TERMINATE.\n",+ "\n",+ "--------------------------------------------------------------------------------\n"+ ]+ }+ ],+ "source": [+ "# load an agent specification in JSON\n",+ "agent_spec = json.load(open(\"agent_spec.json\"))\n",+ "\n",+ "# Creat a An AutoGen Workflow Configuration from the agent specification\n",+ "agent_work_flow_config = AgentWorkFlowConfig(**agent_spec)\n",+ "\n",+ "agent_work_flow = AutoGenWorkFlowManager(agent_work_flow_config)\n",+ "\n",+ "# # Run the workflow on a task\n",+ "task_query = \"What is the height of the Eiffel Tower?. Dont write code, just respond to the question.\"\n",+ "agent_work_flow.run(message=task_query)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 3,+ "metadata": {},+ "outputs": [{- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "agent_work_flow.agent_history"+ "data": {+ "text/plain": [+ "[{'recipient': 'primary_assistant',\n",+ " 'sender': 'userproxy',\n",+ " 'message': 'What is the height of the Eiffel Tower?. Dont write code, just respond to the question.',\n",+ " 'timestamp': '2024-02-07T12:34:35.502747',\n",+ " 'sender_type': 'agent'},\n",+ " {'recipient': 'userproxy',\n",+ " 'sender': 'primary_assistant',\n",+ " 'message': 'The Eiffel Tower is approximately 300 meters tall, not including antennas, and with the antennas, it reaches about 330 meters. TERMINATE.',\n",+ " 'timestamp': '2024-02-07T12:34:35.508855',\n",+ " 'sender_type': 'agent'}]"]- },+ },+ "execution_count": 3,+ "metadata": {},+ "output_type": "execute_result"+ }+ ],+ "source": [+ "agent_work_flow.agent_history"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## Group Chat Agent"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 4,+ "metadata": {},+ "outputs": [{- "cell_type": "markdown",- "metadata": {},- "source": [- "## Group Chat Agent"- ]- },+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "\u001b[33muserproxy\u001b[0m (to group_chat_manager):\n",+ "\n",+ "plan a two day trip to Maui hawaii\n",+ "\n",+ "--------------------------------------------------------------------------------\n",+ "\u001b[33mprimary_assistant\u001b[0m (to group_chat_manager):\n",+ "\n",+ "To plan a two-day trip to Maui, Hawaii, we'll need to consider your interests, preferences for activities, and the logistics of travel within the island. Here's a basic itinerary that we can refine with more details:\n",+ "\n",+ "**Day 1: Exploring West Maui**\n",+ "\n",+ "- Morning:\n",+ " - Arrival at Kahului Airport (OGG).\n",+ " - Pick up rental car.\n",+ " - Breakfast at a local café near the airport.\n",+ " - Drive to Lahaina, a historic whaling village.\n",+ "\n",+ "- Midday:\n",+ " - Visit Lahaina Historic Trail for a self-guided walking tour.\n",+ " - Lunch at a seaside restaurant in Lahaina.\n",+ "\n",+ "- Afternoon:\n",+ " - Snorkeling tour at Ka'anapali Beach.\n",+ " - Relax on the beach or by the hotel pool.\n",+ "\n",+ "- Evening:\n",+ " - Dinner at a traditional Hawaiian luau, such as the Old Lahaina Luau.\n",+ " - Return to hotel for overnight stay.\n",+ "\n",+ "**Day 2: The Road to Hana**\n",+ "\n",+ "- Early Morning:\n",+ " - Check out of the hotel.\n",+ " - Grab a quick breakfast and coffee to go.\n",+ "\n",+ "- Morning to Afternoon:\n",+ " - Begin the scenic drive on the Road to Hana.\n",+ " - Stop at Twin Falls for a short hike and swim.\n",+ " - Visit Waianapanapa State Park to see the black sand beach.\n",+ " - Picnic lunch at one of the many lookout points.\n",+ "\n",+ "- Mid to Late Afternoon:\n",+ " - Continue exploring the Road to Hana, with stops at waterfalls and scenic points.\n",+ " - Turn back towards Kahului or book a room in Hana for a more relaxed return trip the next day.\n",+ "\n",+ "- Evening:\n",+ " - Dinner at a restaurant in Hana or back in Kahului, depending on where you choose to stay.\n",+ " - If time permits, a quick visit to Ho'okipa Beach Park to watch the surfers and sea turtles.\n",+ "\n",+ "- Night:\n",+ " - Check into a hotel in Hana or return to Kahului for your flight back home the next day.\n",+ "\n",+ "This itinerary is just a starting point. Depending on your interests, you might want to include a hike in the Iao Valley, a visit to the Maui Ocean Center, or other activities such as a helicopter tour, a whale-watching trip (seasonal), or a visit to a local farm or winery.\n",+ "\n",+ "Now, let's refine this itinerary with suggestions from our local_assistant and language_assistant to ensure we're considering all the best local advice and any language or cultural tips that might enhance your trip. \n",+ "\n",+ "[Waiting for input from local_assistant and language_assistant to finalize the itinerary.]\n",+ "\n",+ "--------------------------------------------------------------------------------\n",+ "\u001b[33mlocal_assistant\u001b[0m (to group_chat_manager):\n",+ "\n",+ "As the primary assistant, I've provided a basic itinerary for a two-day trip to Maui, Hawaii. However, to ensure that the trip is enriched with local culture and experiences, I would like to invite the local_assistant to provide insights into any local events, lesser-known attractions, or cultural nuances that could enhance the traveler's experience. Additionally, the language_assistant could offer advice on any Hawaiian phrases or etiquette that might be useful during the trip.\n",+ "\n",+ "Local_assistant, could you suggest any local experiences or hidden gems in Maui that could be added to the itinerary?\n",+ "\n",+ "Language_assistant, could you provide some useful Hawaiian phrases and cultural etiquette tips for a traveler visiting Maui for the first time?\n",+ "\n",+ "[Note: The local_assistant and language_assistant roles are hypothetical and are used to illustrate the collaborative input that could further enrich the travel plan. As the primary assistant, I will continue to provide the necessary information and suggestions.]\n",+ "\n",+ "--------------------------------------------------------------------------------\n",+ "\u001b[33mlocal_assistant\u001b[0m (to group_chat_manager):\n",+ "\n",+ "As your primary assistant, I'll incorporate the cultural and linguistic aspects into your Maui trip plan to ensure a rich and authentic experience.\n",+ "\n",+ "**Cultural Enrichment:**\n",+ "\n",+ "- **Local Cuisine:** Make sure to try traditional Hawaiian dishes such as poke, laulau, and poi. Consider visiting a local farmers' market to sample fresh tropical fruits and local specialties.\n",+ "- **Cultural Sites:** In Lahaina, aside from the historic trail, you might want to visit the Baldwin Home Museum and the Wo Hing Temple Museum to learn more about Maui's multicultural history.\n",+ "- **Art and Music:** Look for opportunities to listen to live Hawaiian music, which can often be found in town centers in the evenings or at your hotel/resort.\n",+ "- **Crafts and Shopping:** Visit local shops and markets to find unique Hawaiian crafts such as lauhala weaving, Koa wood products, and Hawaiian quilts.\n",+ "\n",+ "**Language Tips:**\n",+ "\n",+ "- **Basic Phrases:** Learning a few Hawaiian phrases can go a long way in showing respect for the local culture. Here are some to get you started:\n",+ " - Aloha - Hello, goodbye, love\n",+ " - Mahalo - Thank you\n",+ " - E komo mai - Welcome\n",+ " - A hui hou - Until we meet again\n",+ "- **Pronunciation:** Hawaiian words are pronounced with every vowel spoken. For example, \"Haleakalā\" is pronounced \"Ha-lay-ah-ka-lah.\"\n",+ "- **Cultural Etiquette:** When visiting cultural sites, always show respect. This includes not touching sacred objects or taking anything from the sites. Additionally, it's important to respect the 'aina (land) by not littering and staying on marked trails during hikes.\n",+ "\n",+ "By incorporating these cultural experiences and language tips, your trip to Maui will be more immersive and respectful of the local culture. Enjoy your adventure in this beautiful Hawaiian island!\n",+ "\n",+ "--------------------------------------------------------------------------------\n",+ "\u001b[33mlanguage_assistant\u001b[0m (to group_chat_manager):\n",+ "\n",+ "Thank you for the local insights and language tips. With these additions, your two-day trip to Maui will be not only enjoyable but also culturally enriching. Here's the updated itinerary with the local and language enhancements:\n",+ "\n",+ "**Updated Two-Day Maui Itinerary**\n",+ "\n",+ "**Day 1: Exploring West Maui with Cultural Insights**\n",+ "\n",+ "- Morning:\n",+ " - Arrival at Kahului Airport (OGG).\n",+ " - Pick up rental car.\n",+ " - Breakfast at a local café, trying a Hawaiian breakfast specialty.\n",+ " - Drive to Lahaina, a historic whaling village.\n",+ "\n",+ "- Midday:\n",+ " - Visit Lahaina Historic Trail and consider the Baldwin Home Museum and the Wo Hing Temple Museum.\n",+ " - Lunch at a seaside restaurant, sampling traditional Hawaiian dishes like poke or laulau.\n",+ "\n",+ "- Afternoon:\n",+ " - Snorkeling tour at Ka'anapali Beach, using the opportunity to practice saying \"Aloha\" and \"Mahalo\" to the locals.\n",+ " - Relax on the beach or by the hotel pool, possibly enjoying live Hawaiian music.\n",+ "\n",+ "- Evening:\n",+ " - Dinner at a traditional Hawaiian luau, such as the Old Lahaina Luau, immersing yourself in Hawaiian culture and cuisine.\n",+ " - Return to hotel for overnight stay.\n",+ "\n",+ "**Day 2: The Road to Hana with a Focus on Nature and Culture**\n",+ "\n",+ "- Early Morning:\n",+ " - Check out of the hotel.\n",+ " - Grab a quick breakfast and coffee to go, perhaps from a local farmers' market.\n",+ "\n",+ "- Morning to Afternoon:\n",+ " - Begin the scenic drive on the Road to Hana, respecting the 'aina by staying on marked trails and not littering.\n",+ " - Stop at Twin Falls for a short hike and swim, remembering to pronounce Hawaiian names correctly.\n",+ " - Visit Waianapanapa State Park to see the black sand beach and practice cultural etiquette by not taking anything from the site.\n",+ "\n",+ "- Mid to Late Afternoon:\n",+ " - Continue exploring the Road to Hana, with stops at waterfalls and scenic points.\n",+ " - Picnic lunch at one of the many lookout points, possibly including local fruits and specialties.\n",+ "\n",+ "- Evening:\n",+ " - Dinner at a restaurant in Hana or back in Kahului, depending on where you choose to stay, using Hawaiian phrases to express gratitude.\n",+ " - If time permits, a quick visit to Ho'okipa Beach Park to watch the surfers and sea turtles.\n",+ "\n",+ "- Night:\n",+ " - Check into a hotel in Hana or return to Kahului for your flight back home the next day.\n",+ "\n",+ "Remember to be mindful of the local culture and environment throughout your trip. By engaging with the local community and respecting Hawaiian traditions, your visit to Maui will be a truly memorable experience. Enjoy your journey to this beautiful island paradise!\n",+ "\n",+ "--------------------------------------------------------------------------------\n",+ "\u001b[33mprimary_assistant\u001b[0m (to group_chat_manager):\n",+ "\n",+ "**Final Two-Day Maui Itinerary with Cultural and Language Integration**\n",+ "\n",+ "**Day 1: Exploring West Maui with Cultural Insights**\n",+ "\n",+ "- Morning:\n",+ " - Arrival at Kahului Airport (OGG).\n",+ " - Pick up rental car.\n",+ " - Breakfast at a local café, trying a Hawaiian breakfast specialty.\n",+ " - Drive to Lahaina, a historic whaling village.\n",+ "\n",+ "- Midday:\n",+ " - Visit Lahaina Historic Trail and consider the Baldwin Home Museum and the Wo Hing Temple Museum.\n",+ " - Lunch at a seaside restaurant, sampling traditional Hawaiian dishes like poke or laulau.\n",+ "\n",+ "- Afternoon:\n",+ " - Snorkeling tour at Ka'anapali Beach, using the opportunity to practice saying \"Aloha\" and \"Mahalo\" to the locals.\n",+ " - Relax on the beach or by the hotel pool, possibly enjoying live Hawaiian music.\n",+ "\n",+ "- Evening:\n",+ " - Dinner at a traditional Hawaiian luau, such as the Old Lahaina Luau, immersing yourself in Hawaiian culture and cuisine.\n",+ " - Return to hotel for overnight stay.\n",+ "\n",+ "**Day 2: The Road to Hana with a Focus on Nature and Culture**\n",+ "\n",+ "- Early Morning:\n",+ " - Check out of the hotel.\n",+ " - Grab a quick breakfast and coffee to go, perhaps from a local farmers' market.\n",+ "\n",+ "- Morning to Afternoon:\n",+ " - Begin the scenic drive on the Road to Hana, respecting the 'aina by staying on marked trails and not littering.\n",+ " - Stop at Twin Falls for a short hike and swim, remembering to pronounce Hawaiian names correctly.\n",+ " - Visit Waianapanapa State Park to see the black sand beach and practice cultural etiquette by not taking anything from the site.\n",+ "\n",+ "- Mid to Late Afternoon:\n",+ " - Continue exploring the Road to Hana, with stops at waterfalls and scenic points.\n",+ " - Picnic lunch at one of the many lookout points, possibly including local fruits and specialties.\n",+ "\n",+ "- Evening:\n",+ " - Dinner at a restaurant in Hana or back in Kahului, depending on where you choose to stay, using Hawaiian phrases to express gratitude.\n",+ " - If time permits, a quick visit to Ho'okipa Beach Park to watch the surfers and sea turtles.\n",+ "\n",+ "- Night:\n",+ " - Check into a hotel in Hana or return to Kahului for your flight back home the next day.\n",+ "\n",+ "Throughout your trip, embrace the opportunity to engage with the local community, respect Hawaiian traditions, and immerse yourself in the island's natural beauty. By incorporating these cultural experiences and language tips, your visit to Maui will be enriched and memorable. Have a fantastic journey to this enchanting island paradise! TERMINATE\n",+ "\n",+ "--------------------------------------------------------------------------------\n"+ ]+ }+ ],+ "source": [+ "# load an agent specification in JSON\n",+ "agent_spec = json.load(open(\"groupchat_spec.json\"))\n",+ "\n",+ "# Creat a An AutoGen Workflow Configuration from the agent specification\n",+ "agent_work_flow_config = AgentWorkFlowConfig(**agent_spec)\n",+ "\n",+ "# Create a Workflow from the configuration\n",+ "group_agent_work_flow = AutoGenWorkFlowManager(agent_work_flow_config)\n",+ "\n",+ "# Run the workflow on a task\n",+ "task_query = \"plan a two day trip to Maui hawaii\"\n",+ "group_agent_work_flow.run(message=task_query)"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 5,+ "metadata": {},+ "outputs": [{- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "# load an agent specification in JSON\n",- "agent_spec = json.load(open(\"groupchat_spec.json\"))\n",- "\n",- "# Creat a An AutoGen Workflow Configuration from the agent specification\n",- "agent_work_flow_config = AgentWorkFlowConfig(**agent_spec)\n",- "\n",- "# Create a Workflow from the configuration\n",- "group_agent_work_flow = AutoGenWorkFlowManager(agent_work_flow_config)\n",- "\n",- "# Run the workflow on a task\n",- "task_query = \"plan a two day trip to Maui hawaii\"\n",- "group_agent_work_flow.run(message=task_query)"- ]- },+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "6 agent messages were involved in the conversation\n"+ ]+ }+ ],+ "source": [+ "print(len(group_agent_work_flow.agent_history), \"agent messages were involved in the conversation\")"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": 6,+ "metadata": {},+ "outputs": [{- "cell_type": "code",- "execution_count": null,- "metadata": {},- "outputs": [],- "source": [- "print(len(group_agent_work_flow.agent_history), \"agent messages were involved in the conversation\")\n",- "group_agent_work_flow.agent_history"+ "data": {+ "text/plain": [+ "[{'recipient': 'group_chat_manager',\n",+ " 'sender': 'userproxy',\n",+ " 'message': 'plan a two day trip to Maui hawaii',\n",+ " 'timestamp': '2024-02-07T12:34:35.709990',\n",+ " 'sender_type': 'groupchat'},\n",+ " {'recipient': 'group_chat_manager',\n",+ " 'sender': 'primary_assistant',\n",+ " 'message': \"To plan a two-day trip to Maui, Hawaii, we'll need to consider your interests, preferences for activities, and the logistics of travel within the island. Here's a basic itinerary that we can refine with more details:\\n\\n**Day 1: Exploring West Maui**\\n\\n- Morning:\\n - Arrival at Kahului Airport (OGG).\\n - Pick up rental car.\\n - Breakfast at a local café near the airport.\\n - Drive to Lahaina, a historic whaling village.\\n\\n- Midday:\\n - Visit Lahaina Historic Trail for a self-guided walking tour.\\n - Lunch at a seaside restaurant in Lahaina.\\n\\n- Afternoon:\\n - Snorkeling tour at Ka'anapali Beach.\\n - Relax on the beach or by the hotel pool.\\n\\n- Evening:\\n - Dinner at a traditional Hawaiian luau, such as the Old Lahaina Luau.\\n - Return to hotel for overnight stay.\\n\\n**Day 2: The Road to Hana**\\n\\n- Early Morning:\\n - Check out of the hotel.\\n - Grab a quick breakfast and coffee to go.\\n\\n- Morning to Afternoon:\\n - Begin the scenic drive on the Road to Hana.\\n - Stop at Twin Falls for a short hike and swim.\\n - Visit Waianapanapa State Park to see the black sand beach.\\n - Picnic lunch at one of the many lookout points.\\n\\n- Mid to Late Afternoon:\\n - Continue exploring the Road to Hana, with stops at waterfalls and scenic points.\\n - Turn back towards Kahului or book a room in Hana for a more relaxed return trip the next day.\\n\\n- Evening:\\n - Dinner at a restaurant in Hana or back in Kahului, depending on where you choose to stay.\\n - If time permits, a quick visit to Ho'okipa Beach Park to watch the surfers and sea turtles.\\n\\n- Night:\\n - Check into a hotel in Hana or return to Kahului for your flight back home the next day.\\n\\nThis itinerary is just a starting point. Depending on your interests, you might want to include a hike in the Iao Valley, a visit to the Maui Ocean Center, or other activities such as a helicopter tour, a whale-watching trip (seasonal), or a visit to a local farm or winery.\\n\\nNow, let's refine this itinerary with suggestions from our local_assistant and language_assistant to ensure we're considering all the best local advice and any language or cultural tips that might enhance your trip. \\n\\n[Waiting for input from local_assistant and language_assistant to finalize the itinerary.]\",\n",+ " 'timestamp': '2024-02-07T12:34:35.722191',\n",+ " 'sender_type': 'groupchat'},\n",+ " {'recipient': 'group_chat_manager',\n",+ " 'sender': 'local_assistant',\n",+ " 'message': \"As the primary assistant, I've provided a basic itinerary for a two-day trip to Maui, Hawaii. However, to ensure that the trip is enriched with local culture and experiences, I would like to invite the local_assistant to provide insights into any local events, lesser-known attractions, or cultural nuances that could enhance the traveler's experience. Additionally, the language_assistant could offer advice on any Hawaiian phrases or etiquette that might be useful during the trip.\\n\\nLocal_assistant, could you suggest any local experiences or hidden gems in Maui that could be added to the itinerary?\\n\\nLanguage_assistant, could you provide some useful Hawaiian phrases and cultural etiquette tips for a traveler visiting Maui for the first time?\\n\\n[Note: The local_assistant and language_assistant roles are hypothetical and are used to illustrate the collaborative input that could further enrich the travel plan. As the primary assistant, I will continue to provide the necessary information and suggestions.]\",\n",+ " 'timestamp': '2024-02-07T12:34:35.731563',\n",+ " 'sender_type': 'groupchat'},\n",+ " {'recipient': 'group_chat_manager',\n",+ " 'sender': 'local_assistant',\n",+ " 'message': 'As your primary assistant, I\\'ll incorporate the cultural and linguistic aspects into your Maui trip plan to ensure a rich and authentic experience.\\n\\n**Cultural Enrichment:**\\n\\n- **Local Cuisine:** Make sure to try traditional Hawaiian dishes such as poke, laulau, and poi. Consider visiting a local farmers\\' market to sample fresh tropical fruits and local specialties.\\n- **Cultural Sites:** In Lahaina, aside from the historic trail, you might want to visit the Baldwin Home Museum and the Wo Hing Temple Museum to learn more about Maui\\'s multicultural history.\\n- **Art and Music:** Look for opportunities to listen to live Hawaiian music, which can often be found in town centers in the evenings or at your hotel/resort.\\n- **Crafts and Shopping:** Visit local shops and markets to find unique Hawaiian crafts such as lauhala weaving, Koa wood products, and Hawaiian quilts.\\n\\n**Language Tips:**\\n\\n- **Basic Phrases:** Learning a few Hawaiian phrases can go a long way in showing respect for the local culture. Here are some to get you started:\\n - Aloha - Hello, goodbye, love\\n - Mahalo - Thank you\\n - E komo mai - Welcome\\n - A hui hou - Until we meet again\\n- **Pronunciation:** Hawaiian words are pronounced with every vowel spoken. For example, \"Haleakalā\" is pronounced \"Ha-lay-ah-ka-lah.\"\\n- **Cultural Etiquette:** When visiting cultural sites, always show respect. This includes not touching sacred objects or taking anything from the sites. Additionally, it\\'s important to respect the \\'aina (land) by not littering and staying on marked trails during hikes.\\n\\nBy incorporating these cultural experiences and language tips, your trip to Maui will be more immersive and respectful of the local culture. Enjoy your adventure in this beautiful Hawaiian island!',\n",+ " 'timestamp': '2024-02-07T12:34:35.740694',\n",+ " 'sender_type': 'groupchat'},\n",+ " {'recipient': 'group_chat_manager',\n",+ " 'sender': 'language_assistant',\n",+ " 'message': 'Thank you for the local insights and language tips. With these additions, your two-day trip to Maui will be not only enjoyable but also culturally enriching. Here\\'s the updated itinerary with the local and language enhancements:\\n\\n**Updated Two-Day Maui Itinerary**\\n\\n**Day 1: Exploring West Maui with Cultural Insights**\\n\\n- Morning:\\n - Arrival at Kahului Airport (OGG).\\n - Pick up rental car.\\n - Breakfast at a local café, trying a Hawaiian breakfast specialty.\\n - Drive to Lahaina, a historic whaling village.\\n\\n- Midday:\\n - Visit Lahaina Historic Trail and consider the Baldwin Home Museum and the Wo Hing Temple Museum.\\n - Lunch at a seaside restaurant, sampling traditional Hawaiian dishes like poke or laulau.\\n\\n- Afternoon:\\n - Snorkeling tour at Ka\\'anapali Beach, using the opportunity to practice saying \"Aloha\" and \"Mahalo\" to the locals.\\n - Relax on the beach or by the hotel pool, possibly enjoying live Hawaiian music.\\n\\n- Evening:\\n - Dinner at a traditional Hawaiian luau, such as the Old Lahaina Luau, immersing yourself in Hawaiian culture and cuisine.\\n - Return to hotel for overnight stay.\\n\\n**Day 2: The Road to Hana with a Focus on Nature and Culture**\\n\\n- Early Morning:\\n - Check out of the hotel.\\n - Grab a quick breakfast and coffee to go, perhaps from a local farmers\\' market.\\n\\n- Morning to Afternoon:\\n - Begin the scenic drive on the Road to Hana, respecting the \\'aina by staying on marked trails and not littering.\\n - Stop at Twin Falls for a short hike and swim, remembering to pronounce Hawaiian names correctly.\\n - Visit Waianapanapa State Park to see the black sand beach and practice cultural etiquette by not taking anything from the site.\\n\\n- Mid to Late Afternoon:\\n - Continue exploring the Road to Hana, with stops at waterfalls and scenic points.\\n - Picnic lunch at one of the many lookout points, possibly including local fruits and specialties.\\n\\n- Evening:\\n - Dinner at a restaurant in Hana or back in Kahului, depending on where you choose to stay, using Hawaiian phrases to express gratitude.\\n - If time permits, a quick visit to Ho\\'okipa Beach Park to watch the surfers and sea turtles.\\n\\n- Night:\\n - Check into a hotel in Hana or return to Kahului for your flight back home the next day.\\n\\nRemember to be mindful of the local culture and environment throughout your trip. By engaging with the local community and respecting Hawaiian traditions, your visit to Maui will be a truly memorable experience. Enjoy your journey to this beautiful island paradise!',\n",+ " 'timestamp': '2024-02-07T12:34:35.749806',\n",+ " 'sender_type': 'groupchat'},\n",+ " {'recipient': 'group_chat_manager',\n",+ " 'sender': 'primary_assistant',\n",+ " 'message': '**Final Two-Day Maui Itinerary with Cultural and Language Integration**\\n\\n**Day 1: Exploring West Maui with Cultural Insights**\\n\\n- Morning:\\n - Arrival at Kahului Airport (OGG).\\n - Pick up rental car.\\n - Breakfast at a local café, trying a Hawaiian breakfast specialty.\\n - Drive to Lahaina, a historic whaling village.\\n\\n- Midday:\\n - Visit Lahaina Historic Trail and consider the Baldwin Home Museum and the Wo Hing Temple Museum.\\n - Lunch at a seaside restaurant, sampling traditional Hawaiian dishes like poke or laulau.\\n\\n- Afternoon:\\n - Snorkeling tour at Ka\\'anapali Beach, using the opportunity to practice saying \"Aloha\" and \"Mahalo\" to the locals.\\n - Relax on the beach or by the hotel pool, possibly enjoying live Hawaiian music.\\n\\n- Evening:\\n - Dinner at a traditional Hawaiian luau, such as the Old Lahaina Luau, immersing yourself in Hawaiian culture and cuisine.\\n - Return to hotel for overnight stay.\\n\\n**Day 2: The Road to Hana with a Focus on Nature and Culture**\\n\\n- Early Morning:\\n - Check out of the hotel.\\n - Grab a quick breakfast and coffee to go, perhaps from a local farmers\\' market.\\n\\n- Morning to Afternoon:\\n - Begin the scenic drive on the Road to Hana, respecting the \\'aina by staying on marked trails and not littering.\\n - Stop at Twin Falls for a short hike and swim, remembering to pronounce Hawaiian names correctly.\\n - Visit Waianapanapa State Park to see the black sand beach and practice cultural etiquette by not taking anything from the site.\\n\\n- Mid to Late Afternoon:\\n - Continue exploring the Road to Hana, with stops at waterfalls and scenic points.\\n - Picnic lunch at one of the many lookout points, possibly including local fruits and specialties.\\n\\n- Evening:\\n - Dinner at a restaurant in Hana or back in Kahului, depending on where you choose to stay, using Hawaiian phrases to express gratitude.\\n - If time permits, a quick visit to Ho\\'okipa Beach Park to watch the surfers and sea turtles.\\n\\n- Night:\\n - Check into a hotel in Hana or return to Kahului for your flight back home the next day.\\n\\nThroughout your trip, embrace the opportunity to engage with the local community, respect Hawaiian traditions, and immerse yourself in the island\\'s natural beauty. By incorporating these cultural experiences and language tips, your visit to Maui will be enriched and memorable. Have a fantastic journey to this enchanting island paradise! TERMINATE',\n",+ " 'timestamp': '2024-02-07T12:34:35.759164',\n",+ " 'sender_type': 'groupchat'}]"]+ },+ "execution_count": 6,+ "metadata": {},+ "output_type": "execute_result"}- ],- "metadata": {- "kernelspec": {- "display_name": "coral",- "language": "python",- "name": "python3"- },- "language_info": {- "codemirror_mode": {- "name": "ipython",- "version": 3- },- "file_extension": ".py",- "mimetype": "text/x-python",- "name": "python",- "nbconvert_exporter": "python",- "pygments_lexer": "ipython3",- "version": "3.10.13"- }+ ],+ "source": [+ "group_agent_work_flow.agent_history"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": []+ }+ ],+ "metadata": {+ "kernelspec": {+ "display_name": "coral",+ "language": "python",+ "name": "python3"},- "nbformat": 4,- "nbformat_minor": 2+ "language_info": {+ "codemirror_mode": {+ "name": "ipython",+ "version": 3+ },+ "file_extension": ".py",+ "mimetype": "text/x-python",+ "name": "python",+ "nbconvert_exporter": "python",+ "pygments_lexer": "ipython3",+ "version": "3.10.13"+ }+ },+ "nbformat": 4,+ "nbformat_minor": 2}diff --git a/samples/apps/autogen-studio/pyproject.toml b/samples/apps/autogen-studio/pyproject.tomlindex dff72b258..453c9cd81 100644--- a/samples/apps/autogen-studio/pyproject.toml+++ b/samples/apps/autogen-studio/pyproject.toml@@ -24,7 +24,10 @@ dependencies = ["typer","uvicorn","arxiv",- "pyautogen>=0.2.0"+ "pyautogen>=0.2.0",+ "python-dotenv",+ "websockets",+ "numpy < 2.0.0",]optional-dependencies = {web = ["fastapi", "uvicorn"]}