🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
feat:add mock website (#2538)
Puzhen Zhang9a59aa52f3a2
diff --git a/camel/benchmarks/mock_website/README.md b/camel/benchmarks/mock_website/README.mdnew file mode 100644index 000000000..fe4433644--- /dev/null+++ b/camel/benchmarks/mock_website/README.md@@ -0,0 +1,96 @@+# Mock Website Benchmarks for Web Agent Testing++This project provides a framework for testing web agents against various mock websites. It features a central dispatcher (`mock_web.py`) that manages different test environments, each simulating a specific type of website (e.g., an e-commerce site). The initial example project is an Amazon-like shopping website.++## Core Concepts++* **Dispatcher (`mock_web.py`):** The single entry point for running any benchmark. It handles:+ * Downloading necessary web assets (HTML templates, CSS, JS) for a specific project from Hugging Face (https://huggingface.co/datasets/camel-ai/mock_websites).+ * Reading the task configuration from `task.json`.+ * Launching the project's dedicated Flask web server as a background process.+ * Monitoring the server for task completion via API polling.+ * Reporting the final results (success status, number of operations) and shutting down the server.+* **Projects (e.g., `shopping_mall/`):** Each project is a self-contained Flask application representing a unique website.+* **Task Configuration (`task.json`):** A central JSON file that defines the environment and the goal for the agent.++## Example Project: `shopping_mall`++The included `shopping_mall` project simulates an e-commerce website with the following features:+* **Product Display:** View a list of products with images, descriptions, ratings, and prices.+* **Product Detail Pages:** Click on a product to see its dedicated detail page.+* **Shopping Cart:** Add products, view the cart, and manage its contents.+* **API-Driven:** The backend provides API endpoints for all state-changing actions.++## Setup and Usage++1. **Install Dependencies:**+ ```bash+ pip install -r requirements.txt+ ```+ This will install `Flask`, `huggingface-hub`, `requests`, and other necessary packages.++2. **Configure the Task:**+ Edit the `task.json` file to define the products available on the website and the agent's goal. The structure is as follows:+ ```json+ {+ "products": [+ {+ "id": 1,+ "name": "Gaming Laptop",+ "price": 1200,+ "image": "assets/img/products/laptop.jpg",+ "category": "Electronics",+ "rating": 4.5,+ "description": "High-performance gaming laptop with latest specs."+ }+ ],+ "ground_truth_cart": [+ {+ "id": 1,+ "quantity": 1+ }+ ]+ }+ ```+ * `products`: A list of all product objects available in the environment.+ * `ground_truth_cart`: A list of items that defines the target state of the shopping cart for the task to be considered complete.++3. **Running the Benchmark:**+ Use the `mock_web.py` dispatcher to run a project.+ ```bash+ python mock_web.py --project shopping_mall+ ```+ * `--project`: Specifies which mock website project to run (default: `shopping_mall`).+ * `--port`: Specifies the port to run the server on (default: `5001`).++ The dispatcher will start the server and begin polling for task completion. You or your agent can then interact with the website at `http://127.0.0.1:5001/`. Once the conditions defined in `ground_truth_cart` are met, the dispatcher will automatically detect it, report the results, and shut down. You can also stop it early by pressing `Ctrl+C`.++## Logging++* `dispatcher.log`: High-level log from the dispatcher, showing setup, status, and final results.+* `shopping_mall/app.log`: Detailed internal log from the Flask application for the `shopping_mall` project.++## Project Structure++```+.+├── mock_web.py # Main dispatcher for running benchmarks+├── task.json # Task configuration file+├── requirements.txt # Python dependencies+├── shopping_mall/ # Example project: shopping_mall+│ └── app.py # Flask application for this project+├── dispatcher.log # (Generated at runtime)+└── README.md # This file+```+The dispatcher will automatically download project-specific `templates` and `static` folders from Hugging Face Hub and place them inside the corresponding project directory at runtime.++## TODO: Automated Question Generation Module++A planned future module for this project is the development of an automated question generation system. This system would analyze the current state of the web application environment (e.g., visible elements, available products, cart status) and generate relevant questions or tasks for a web agent to solve.++This could involve:+* Identifying interactable elements and their states.+* Understanding the current context (e.g., on product page, in cart).+* Formulating natural language questions or goal descriptions based on this context (e.g., "Find a product under $50 in the Electronics category and add it to the cart," or "What is the current subtotal of the cart after adding two units of item X?").++diff --git a/camel/benchmarks/mock_website/mock_web.py b/camel/benchmarks/mock_website/mock_web.pynew file mode 100644index 000000000..347aa1e43--- /dev/null+++ b/camel/benchmarks/mock_website/mock_web.py@@ -0,0 +1,299 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+import argparse+import json+import logging+import os+import shutil+import subprocess+import sys+import time+from logging.handlers import RotatingFileHandler+from queue import Empty, Queue+from threading import Thread++import requests+++def setup_dispatcher_logging():+ log_formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')+ log_file = 'dispatcher.log'++ logger = logging.getLogger('dispatcher')+ logger.setLevel(logging.INFO)++ # File Handler+ file_handler = RotatingFileHandler(+ log_file, maxBytes=1024 * 1024 * 5, backupCount=2+ )+ file_handler.setFormatter(log_formatter)+ logger.addHandler(file_handler)++ # Stream Handler (for console output)+ stream_handler = logging.StreamHandler(sys.stdout)+ stream_handler.setFormatter(log_formatter)+ logger.addHandler(stream_handler)++ return logger+++log = setup_dispatcher_logging()+++def download_website_assets(project_name: str):+ log.info(f"Checking for assets for project: {project_name}")++ # Check if assets already exist+ project_dir = project_name+ templates_path = os.path.join(project_dir, 'templates')+ static_path = os.path.join(project_dir, 'static')+ if os.path.exists(templates_path) and os.path.exists(static_path):+ log.info(+ "Templates and static folders already exist. Skipping download."+ )+ return True++ log.info(f"Attempting to download assets for project: {project_name}")+ try:+ from huggingface_hub import snapshot_download+ except ImportError:+ log.error(+ "huggingface_hub not installed. "+ "Please install it with `pip install huggingface-hub`"+ )+ return False++ repo_id = "camel-ai/mock_websites"+ local_dir_root = "hf_mock_website"+ project_pattern = f"{project_name}/*"++ try:+ # Download only the project's folder+ snapshot_path = snapshot_download(+ repo_id=repo_id,+ repo_type="dataset",+ allow_patterns=project_pattern,+ local_dir=local_dir_root,+ local_dir_use_symlinks=False,+ # Use False for Windows compatibility+ )+ log.info(f"Snapshot downloaded to: {snapshot_path}")++ # The downloaded content for the project is in a subdirectory+ project_assets_path = os.path.join(snapshot_path, project_name)++ if not os.path.isdir(project_assets_path):+ log.error(+ f"Project folder '{project_name}' not found in downloaded "+ f"assets at '{project_assets_path}'"+ )+ return False++ # Copy templates and static folders into project root+ for folder in ['templates', 'static']:+ src = os.path.join(project_assets_path, folder)+ # Destination is now inside the project folder+ dst = os.path.join(".", project_name, folder)+ if not os.path.exists(src):+ log.warning(f"'{src}' not found in downloaded assets.")+ continue++ if os.path.exists(dst):+ log.info(f"Removing existing '{dst}' directory.")+ shutil.rmtree(dst)+ log.info(f"Copying '{src}' to '{dst}'.")+ shutil.copytree(src, dst)+ log.info(f"Assets for '{project_name}' are set up.")+ return True+ except Exception as e:+ log.error(f"Failed to download or set up assets: {e}")+ return False+++def enqueue_output(stream, queue):+ # If `stream` is from a subprocess opened with `text=True`,+ # then `readline()` returns strings, and `''` is the sentinel for EOF.+ for line in iter(stream.readline, ''):+ queue.put(line)+ stream.close()+++def run_project(project_name: str, port: int):+ # 1. Prepare environment+ log.info(f"Setting up project: {project_name}")+ if not download_website_assets(project_name):+ log.error("Failed to download assets. Aborting.")+ return++ # Load task configuration+ task_file = 'task.json'+ if not os.path.exists(task_file):+ log.error(f"'{task_file}' not found. Aborting.")+ return+ with open(task_file, 'r') as f:+ task_data = json.load(f)+ products = task_data.get("products", [])+ ground_truth = task_data.get("ground_truth_cart", [])++ # Prepare project-specific files+ project_dir = project_name+ app_path = os.path.join(project_dir, 'app.py')+ if not os.path.exists(app_path):+ log.error(f"Application file not found: {app_path}. Aborting.")+ return++ # Write the products to a file inside the project directory+ with open(os.path.join(project_dir, 'products.json'), 'w') as f:+ json.dump(products, f)+ log.info(f"Wrote products.json to '{project_dir}'.")++ # Start the web server app+ # Use sys.executable to ensure we use the same python interpreter+ cmd = [sys.executable, app_path, '--port', str(port)]+ process = subprocess.Popen(+ cmd,+ stdout=subprocess.PIPE,+ stderr=subprocess.PIPE,+ text=True,+ bufsize=1,+ universal_newlines=True,+ )+ log.info(f"Started {app_path} on port {port} with PID: {process.pid}")++ # Non-blocking stream reading for both stdout and stderr+ q_out: Queue[str] = Queue()+ t_out = Thread(target=enqueue_output, args=(process.stdout, q_out))+ t_out.daemon = True+ t_out.start()++ q_err: Queue[str] = Queue()+ t_err = Thread(target=enqueue_output, args=(process.stderr, q_err))+ t_err.daemon = True+ t_err.start()++ time.sleep(5) # Wait for server to start++ # 5. Start the task and then wait for user to terminate+ base_url = f"http://127.0.0.1:{port}"+ try:+ # Start task+ log.info(f"Starting task with ground truth: {ground_truth}")+ r = requests.post(+ f"{base_url}/task/start", json={"ground_truth_cart": ground_truth}+ )+ r.raise_for_status()+ log.info(f"Task started on server: {r.json()['message']}")+ print(+ "Server is running. Interact with the website at "+ f"http://127.0.0.1:{port}"+ )+ print("Dispatcher is now polling for task completion...")+ print("Press Ctrl+C to stop the dispatcher early and get results.")++ # Poll for task completion+ while True:+ # Check if the subprocess has terminated unexpectedly+ if process.poll() is not None:+ log.error("App process terminated unexpectedly.")+ break++ # Check for completion via API+ try:+ r_check = requests.get(f"{base_url}/task/check")+ r_check.raise_for_status()+ status = r_check.json()+ if status.get('completed', False):+ log.info(+ "Task completion reported by API. "+ "Proceeding to final report and shutdown."+ )+ break # Exit the loop on completion+ except requests.exceptions.RequestException as e:+ log.error(f"Could not poll task status: {e}")+ break # Exit if the server becomes unresponsive++ # Log any error output from the app+ try:+ err_line = q_err.get_nowait()+ log.error(f"APP STDERR: {err_line.strip()}")+ except Empty:+ pass # No new error output+ time.sleep(2) # Wait for 2 seconds before polling again++ except KeyboardInterrupt:+ log.info(+ "\nCtrl+C detected. Shutting down and checking final task status."+ )++ except requests.exceptions.RequestException as e:+ log.error(f"Failed to communicate with the web app: {e}")+ finally:+ # 6. Check task completion+ log.info("Checking final task completion status.")+ op_steps = 0+ try:+ r = requests.get(f"{base_url}/task/check")+ r.raise_for_status()+ result = r.json()+ log.info(f"Final task check result: {result}")+ success = result.get('completed', False)+ op_steps = result.get('steps', 0)+ except requests.exceptions.RequestException as e:+ log.error(f"Could not get final task status: {e}")+ success = False++ log.info("--- FINAL FEEDBACK ---")+ log.info(f"Project: {project_name}")+ log.info(f"Success: {success}")+ log.info(f"Total Operation Steps: {op_steps}")+ log.info("----------------------")++ # 7. Shutdown server+ log.info("Shutting down web server.")+ process.terminate()+ try:+ process.wait(timeout=5)+ except subprocess.TimeoutExpired:+ log.warning("Server did not terminate gracefully. Killing.")+ process.kill()+ log.info("Web server process stopped.")+ # Log any remaining stderr for debugging+ # Drain the queue first+ while not q_err.empty():+ log.error(f"APP STDERR: {q_err.get_nowait().strip()}")+++def main():+ parser = argparse.ArgumentParser(+ description="Dispatcher for running mock website benchmarks."+ )+ parser.add_argument(+ '--project',+ type=str,+ default='shopping_mall',+ help='The name of the project to run (e.g., shopping_mall).',+ )+ parser.add_argument(+ '--port',+ type=int,+ default=5001,+ help='Port to run the project web server on.',+ )+ args = parser.parse_args()++ run_project(args.project, args.port)+++if __name__ == "__main__":+ main()diff --git a/camel/benchmarks/mock_website/requirements.txt b/camel/benchmarks/mock_website/requirements.txtnew file mode 100644index 000000000..812033fc3--- /dev/null+++ b/camel/benchmarks/mock_website/requirements.txt@@ -0,0 +1,3 @@+Flask>=2.0+huggingface-hub+requests\ No newline at end of filediff --git a/camel/benchmarks/mock_website/shopping_mall/app.py b/camel/benchmarks/mock_website/shopping_mall/app.pynew file mode 100644index 000000000..52cc58715--- /dev/null+++ b/camel/benchmarks/mock_website/shopping_mall/app.py@@ -0,0 +1,465 @@+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========+import argparse+import json+import logging+import os+import sys # Import the sys module+from logging.handlers import RotatingFileHandler+from typing import Any, Dict, List++app = None+products: List[Dict[str, Any]] = []+products_by_id: Dict[int, Dict[str, Any]] = {}+cart: List[Dict[str, Any]] = []+ACTION_COUNT: int = 0+++def load_products(file_path: str = 'products.json') -> None:+ global products, products_by_id+ try:+ # The products.json is expected to be+ # in the same directory as this app.py+ # or given by mock_web.py+ script_dir = os.path.dirname(__file__)+ abs_file_path = os.path.join(script_dir, file_path)+ with open(abs_file_path, 'r') as f:+ products = json.load(f)+ products_by_id = {product['id']: product for product in products}+ except FileNotFoundError:+ sys.stderr.write(f"Error: {file_path} not found.\n")+ products = []+ products_by_id = {}+ except json.JSONDecodeError:+ sys.stderr.write(f"Error: Could not decode JSON from {file_path}.\n")+ products = []+ products_by_id = {}+++# --- Logging Setup ---+def setup_logging(application):+ log_formatter = logging.Formatter(+ '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'+ )+ # Log to a file in the same directory as this script+ script_dir = os.path.dirname(__file__)+ log_file = os.path.join(script_dir, 'app.log')++ # File Handler+ file_handler = RotatingFileHandler(+ log_file, maxBytes=1024 * 1024 * 10, backupCount=5+ ) # 10MB per file, 5 backups+ file_handler.setFormatter(log_formatter)+ file_handler.setLevel(logging.INFO)++ # Stream Handler (for console output)+ stream_handler = logging.StreamHandler(+ sys.stdout+ ) # Explicitly set to stdout+ stream_handler.setFormatter(log_formatter)+ stream_handler.setLevel(logging.INFO)++ application.logger.addHandler(file_handler)+ application.logger.addHandler(stream_handler)+ application.logger.setLevel(logging.INFO)+ application.logger.info(+ f"Logging setup complete. Logs will be saved to {log_file}"+ )+++# --- End Logging Setup ---+++# --- Task Mode Helper ---+def check_task_completion(current_cart_raw, ground_truth_spec):+ if not ground_truth_spec: # No ground truth defined+ return False++ # Group current cart by product ID and count quantity+ current_cart_grouped = {}+ for item in current_cart_raw:+ pid = item['id']+ current_cart_grouped[pid] = current_cart_grouped.get(pid, 0) + 1++ # Convert ground truth spec to a comparable dictionary {product_id:+ # quantity}+ ground_truth_dict = {}+ for item_spec in ground_truth_spec:+ ground_truth_dict[item_spec['id']] = item_spec['quantity']++ # Check if current cart exactly matches ground truth+ # 1. Same number of unique product types+ if len(current_cart_grouped) != len(ground_truth_dict):+ return False++ # 2. Each product in current cart matches ground truth quantity, and all+ # ground truth items are present+ for pid, qty_spec in ground_truth_dict.items():+ if (+ pid not in current_cart_grouped+ or current_cart_grouped[pid] != qty_spec+ ):+ return False++ # Ensure no extra items in current_cart_grouped that are not in+ # ground_truth_dict (already covered by length check if all ground truth+ # items are found)+ # For robustness, explicitly check this too:+ for pid_current in current_cart_grouped.keys():+ if pid_current not in ground_truth_dict:+ return False++ return True+++# --- End Task Mode Helper ---+++# --- Task Completion Helper ---+def _trigger_task_completion_check():+ r"""Checks for task completion if in task mode and not already signaled."""+ # Uses global `app` and `cart`+ if app.config.get('TASK_ACTIVE') and not app.config.get(+ 'TASK_COMPLETION_SIGNALED'+ ):+ if check_task_completion(cart, app.config.get('GROUND_TRUTH_CART')):+ app.config['TASK_COMPLETION_SIGNALED'] = True+ app.logger.info(+ "TASK COMPLETED: Ground truth cart state achieved."+ )+++# --- End Task Completion Helper ---+def create_app():+ global app+ try:+ from flask import Flask, jsonify, render_template, request+ except ImportError:+ raise ImportError(+ "Flask not installed. Please install it with `pip install Flask`"+ )++ # Adjust template and static folder paths+ script_dir = os.path.dirname(os.path.abspath(__file__))+ app = Flask(+ __name__,+ template_folder=os.path.join(script_dir, 'templates'),+ static_folder=os.path.join(script_dir, 'static'),+ )+ setup_logging(app)++ # --- Global Task Config ---+ app.config['TASK_ACTIVE'] = False+ app.config['GROUND_TRUTH_CART'] = []+ app.config['TASK_COMPLETION_SIGNALED'] = False++ @app.route('/')+ def home():+ global ACTION_COUNT+ ACTION_COUNT += 1+ unique_categories = sorted({p["category"] for p in products})+ products_by_category = {}+ for product in products:+ category = product["category"]+ if category not in products_by_category:+ products_by_category[category] = []+ products_by_category[category].append(product)++ app.logger.info(+ "Home page requested. "+ f"Categories: {unique_categories}. Cart count: {len(cart)}"+ )+ # Pass products_by_category to the template instead of the flat+ # products list for main display+ return render_template(+ 'index.html',+ products_by_category=products_by_category,+ categories=unique_categories,+ cart_count=len(cart),+ all_products=products,+ )++ @app.route('/product/<int:product_id>')+ def product_detail(product_id):+ global ACTION_COUNT+ ACTION_COUNT += 1+ product = products_by_id.get(product_id)+ app.logger.info(+ f"Product detail page requested for ID: {product_id}. "+ f"Cart count: {len(cart)}"+ )+ if product:+ return render_template(+ 'product-detail.html', product=product, cart_count=len(cart)+ )+ return "Product not found", 404++ @app.route('/cart')+ def view_cart():+ global ACTION_COUNT+ ACTION_COUNT += 1+ total_price = sum(+ item['price'] * item.get('quantity', 1) for item in cart+ )+ app.logger.info(f"Cart page requested. Cart count: {len(cart)}")+ return render_template(+ 'cart.html', cart_items=cart, total_price=total_price+ )++ @app.route('/api/products')+ def get_products():+ return jsonify(products)++ @app.route('/api/cart', methods=['GET'])+ def get_cart_api():+ total_price = sum(+ item['price'] * item.get('quantity', 1) for item in cart+ )+ return jsonify({'cart': cart, 'total_price': total_price})++ @app.route('/api/cart/add', methods=['POST'])+ def add_to_cart_api():+ global ACTION_COUNT+ data = request.json+ product_id = data.get('productId')++ if not product_id:+ return jsonify(+ {'success': False, 'message': 'Product ID is required'}+ ), 400++ product = products_by_id.get(product_id)+ if not product:+ return jsonify(+ {'success': False, 'message': 'Product not found'}+ ), 404++ # Check if product is already in cart+ for item in cart:+ if item['id'] == product_id:+ # If yes, just increment quantity+ item.get('quantity', 1)+ item['quantity'] = item.get('quantity', 1) + 1+ app.logger.info(+ f"Incremented quantity for product {product_id} in cart."+ )+ return jsonify(+ {'success': True, 'cart': cart, 'cart_count': len(cart)}+ )++ # If not, add new item to cart+ cart_item = product.copy()+ cart_item['quantity'] = 1 # Start with quantity 1+ cart.append(cart_item)+ ACTION_COUNT += 1 # Increment on successful add++ _trigger_task_completion_check()++ app.logger.info(f"Added product {product_id} to cart.")+ return jsonify(+ {'success': True, 'cart': cart, 'cart_count': len(cart)}+ )++ @app.route('/api/cart/update', methods=['POST'])+ def update_cart_item_api():+ data = request.json+ product_id = data.get('productId')+ quantity = data.get('quantity')++ if not product_id:+ return jsonify(+ {'success': False, 'message': 'Product ID is required'}+ ), 400++ try:+ # Ensure quantity is a non-negative integer+ quantity = int(quantity)+ if quantity < 0:+ raise ValueError+ except (ValueError, TypeError):+ return jsonify(+ {'success': False, 'message': 'Invalid quantity'}+ ), 400++ found_item = False+ for item in cart:+ if item['id'] == product_id:+ if quantity > 0:+ item['quantity'] = quantity+ app.logger.info(+ "Updated quantity for product "+ f"{product_id} to {quantity}."+ )+ else:+ # If quantity is 0, remove the item+ cart.remove(item)+ app.logger.info(f"Removed product {product_id} from cart.")+ found_item = True+ break++ if not found_item:+ return jsonify(+ {'success': False, 'message': 'Product not in cart'}+ ), 404++ _trigger_task_completion_check()++ total_price = sum(+ item['price'] * item.get('quantity', 1) for item in cart+ )+ return jsonify(+ {+ 'success': True,+ 'cart': cart,+ 'cart_count': len(cart),+ 'total_price': total_price,+ }+ )++ @app.route('/api/cart/remove', methods=['POST'])+ def remove_from_cart_api():+ global cart, ACTION_COUNT+ data = request.json+ product_id = data.get('productId')++ if not product_id:+ return jsonify(+ {'success': False, 'message': 'Product ID is required'}+ ), 400++ original_cart_len = len(cart)+ # List comprehension to create a new list excluding the item to be+ # removed This is simpler than finding index and deleting+ cart[:] = [item for item in cart if item['id'] != product_id]++ if len(cart) < original_cart_len:+ ACTION_COUNT += 1 # Increment on successful remove+ app.logger.info(f"Removed product {product_id} from cart.")++ _trigger_task_completion_check()++ total_price = sum(+ item['price'] * item.get('quantity', 1) for item in cart+ )+ return jsonify(+ {+ 'success': True,+ 'cart': cart,+ 'cart_count': len(cart),+ 'total_price': total_price,+ }+ )++ return jsonify(+ {'success': False, 'message': 'Product not in cart'}+ ), 404++ @app.route('/task/start', methods=['POST'])+ def start_task():+ global cart, ACTION_COUNT+ ACTION_COUNT = 0 # Reset action counter+ data = request.json+ ground_truth = data.get('ground_truth_cart')++ if not isinstance(ground_truth, list):+ return jsonify(+ {+ 'success': False,+ 'message': '`ground_truth_cart` must be a list.',+ }+ ), 400++ # Validate ground truth spec+ for item_spec in ground_truth:+ if not all(k in item_spec for k in ['id', 'quantity']):+ return jsonify(+ {+ 'success': False,+ 'message': (+ 'Each item in `ground_truth_cart` must have '+ '`id` and `quantity`.'+ ),+ }+ ), 400++ app.config['TASK_ACTIVE'] = True+ app.config['GROUND_TRUTH_CART'] = ground_truth+ app.config['TASK_COMPLETION_SIGNALED'] = False # Reset signal+ cart = [] # Reset cart+ app.logger.info(f"TASK MODE STARTED. Ground truth: {ground_truth}")+ return jsonify(+ {'success': True, 'message': 'Task mode started. Cart reset.'}+ )++ @app.route('/task/check', methods=['GET'])+ def check_task():+ global ACTION_COUNT+ if not app.config.get('TASK_ACTIVE'):+ return jsonify(+ {'success': False, 'message': 'Task mode is not active.'}+ ), 400++ completed = app.config.get('TASK_COMPLETION_SIGNALED', False)+ if completed:+ message = "Task completed successfully."+ else:+ message = "Task not yet completed."++ return jsonify(+ {+ 'success': True,+ 'completed': completed,+ 'steps': ACTION_COUNT,+ 'message': message,+ }+ )++ @app.route('/task/stop', methods=['POST'])+ def stop_task():+ global cart+ app.config['TASK_ACTIVE'] = False+ app.config['GROUND_TRUTH_CART'] = []+ app.config['TASK_COMPLETION_SIGNALED'] = False+ cart = [] # Reset cart+ app.logger.info("TASK MODE STOPPED. Cart reset.")+ return jsonify(+ {'success': True, 'message': 'Task mode stopped. Cart reset.'}+ )++ return app+++def main():+ parser = argparse.ArgumentParser(+ description="Run the mock website server."+ )+ parser.add_argument(+ '--port', type=int, default=5000, help='Port to run the server on.'+ )+ args = parser.parse_args()++ # Load products specific to this app+ load_products()+ flask_app = create_app()++ if flask_app:+ # Use 0.0.0.0 to make it accessible from the dispatcher+ # Disable the reloader to prevent state loss on logging+ flask_app.run(+ debug=True, port=args.port, host='0.0.0.0', use_reloader=False+ )+++if __name__ == "__main__":+ main()diff --git a/camel/benchmarks/mock_website/task.json b/camel/benchmarks/mock_website/task.jsonnew file mode 100644index 000000000..ef652493b--- /dev/null+++ b/camel/benchmarks/mock_website/task.json@@ -0,0 +1,104 @@+{+ "products": [+ {+ "id": 1,+ "name": "Gaming Laptop",+ "price": 1200,+ "image": "assets/img/products/laptop.jpg",+ "category": "Electronics",+ "rating": 4.5,+ "description": "High-performance gaming laptop with latest specs."+ },+ {+ "id": 2,+ "name": "Wireless Mouse",+ "price": 25,+ "image": "assets/img/products/mouse.jpg",+ "category": "Electronics",+ "rating": 4.0,+ "description": "Ergonomic wireless mouse with long battery life."+ },+ {+ "id": 3,+ "name": "Mechanical Keyboard",+ "price": 75,+ "image": "assets/img/products/keyboard.jpg",+ "category": "Electronics",+ "rating": 4.8,+ "description": "RGB mechanical keyboard with customizable keys."+ },+ {+ "id": 4,+ "name": "Coffee Maker",+ "price": 50,+ "image": "assets/img/products/coffeemaker.jpg",+ "category": "Home Goods",+ "rating": 3.9,+ "description": "Drip coffee maker with programmable timer."+ },+ {+ "id": 5,+ "name": "Bluetooth Speaker",+ "price": 45,+ "image": "assets/img/products/speaker.jpg",+ "category": "Electronics",+ "rating": 4.2,+ "description": "Portable Bluetooth speaker with rich sound."+ },+ {+ "id": 6,+ "name": "Smartphone",+ "price": 699,+ "image": "assets/img/products/smartphone.jpg",+ "category": "Electronics",+ "rating": 4.6,+ "description": "Latest-gen smartphone with stunning display and fast performance."+ },+ {+ "id": 7,+ "name": "Air Purifier",+ "price": 130,+ "image": "assets/img/products/airpurifier.jpg",+ "category": "Home Goods",+ "rating": 4.3,+ "description": "HEPA air purifier with quiet operation and multiple fan speeds."+ },+ {+ "id": 8,+ "name": "Fitness Tracker",+ "price": 85,+ "image": "assets/img/products/fitnesstracker.jpg",+ "category": "Electronics",+ "rating": 4.1,+ "description": "Waterproof fitness tracker with heart rate and sleep monitoring."+ },+ {+ "id": 9,+ "name": "Electric Kettle",+ "price": 35,+ "image": "assets/img/products/kettle.jpg",+ "category": "Home Goods",+ "rating": 4.0,+ "description": "Stainless steel electric kettle with auto shut-off feature."+ },+ {+ "id": 10,+ "name": "Noise Cancelling Headphones",+ "price": 150,+ "image": "assets/img/products/headphones.jpg",+ "category": "Electronics",+ "rating": 4.7,+ "description": "Over-ear headphones with active noise cancellation and long battery life."+ }+ ],+ "ground_truth_cart": [+ {+ "id": 1,+ "quantity": 1+ },+ {+ "id": 2,+ "quantity": 1+ }+ ]+}\ No newline at end of filediff --git a/docs/mintlify/docs.json b/docs/mintlify/docs.jsonindex 95c317a9f..07bde3232 100644--- a/docs/mintlify/docs.json+++ b/docs/mintlify/docs.json@@ -584,7 +584,8 @@"reference/camel.benchmarks.browsecomp","reference/camel.benchmarks.gaia","reference/camel.benchmarks.nexus",- "reference/camel.benchmarks.ragbench"+ "reference/camel.benchmarks.ragbench",+ "reference/camel.benchmarks.mock_website.app"]},{diff --git a/docs/mintlify/reference/camel.benchmarks.mock_website.app.mdx b/docs/mintlify/reference/camel.benchmarks.mock_website.app.mdxnew file mode 100644index 000000000..aef493eff--- /dev/null+++ b/docs/mintlify/reference/camel.benchmarks.mock_website.app.mdx@@ -0,0 +1,81 @@+<a id="camel.benchmarks.mock_website.app"></a>++<a id="camel.benchmarks.mock_website.app.setup_logging"></a>++## setup_logging++```python+def setup_logging(application):+```++<a id="camel.benchmarks.mock_website.app.check_task_completion"></a>++## check_task_completion++```python+def check_task_completion(current_cart_raw, ground_truth_spec):+```++<a id="camel.benchmarks.mock_website.app.home"></a>++## home++```python+def home():+```++<a id="camel.benchmarks.mock_website.app.product_detail"></a>++## product_detail++```python+def product_detail(product_id):+```++<a id="camel.benchmarks.mock_website.app.view_cart"></a>++## view_cart++```python+def view_cart():+```++<a id="camel.benchmarks.mock_website.app.get_products"></a>++## get_products++```python+def get_products():+```++<a id="camel.benchmarks.mock_website.app.get_cart_api"></a>++## get_cart_api++```python+def get_cart_api():+```++<a id="camel.benchmarks.mock_website.app.add_to_cart_api"></a>++## add_to_cart_api++```python+def add_to_cart_api():+```++<a id="camel.benchmarks.mock_website.app.update_cart_item_api"></a>++## update_cart_item_api++```python+def update_cart_item_api():+```++<a id="camel.benchmarks.mock_website.app.remove_from_cart_api"></a>++## remove_from_cart_api++```python+def remove_from_cart_api():+```diff --git a/pyproject.toml b/pyproject.tomlindex adc051b09..01547e5d9 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -57,6 +57,7 @@ dev = ["types-requests>=2.31.0,<3","types-setuptools>=69.2.0,<70","uv==0.6.5",+ "Flask>=2.0",]docs = ["sphinx>=7,<8",@@ -195,6 +196,7 @@ huggingface = ["soundfile>=0.13,<0.14","sentencepiece>=0.2,<0.3","opencv-python>=4,<5",+ "huggingface-hub",]storage = ["qdrant-client>=1.9.0,<2",@@ -383,9 +385,10 @@ all = ["weaviate-client>=4.15.0","python-pptx>=1.0.2","langfuse>=2.60.5",-+ "Flask>=2.0",]+[project.urls]Homepage = "https://www.camel-ai.org/"Repository = "https://github.com/camel-ai/camel"diff --git a/uv.lock b/uv.lockindex f20585996..cc6906da3 100644--- a/uv.lock+++ b/uv.lock@@ -546,18 +546,27 @@ css = [{ name = "tinycss2" },]+[[package]]+name = "blinker"+version = "1.9.0"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/21/28/9b3f50ce0e048515135495f198351908d99540d69bfdc8c1d15b73dc55ce/blinker-1.9.0.tar.gz", hash = "sha256:b4ce2265a7abece45e7cc896e98dbebe6cead56bcf805a3d23136d145f5445bf", size = 22460 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/10/cb/f2ad4230dc2eb1a74edf38f1a38b9b52277f75bef262d8908e60d957e13c/blinker-1.9.0-py3-none-any.whl", hash = "sha256:ba0efaa9080b619ff2f3459d1d500c57bddea4a6b424b60a91141db6fd2f08bc", size = 8458 },+]+[[package]]name = "botocore"-version = "1.38.34"+version = "1.38.35"source = { registry = "https://pypi.org/simple" }dependencies = [{ name = "jmespath" },{ name = "python-dateutil" },{ name = "urllib3" },]-sdist = { url = "https://files.pythonhosted.org/packages/08/27/34dfe90dd51d16473985198e056b82d74afd355dc47daa10af2a4f117072/botocore-1.38.34.tar.gz", hash = "sha256:a105f4d941f329aa72c43ddf42371ec4bee50ab3619fc1ef35d0005520219612", size = 13953563 }+sdist = { url = "https://files.pythonhosted.org/packages/cd/2e/763918cd2b5af0345a38181bc5f16d1f6c32aad2a03b7738274cf068d864/botocore-1.38.35.tar.gz", hash = "sha256:3c7032948e066eed5f91d64cd51ee9664d1db9beaf3279ac27da608176bb3d54", size = 13962912 }wheels = [- { url = "https://files.pythonhosted.org/packages/c9/17/d9611cf624ec274ed83139cf4446f631dbbb51cbfe51336db7b27a724dd7/botocore-1.38.34-py3-none-any.whl", hash = "sha256:95ff2c4819498e94b321c9b5ac65d02267df93ff7ce7617323b19f19ea7cb545", size = 13614470 },+ { url = "https://files.pythonhosted.org/packages/97/89/b993928d3d4385b3698fd7a1fb251c117c76bc6cf8d5f3a587067f1298e3/botocore-1.38.35-py3-none-any.whl", hash = "sha256:bbfae3f13a5d75ad73bf71b5ba5ff3ccd055d947d63593e8a0e84acc95a8bfa4", size = 13623012 },][[package]]@@ -620,6 +629,7 @@ all = [{ name = "ffmpeg-python" },{ name = "firecrawl-py" },{ name = "fish-audio-sdk" },+ { name = "flask" },{ name = "fpdf" },{ name = "google-api-python-client" },{ name = "google-auth-httplib2" },@@ -734,6 +744,7 @@ data-tools = [{ name = "textblob" },]dev = [+ { name = "flask" },{ name = "gradio" },{ name = "mock" },{ name = "mypy" },@@ -797,6 +808,7 @@ huggingface = [{ name = "accelerate" },{ name = "datasets" },{ name = "diffusers" },+ { name = "huggingface-hub" },{ name = "opencv-python" },{ name = "sentencepiece" },{ name = "soundfile" },@@ -1023,6 +1035,8 @@ requires-dist = [{ name = "firecrawl-py", marker = "extra == 'web-tools'", specifier = ">=1.0.0,<2" },{ name = "fish-audio-sdk", marker = "extra == 'all'", specifier = ">=2024.12.5,<2025" },{ name = "fish-audio-sdk", marker = "extra == 'model-platforms'", specifier = ">=2024.12.5,<2025" },+ { name = "flask", marker = "extra == 'all'", specifier = ">=2.0" },+ { name = "flask", marker = "extra == 'dev'", specifier = ">=2.0" },{ name = "fpdf", marker = "extra == 'all'", specifier = ">=1.7.2" },{ name = "fpdf", marker = "extra == 'document-tools'", specifier = ">=1.7.2" },{ name = "fpdf", marker = "extra == 'owl'", specifier = ">=1.7.2" },@@ -1044,6 +1058,7 @@ requires-dist = [{ name = "html2text", marker = "extra == 'owl'", specifier = ">=2024.2.26" },{ name = "html2text", marker = "extra == 'web-tools'", specifier = ">=2024.2.26" },{ name = "httpx", specifier = ">=0.28.0,<1.0.0.dev0" },+ { name = "huggingface-hub", marker = "extra == 'huggingface'" },{ name = "ibm-watsonx-ai", marker = "extra == 'all'", specifier = ">=1.3.11" },{ name = "ibm-watsonx-ai", marker = "extra == 'model-platforms'", specifier = ">=1.3.11" },{ name = "imageio", extras = ["pyav"], marker = "extra == 'all'", specifier = ">=2.34.2,<3" },@@ -2324,6 +2339,23 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/b6/6d/b3f92e7a166ebb2033c41b45f5b5fdbc4282e680492eff38f72180bc0510/fish_audio_sdk-2024.12.5-py3-none-any.whl", hash = "sha256:a4ce81c6609c239d5518cc1d78c7a0699da50797e0af4d6b3758a8fb5c12384e", size = 7934 },]+[[package]]+name = "flask"+version = "3.1.1"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "blinker" },+ { name = "click" },+ { name = "itsdangerous" },+ { name = "jinja2" },+ { name = "markupsafe" },+ { name = "werkzeug" },+]+sdist = { url = "https://files.pythonhosted.org/packages/c0/de/e47735752347f4128bcf354e0da07ef311a78244eba9e3dc1d4a5ab21a98/flask-3.1.1.tar.gz", hash = "sha256:284c7b8f2f58cb737f0cf1c30fd7eaf0ccfcde196099d24ecede3fc2005aa59e", size = 753440 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/3d/68/9d4508e893976286d2ead7f8f571314af6c2037af34853a30fd769c02e9d/flask-3.1.1-py3-none-any.whl", hash = "sha256:07aae2bb5eaf77993ef57e357491839f5fd9f4dc281593a81a9e4d79a24f295c", size = 103305 },+]+[[package]]name = "flatbuffers"version = "25.2.10"@@ -2973,7 +3005,7 @@ wheels = [[[package]]name = "huggingface-hub"-version = "0.32.6"+version = "0.33.0"source = { registry = "https://pypi.org/simple" }dependencies = [{ name = "filelock" },@@ -2985,9 +3017,9 @@ dependencies = [{ name = "tqdm" },{ name = "typing-extensions" },]-sdist = { url = "https://files.pythonhosted.org/packages/8f/fb/7fcbafabdf470ffb5457b756cc1f659b4e88a9ff37c108e6c7a5ab5e781e/huggingface_hub-0.32.6.tar.gz", hash = "sha256:8e960f23dc57519c6c2a0bbc7e9bc030eaa14e7f2d61f8e68fd3d025dabed2fa", size = 424961 }+sdist = { url = "https://files.pythonhosted.org/packages/91/8a/1362d565fefabaa4185cf3ae842a98dbc5b35146f5694f7080f043a6952f/huggingface_hub-0.33.0.tar.gz", hash = "sha256:aa31f70d29439d00ff7a33837c03f1f9dd83971ce4e29ad664d63ffb17d3bb97", size = 426179 }wheels = [- { url = "https://files.pythonhosted.org/packages/c5/42/dd58e603c5b069c4e4759c7c44e4f5ccdc2ce02185848232775f5d6d5d50/huggingface_hub-0.32.6-py3-none-any.whl", hash = "sha256:32cde9558c965477556edca72352621def7fbc42e167aaf33f4cdb9af65bb28b", size = 512800 },+ { url = "https://files.pythonhosted.org/packages/33/fb/53587a89fbc00799e4179796f51b3ad713c5de6bb680b2becb6d37c94649/huggingface_hub-0.33.0-py3-none-any.whl", hash = "sha256:e8668875b40c68f9929150d99727d39e5ebb8a05a98e4191b908dc7ded9074b3", size = 514799 },][[package]]@@ -3241,6 +3273,15 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/15/aa/0aca39a37d3c7eb941ba736ede56d689e7be91cab5d9ca846bde3999eba6/isodate-0.7.2-py3-none-any.whl", hash = "sha256:28009937d8031054830160fce6d409ed342816b543597cece116d966c6d99e15", size = 22320 },]+[[package]]+name = "itsdangerous"+version = "2.2.0"+source = { registry = "https://pypi.org/simple" }+sdist = { url = "https://files.pythonhosted.org/packages/9c/cb/8ac0172223afbccb63986cc25049b154ecfb5e85932587206f42317be31d/itsdangerous-2.2.0.tar.gz", hash = "sha256:e0050c0b7da1eea53ffaf149c0cfbb5c6e2e2b69c4bef22c81fa6eb73e5f6173", size = 54410 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/04/96/92447566d16df59b2a776c0fb82dbc4d9e07cd95062562af01e408583fc4/itsdangerous-2.2.0-py3-none-any.whl", hash = "sha256:c6242fc49e35958c8b15141343aa660db5fc54d4f13a1db01a3f5891b98700ef", size = 16234 },+]+[[package]]name = "jaraco-context"version = "6.0.1"@@ -3931,7 +3972,7 @@ wheels = [[[package]]name = "mem0ai"-version = "0.1.106"+version = "0.1.107"source = { registry = "https://pypi.org/simple" }dependencies = [{ name = "openai" },@@ -3941,9 +3982,9 @@ dependencies = [{ name = "qdrant-client" },{ name = "sqlalchemy" },]-sdist = { url = "https://files.pythonhosted.org/packages/6e/f3/5a5bd30e452c79078ac4d85e567674089fc526d8e2e3c5d62414a91f835a/mem0ai-0.1.106.tar.gz", hash = "sha256:4a38195d7783e05d1f7a026c73440e58cd6391c282ca77221172acd3e3470c49", size = 100803 }+sdist = { url = "https://files.pythonhosted.org/packages/c6/6d/694ac84bd4530e2b92100efd11a805293c6b44b28ac75ec25340660ea3bc/mem0ai-0.1.107.tar.gz", hash = "sha256:b7bba7f68c44efa65c91082750c829e566fc5d06ebe8c70c2f1d5f31fe57164d", size = 101140 }wheels = [- { url = "https://files.pythonhosted.org/packages/66/29/3e44b620c915b7116e2685ade8f60311307b4b349249818d1e440b11bfad/mem0ai-0.1.106-py3-none-any.whl", hash = "sha256:65751efa4752959c1565526ae63a03829a1d5166410380bd9739e5dabadcf592", size = 156712 },+ { url = "https://files.pythonhosted.org/packages/46/f9/42e68a256cdaebc14258a576c14d2a3dc08b8d695b7c1016a1a276c807f2/mem0ai-0.1.107-py3-none-any.whl", hash = "sha256:986fd99db8a18d8549213e202f516a5a877bafbd6670050a03b4b82871cdfdb3", size = 157029 },][[package]]@@ -8114,6 +8155,18 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/fa/a8/5b41e0da817d64113292ab1f8247140aac61cbf6cfd085d6a0fa77f4984f/websockets-15.0.1-py3-none-any.whl", hash = "sha256:f7a866fbc1e97b5c617ee4116daaa09b722101d4a3c170c787450ba409f9736f", size = 169743 },]+[[package]]+name = "werkzeug"+version = "3.1.3"+source = { registry = "https://pypi.org/simple" }+dependencies = [+ { name = "markupsafe" },+]+sdist = { url = "https://files.pythonhosted.org/packages/9f/69/83029f1f6300c5fb2471d621ab06f6ec6b3324685a2ce0f9777fd4a8b71e/werkzeug-3.1.3.tar.gz", hash = "sha256:60723ce945c19328679790e3282cc758aa4a6040e4bb330f53d30fa546d44746", size = 806925 }+wheels = [+ { url = "https://files.pythonhosted.org/packages/52/24/ab44c871b0f07f491e5d2ad12c9bd7358e527510618cb1b803a88e986db1/werkzeug-3.1.3-py3-none-any.whl", hash = "sha256:54b78bf3716d19a65be4fceccc0d1d7b89e608834989dfae50ea87564639213e", size = 224498 },+]+[[package]]name = "wikipedia"version = "1.4.0"