### Launch Web UI Source: https://github.com/wecoai/aideml/blob/main/README.md Install the necessary dependencies and start the Streamlit-based web interface. ```bash pip install -U aideml # adds streamlit cd aide/webui streamlit run app.py ``` -------------------------------- ### Perform Development Install Source: https://github.com/wecoai/aideml/blob/main/README.md Clone the repository and install the package in editable mode for development. ```bash git clone https://github.com/WecoAI/aideml.git cd aideml && pip install -e . ``` -------------------------------- ### CLI with Local LLM (Ollama) Source: https://context7.com/wecoai/aideml/llms.txt Use a local LLM server by setting the OPENAI_BASE_URL environment variable. This example shows using a local model for coding and OpenAI for evaluation, and a fully local setup. ```bash # Start Ollama server, then run AIDE with local model export OPENAI_BASE_URL="http://localhost:11434/v1" # Use local model for coding, OpenAI for evaluation aide agent.code.model="qwen2.5" \ data_dir="./my_data" \ goal="Time series forecasting" \ eval="MAE" ``` ```bash # Fully local (no external API calls) aide agent.code.model="qwen2.5" \ agent.feedback.model="qwen2.5" \ data_dir="./my_data" \ goal="Anomaly detection" \ eval="Precision at 95% recall" ``` -------------------------------- ### Install AIDE ML Source: https://github.com/wecoai/aideml/blob/main/README.md Use pip to install the latest version of the AIDE ML package. ```bash pip install -U aideml ``` -------------------------------- ### CLI with Custom Model and Steps Source: https://context7.com/wecoai/aideml/llms.txt Configure the coding model, feedback model, and number of improvement iterations via CLI arguments. This example demonstrates using Claude for code generation with 50 improvement steps and GPT-4 Turbo with cross-validation. ```bash # Use Claude for code generation with 50 improvement steps aide agent.code.model="claude-4-sonnet" \ agent.steps=50 \ agent.search.num_drafts=3 \ data_dir="./my_dataset" \ goal="Build a classifier for customer churn" \ eval="F1 score on validation set" ``` ```bash # Use GPT-4 Turbo with cross-validation aide agent.code.model="gpt-4-turbo" \ agent.k_fold_validation=5 \ data_dir="./my_dataset" \ goal="Predict house prices" \ eval="RMSE between log-prices" ``` -------------------------------- ### Configure LLM Provider API Keys Source: https://context7.com/wecoai/aideml/llms.txt Set your LLM provider API key as an environment variable before running AIDE ML. This example shows configurations for OpenAI, Anthropic, Google Gemini, and OpenRouter. ```bash # OpenAI (default) export OPENAI_API_KEY="sk-your-openai-key" ``` ```bash # Anthropic (for Claude models) export ANTHROPIC_API_KEY="your-anthropic-key" ``` ```bash # Google Gemini export GEMINI_API_KEY="your-gemini-key" ``` ```bash # OpenRouter (for various models) export OPENROUTER_API_KEY="your-openrouter-key" ``` -------------------------------- ### Python API: Solution Object Usage Source: https://context7.com/wecoai/aideml/llms.txt The Solution dataclass returned by Experiment.run() contains the best code found and its validation metric. This example shows how to initialize an experiment and retrieve the solution. ```python from dataclasses import dataclass @dataclass class Solution: code: str # The Python code of the best solution valid_metric: float # The validation metric value achieved # Usage example import aide exp = aide.Experiment( data_dir="./bitcoin_data", goal="Build a time series forecasting model for bitcoin close price", eval="RMSLE" ) solution = exp.run(steps=10) ``` -------------------------------- ### Initialize Agent for search Source: https://context7.com/wecoai/aideml/llms.txt Sets up the agent with task configuration, journal, and interpreter for code generation. ```python from aide.agent import Agent from aide.journal import Journal from aide.interpreter import Interpreter from aide.utils.config import load_cfg, load_task_desc, prep_agent_workspace # Typically used internally by Experiment, but can be used directly cfg = load_cfg() # Load configuration task_desc = load_task_desc(cfg) prep_agent_workspace(cfg) journal = Journal() agent = Agent( task_desc=task_desc, cfg=cfg, journal=journal ) interpreter = Interpreter(cfg.workspace_dir, **cfg.exec) # Run one step of the agent # The agent will: ``` -------------------------------- ### Build and Run AIDE ML Docker Image Source: https://context7.com/wecoai/aideml/llms.txt Build the AIDE ML Docker image using the provided Dockerfile and run it with mounted volumes for data persistence and logs. Mounts include logs, workspaces, and data directories. The `OPENAI_API_KEY` environment variable must be set. ```bash # Build the Docker image docker build -t aide . # Run with mounted volumes for data and logs docker run -it --rm \ -v "${PWD}/logs:/app/logs" \ -v "${PWD}/workspaces:/app/workspaces" \ -v "${PWD}/my_data:/app/data" \ -e OPENAI_API_KEY="your-api-key" \ aide data_dir=/app/data \ goal="Your ML task goal" \ eval="Your evaluation metric" ``` -------------------------------- ### Launch AIDE ML Streamlit Web UI Source: https://context7.com/wecoai/aideml/llms.txt Instructions for launching the interactive Streamlit web UI, which provides a visual interface for managing experiments, configuring API keys, uploading data, and visualizing results. ```bash # Navigate to the webui directory and run cd aide/webui streamlit run app.py # Or run from package root python -m streamlit run aide/webui/app.py ``` -------------------------------- ### Python API: Experiment Class Initialization and Run Source: https://context7.com/wecoai/aideml/llms.txt Initialize an AIDE ML experiment using the Experiment class, configuring data directory, goal, and evaluation metric. Run the optimization and access the best solution and journal. ```python import aide import logging # Configure logging to see AIDE progress logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) aide_logger = logging.getLogger("aide") aide_logger.setLevel(logging.INFO) # Initialize experiment with data directory, goal, and evaluation metric exp = aide.Experiment( data_dir="example_tasks/house_prices", goal="Predict the sales price for each house based on property features", eval="RMSE between the logarithm of predicted and observed values" ) # Run the optimization for a specified number of steps # Returns a Solution object with the best code and validation metric best_solution = exp.run(steps=20) # Access results print(f"Best validation metric: {best_solution.valid_metric}") print(f"Best solution code:\n{best_solution.code}") # Access the full solution tree via the journal for node in exp.journal.nodes: status = "buggy" if node.is_buggy else f"metric={node.metric.value:.4f}" print(f"Step {node.step}: {node.stage_name} - {status}") ``` -------------------------------- ### Configure API Key and Run Optimization Source: https://github.com/wecoai/aideml/blob/main/README.md Set the required OpenAI API key and execute an optimization task via the CLI. ```bash export OPENAI_API_KEY= # https://platform.openai.com/api-keys ``` ```bash aide data_dir="example_tasks/house_prices" \ goal="Predict the sales price for each house" \ eval="RMSE between log‑prices" ``` -------------------------------- ### CLI Basic Usage Source: https://context7.com/wecoai/aideml/llms.txt Run AIDE ML from the command line by specifying the data directory, goal description, and evaluation metric. ```bash aide data_dir="path/to/your/data" \ goal="Predict the target variable based on features" \ eval="Use RMSE as the evaluation metric" ``` -------------------------------- ### Configure Local LLM Source: https://github.com/wecoai/aideml/blob/main/README.md Run AIDE using a local LLM via Ollama, with optional local feedback model configuration. ```bash export OPENAI_BASE_URL="http://localhost:11434/v1" aide agent.code.model="qwen2.5" data_dir=… goal=… eval=… ``` ```bash export OPENAI_BASE_URL="http://localhost:11434/v1" aide agent.code.model="qwen2.5" agent.feedback.model="qwen2.5" data_dir=… goal=… eval=… ``` -------------------------------- ### Run AIDE ML Docker with Custom Model Settings Source: https://context7.com/wecoai/aideml/llms.txt Run the AIDE ML Docker container with custom model settings, including specifying alternative API keys for different models (e.g., Anthropic) and overriding agent parameters like model and steps. This allows for cost optimization and tailored experiment configurations. ```bash # With custom model settings docker run -it --rm \ -v "${PWD}/logs:/app/logs" \ -v "${PWD}/workspaces:/app/workspaces" \ -v "${PWD}/my_data:/app/data" \ -e OPENAI_API_KEY="your-api-key" \ -e ANTHROPIC_API_KEY="your-anthropic-key" \ aide agent.code.model="claude-4-sonnet" \ agent.steps=30 \ data_dir=/app/data \ goal="Predict target" \ eval="RMSE" ``` -------------------------------- ### Programmatic Configuration Loading and Modification Source: https://context7.com/wecoai/aideml/llms.txt Load, modify, and save AIDE ML configurations programmatically using OmegaConf, allowing for dynamic adjustment of parameters like data directories, goals, and agent models. ```python from aide.utils.config import load_cfg, prep_cfg, _load_cfg from omegaconf import OmegaConf # Load default config with CLI args cfg = load_cfg() # Load config without CLI args (for programmatic use) cfg = _load_cfg(use_cli_args=False) cfg.data_dir = "./my_data" cfg.goal = "Predict customer lifetime value" cfg.eval = "Mean Absolute Error" cfg.agent.steps = 30 cfg.agent.code.model = "claude-4-sonnet" cfg = prep_cfg(cfg) # Access config values print(f"Log directory: {cfg.log_dir}") print(f"Workspace: {cfg.workspace_dir}") print(f"Timeout: {cfg.exec.timeout}s") print(f"Model: {cfg.agent.code.model}") # Save/load config OmegaConf.save(config=cfg, f="my_config.yaml") loaded_cfg = OmegaConf.load("my_config.yaml") ``` -------------------------------- ### Run AIDE ML Task Source: https://github.com/wecoai/aideml/blob/main/README.md Execute the agent by specifying the data directory, the goal, and the evaluation metric. ```bash aide data_dir=… goal="Predict churn" eval="AUROC" ``` -------------------------------- ### Run AIDE in Docker Source: https://github.com/wecoai/aideml/blob/main/README.md Execute AIDE within a containerized environment with volume mounts for logs and workspaces. ```bash docker build -t aide . docker run -it --rm \ -v "${LOGS_DIR:-$(pwd)/logs}:/app/logs" \ -v "${WORKSPACE_BASE:-$(pwd)/workspaces}:/app/workspaces" \ -v "$(pwd)/aide/example_tasks:/app/data" \ -e OPENAI_API_KEY="your-actual-api-key" \ aide data_dir=/app/data/house_prices goal="Predict price" eval="RMSE" ``` -------------------------------- ### Save solution to file Source: https://context7.com/wecoai/aideml/llms.txt Writes the code from a solution object to a local Python file. ```python with open("best_model.py", "w") as f: f.write(solution.code) print(f"Achieved RMSLE: {solution.valid_metric}") ``` -------------------------------- ### Integrate AIDE ML in Python Source: https://github.com/wecoai/aideml/blob/main/README.md Programmatically run experiments using the AIDE Python API. ```python import aide import logging def main(): logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') aide_logger = logging.getLogger("aide") aide_logger.setLevel(logging.INFO) print("Starting experiment...") exp = aide.Experiment( data_dir="example_tasks/bitcoin_price", # replace this with your own directory goal="Build a time series forecasting model for bitcoin close price.", # replace with your own goal description eval="RMSLE" # replace with your own evaluation metric ) best_solution = exp.run(steps=2) print(f"Best solution has validation metric: {best_solution.valid_metric}") print(f"Best solution code: {best_solution.code}") print("Experiment finished.") if __name__ == '__main__': main() ``` -------------------------------- ### Advanced CLI Configuration Source: https://github.com/wecoai/aideml/blob/main/README.md Customize the coding model and number of optimization steps using CLI flags. ```bash aide agent.code.model="claude-4-sonnet" \ agent.steps=50 \ data_dir=… goal=… eval=… ``` -------------------------------- ### Default AIDE ML Configuration Structure Source: https://context7.com/wecoai/aideml/llms.txt Defines the default configuration parameters for AIDE ML using YAML, covering data paths, execution settings, agent behavior, and model choices for different tasks. ```yaml # config.yaml - Default configuration structure data_dir: null # Required: path to data directory desc_file: null # Optional: path to task description file goal: null # Required if desc_file not provided eval: null # Optional: evaluation metric description log_dir: logs workspace_dir: workspaces preprocess_data: true # Unzip archives in data directory copy_data: true # Copy data to workspace (vs symlink) exp_name: null # Auto-generated if not provided exec: timeout: 3600 # Code execution timeout (seconds) agent_file_name: runfile.py format_tb_ipython: false generate_report: true report: model: gpt-4.1 temp: 1.0 agent: steps: 20 # Number of improvement iterations k_fold_validation: 5 # Cross-validation folds expose_prediction: false # Include predict() function data_preview: true # Show data preview to agent code: model: o4-mini # Model for code generation temp: 0.5 feedback: model: gpt-4.1-mini # Model for output evaluation temp: 0.5 search: max_debug_depth: 3 # Max consecutive debug attempts debug_prob: 0.5 # Probability of debugging vs improving num_drafts: 5 # Initial draft solutions before improving ``` -------------------------------- ### Access AIDE ML Output Files Programmatically Source: https://context7.com/wecoai/aideml/llms.txt Access generated output files from an AIDE ML experiment programmatically using the Python API. This includes reading the best performing solution code, accessing the visualization HTML, and obtaining the log directory path. ```python import aide from pathlib import Path exp = aide.Experiment( data_dir="./data", goal="Classification", eval="Accuracy" ) exp.run(steps=5) # Get output paths log_dir = exp.cfg.log_dir best_code = (log_dir / "best_solution.py").read_text() tree_viz = log_dir / "tree_plot.html" # Open in browser print(f"Results saved to: {log_dir}") ``` -------------------------------- ### Manage Journal solution tree Source: https://context7.com/wecoai/aideml/llms.txt Accesses and inspects the experiment journal to retrieve nodes, metrics, and summaries. ```python from aide.journal import Journal, Node # Journal is automatically created by Experiment # Access via exp.journal after creating an Experiment import aide exp = aide.Experiment( data_dir="./data", goal="Classification task", eval="Accuracy" ) exp.run(steps=5) journal = exp.journal # Get all nodes print(f"Total attempts: {len(journal)}") # Get initial draft nodes (root nodes in the tree) draft_nodes = journal.draft_nodes print(f"Number of initial drafts: {len(draft_nodes)}") # Get nodes by status good_nodes = journal.good_nodes # Successfully executed with valid metric buggy_nodes = journal.buggy_nodes # Failed execution or invalid metric # Get the best performing node best_node = journal.get_best_node() if best_node: print(f"Best metric: {best_node.metric.value}") print(f"Best code plan: {best_node.plan}") # Get metric history for plotting metrics = journal.get_metric_history() # Generate a summary for the agent's memory summary = journal.generate_summary(include_code=False) ``` -------------------------------- ### Inspect Solution Tree Node properties Source: https://context7.com/wecoai/aideml/llms.txt Describes the properties and metadata available on a node within the solution tree. ```python from aide.journal import Node from aide.utils.metric import MetricValue # Nodes are created by the Agent during search # Each node represents one solution attempt # Node properties after execution: # - code: str - The Python code # - plan: str - Natural language description of the approach # - step: int - The step number in the journal # - id: str - Unique identifier # - parent: Node | None - Parent node (None for draft nodes) # - children: set[Node] - Child nodes # Execution info: # - term_out: str - Terminal output (stdout/stderr) # - exec_time: float - Execution time in seconds # - exc_type: str | None - Exception type if failed # Evaluation info: # - metric: MetricValue - The validation metric # - is_buggy: bool - Whether the code is considered buggy # - analysis: str - LLM analysis of the execution # Check node stage node.stage_name # Returns: "draft", "debug", or "improve" # Check if node is a leaf (no children) node.is_leaf # Returns: bool # Get debug depth (consecutive debugging steps) node.debug_depth # Returns: int ``` -------------------------------- ### Cite AIDE ML Source: https://github.com/wecoai/aideml/blob/main/README.md BibTeX citation for the AIDE research paper. ```bibtex @article{aide2025, title={AIDE: AI-Driven Exploration in the Space of Code}, author={Zhengyao Jiang and Dominik Schmidt and Dhruv Srikanth and Dixing Xu and Ian Kaplan and Deniss Jacenko and Yuxiang Wu}, year={2025}, eprint={2502.13138}, archivePrefix={arXiv}, primaryClass={cs.AI}, url={https://arxiv.org/abs/2502.13138}, } ``` -------------------------------- ### Journal: Solution Tree Management Source: https://context7.com/wecoai/aideml/llms.txt The Journal class manages solution nodes in a tree structure, tracking code, execution results, and metrics for each attempt. It is automatically created by the Experiment class. ```APIDOC ## Journal: Solution Tree Management ### Description The Journal class maintains all solution nodes in a tree structure, tracking code, execution results, and metrics for each attempt. ### Accessing Journal Journal is automatically created by Experiment. Access via `exp.journal`. ```python import aide exp = aide.Experiment( data_dir="./data", goal="Classification task", eval="Accuracy" ) exp.run(steps=5) journal = exp.journal ``` ### Journal Properties and Methods - **`len(journal)`**: Returns the total number of attempts (nodes). - **`journal.draft_nodes`**: Returns a list of initial draft nodes (root nodes). - **`journal.good_nodes`**: Returns a list of nodes with successfully executed code and valid metrics. - **`journal.buggy_nodes`**: Returns a list of nodes that failed execution or had invalid metrics. - **`journal.get_best_node()`**: Returns the node with the best performing metric. Returns `None` if no nodes exist. - **`best_node.metric.value`**: The value of the best metric. - **`best_node.plan`**: The code plan associated with the best node. - **`journal.get_metric_history()`**: Returns a history of metrics, useful for plotting. - **`journal.generate_summary(include_code=False)`**: Generates a summary of the journal for agent memory. ``` -------------------------------- ### Agent: Core Search and Code Generation Source: https://context7.com/wecoai/aideml/llms.txt The Agent class implements the core tree search policy and handles code generation through distinct phases: drafting, improving, and debugging. ```APIDOC ## Agent: Core Search and Code Generation ### Description The Agent class implements the tree search policy and generates code through drafting, improving, and debugging phases. It is typically used internally by the `Experiment` class but can be instantiated directly. ### Initialization ```python from aide.agent import Agent from aide.journal import Journal from aide.interpreter import Interpreter from aide.utils.config import load_cfg, load_task_desc, prep_agent_workspace # Load configuration and task description cfg = load_cfg() task_desc = load_task_desc(cfg) prep_agent_workspace(cfg) # Initialize Journal and Interpreter journal = Journal() interpreter = Interpreter(cfg.workspace_dir, **cfg.exec) # Initialize Agent agent = Agent( task_desc=task_desc, cfg=cfg, journal=journal ) ``` ### Agent Operations - **`agent.run_step()`**: Executes one step of the agent's search and code generation process. The agent will: - Draft new solutions. - Improve existing solutions. - Debug failing solutions. - Update the journal with the results. ``` -------------------------------- ### House Features Data Dictionary Source: https://github.com/wecoai/aideml/blob/main/aide/example_tasks/house_prices/data_description.txt This section details the various features and their possible values that describe a house. ```APIDOC ## House Features Data Dictionary ### Description This document outlines the data dictionary for house features, providing definitions and possible values for each attribute. ### TotRmsAbvGrd **Description**: Total rooms above grade (does not include bathrooms). ### Functional **Description**: Home functionality. **Values**: - Min1: Minor Deductions 1 - Min2: Minor Deductions 2 - Mod: Moderate Deductions - Maj1: Major Deductions 1 - Maj2: Major Deductions 2 - Sev: Severely Damaged - Sal: Salvage only ### Fireplaces **Description**: Number of fireplaces. ### FireplaceQu **Description**: Fireplace quality. **Values**: - Ex: Excellent - Exceptional Masonry Fireplace - Gd: Good - Masonry Fireplace in main level - TA: Average - Prefabricated Fireplace in main living area or Masonry Fireplace in basement - Fa: Fair - Prefabricated Fireplace in basement - Po: Poor - Ben Franklin Stove - NA: No Fireplace ### GarageType **Description**: Garage location. **Values**: - 2Types: More than one type of garage - Attchd: Attached to home - Basment: Basement Garage - BuiltIn: Built-In (Garage part of house - typically has room above garage) - CarPort: Car Port - Detchd: Detached from home - NA: No Garage ### GarageYrBlt **Description**: Year garage was built. ### GarageFinish **Description**: Interior finish of the garage. **Values**: - Fin: Finished - RFn: Rough Finished - Unf: Unfinished - NA: No Garage ### GarageCars **Description**: Size of garage in car capacity. ### GarageArea **Description**: Size of garage in square feet. ### GarageQual **Description**: Garage quality. **Values**: - Ex: Excellent - Gd: Good - TA: Typical/Average - Fa: Fair - Po: Poor - NA: No Garage ### GarageCond **Description**: Garage condition. **Values**: - Ex: Excellent - Gd: Good - TA: Typical/Average - Fa: Fair - Po: Poor - NA: No Garage ### PavedDrive **Description**: Paved driveway. **Values**: - Y: Paved - P: Partial Pavement - N: Dirt/Gravel ### WoodDeckSF **Description**: Wood deck area in square feet. ### OpenPorchSF **Description**: Open porch area in square feet. ### EnclosedPorch **Description**: Enclosed porch area in square feet. ### 3SsnPorch **Description**: Three season porch area in square feet. ### ScreenPorch **Description**: Screen porch area in square feet. ### PoolArea **Description**: Pool area in square feet. ### PoolQC **Description**: Pool quality. **Values**: - Ex: Excellent - Gd: Good - TA: Average/Typical - Fa: Fair - NA: No Pool ### Fence **Description**: Fence quality. **Values**: - GdPrv: Good Privacy - MnPrv: Minimum Privacy - GdWo: Good Wood - MnWw: Minimum Wood/Wire - NA: No Fence ### MiscFeature **Description**: Miscellaneous feature not covered in other categories. **Values**: - Elev: Elevator - Gar2: 2nd Garage (if not described in garage section) - Othr: Other - Shed: Shed (over 100 SF) - TenC: Tennis Court - NA: None ### MiscVal **Description**: $Value of miscellaneous feature. ### MoSold **Description**: Month Sold (MM). ### YrSold **Description**: Year Sold (YYYY). ### SaleType **Description**: Type of sale. **Values**: - WD: Warranty Deed - Conventional - CWD: Warranty Deed - Cash - VWD: Warranty Deed - VA Loan - New: Home just constructed and sold - COD: Court Officer Deed/Estate - Con: Contract 15% Down payment regular terms - ConLw: Contract Low Down payment and low interest - ConLI: Contract Low Interest - ConLD: Contract Low Down - Oth: Other ### SaleCondition **Description**: Condition of sale. **Values**: - Normal: Normal Sale - Abnorml: Abnormal Sale - trade, foreclosure, short sale - AdjLand: Adjoining Land Purchase - Alloca: Allocation - two linked properties with separate deeds, typically condo with a garage unit - Family: Sale between family members - Partial: Home was not completed when last assessed (associated with New Homes) ``` -------------------------------- ### Generate Technical Report from Journal Source: https://context7.com/wecoai/aideml/llms.txt Use the `journal2report` function to generate a markdown report summarizing experiment findings. Requires an `Experiment` object and its journal, along with task description and report configuration. ```python from aide.journal2report import journal2report from aide.journal import Journal from aide.utils.config import StageConfig # After running an experiment import aide exp = aide.Experiment( data_dir="./data", goal="Regression task", eval="R-squared" ) exp.run(steps=10) # Generate markdown report report_config = StageConfig(model="gpt-4.1", temp=1.0) report = journal2report( journal=exp.journal, task_desc={"Task goal": "Regression task"}, rcfg=report_config ) # Report sections include: # - Introduction # - Preprocessing # - Modeling Methods # - Results Discussion # - Future Work print(report) # Save report with open("experiment_report.md", "w") as f: f.write(report) ``` -------------------------------- ### Determine LLM Provider and Query LLMs Source: https://context7.com/wecoai/aideml/llms.txt Automatically detect the LLM provider based on the model name and perform simple text queries or queries with function calling for structured output. ```python from aide.backend import query, determine_provider from aide.backend.utils import FunctionSpec # Automatic provider detection based on model name print(determine_provider("gpt-4-turbo")) # "openai" print(determine_provider("claude-3-opus")) # "anthropic" print(determine_provider("gemini-1.5-pro")) # "gemini" print(determine_provider("mistral-large")) # "openrouter" ``` ```python # Simple text query response = query( system_message="You are a helpful assistant.", user_message="Explain gradient descent in one sentence.", model="gpt-4-turbo", temperature=0.7, max_tokens=100 ) print(response) # String response ``` ```python # Query with function calling (structured output) func_spec = FunctionSpec( name="analyze_code", description="Analyze code execution output", json_schema={ "type": "object", "properties": { "is_bug": {"type": "boolean"}, "metric": {"type": "number"}, "summary": {"type": "string"} }, "required": ["is_bug", "metric", "summary"] } ) response = query( system_message="Analyze this code output.", user_message="Output: RMSE = 0.1234\nExecution time: 5.2s", model="gpt-4-turbo", func_spec=func_spec ) print(response) # Dict: {"is_bug": False, "metric": 0.1234, "summary": "..."} ``` -------------------------------- ### Node: Solution Tree Node Source: https://context7.com/wecoai/aideml/llms.txt Each Node in the solution tree represents a single solution attempt and contains code, execution results, and evaluation information, with defined parent-child relationships. ```APIDOC ## Node: Solution Tree Node ### Description Each Node in the solution tree contains code, execution results, and evaluation information with parent-child relationships. Nodes are created by the Agent during the search process. ### Node Properties - **`code`** (str): The Python code for this solution attempt. - **`plan`** (str): A natural language description of the approach. - **`step`** (int): The step number in the journal. - **`id`** (str): A unique identifier for the node. - **`parent`** (Node | None): The parent node in the tree. `None` for draft nodes. - **`children`** (set[Node]): A set of child nodes. ### Execution Information - **`term_out`** (str): Terminal output (stdout/stderr) from execution. - **`exec_time`** (float): Execution time in seconds. - **`exc_type`** (str | None): The type of exception raised during execution, if any. - **`exc_info`**: Exception details. - **`exc_stack`**: Exception traceback. ### Evaluation Information - **`metric`** (MetricValue): The validation metric result. - **`is_buggy`** (bool): Indicates if the code is considered buggy. - **`analysis`** (str): LLM analysis of the execution. ### Node Status and Stage - **`node.stage_name`** (str): Returns the current stage of the node: "draft", "debug", or "improve". - **`node.is_leaf`** (bool): Returns `True` if the node has no children, `False` otherwise. - **`node.debug_depth`** (int): Returns the number of consecutive debugging steps for this node. ``` -------------------------------- ### Execute code with Interpreter Source: https://context7.com/wecoai/aideml/llms.txt Runs Python code in an isolated subprocess with timeout protection and result capture. ```python from aide.interpreter import Interpreter, ExecutionResult from pathlib import Path # Create interpreter with a working directory interpreter = Interpreter( working_dir=Path("./workspace"), timeout=3600, # 1 hour timeout (default) format_tb_ipython=False, # Use standard Python traceback format agent_file_name="runfile.py" # Name for the executed file ) # Execute code code = """ import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestRegressor from sklearn.metrics import mean_squared_error # Load data df = pd.read_csv('./input/train.csv') X = df.drop(['SalePrice', 'Id'], axis=1) y = np.log1p(df['SalePrice']) # Handle categorical columns X = pd.get_dummies(X) # Split and train X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2) model = RandomForestRegressor(n_estimators=100, random_state=42) model.fit(X_train, y_train) # Evaluate y_pred = model.predict(X_val) rmse = np.sqrt(mean_squared_error(y_val, y_pred)) print(f"Validation RMSE: {rmse:.4f}") """ result: ExecutionResult = interpreter.run(code, reset_session=True) # ExecutionResult contains: print(f"Output: {''.join(result.term_out)}") print(f"Execution time: {result.exec_time:.2f}s") print(f"Exception type: {result.exc_type}") # None if successful print(f"Exception info: {result.exc_info}") print(f"Exception stack: {result.exc_stack}") # Clean up when done interpreter.cleanup_session() ``` -------------------------------- ### Interpreter: Safe Code Execution Source: https://context7.com/wecoai/aideml/llms.txt The Interpreter class provides a secure environment for executing Python code in isolated subprocesses, featuring timeout protection and output capture. ```APIDOC ## Interpreter: Safe Code Execution ### Description The Interpreter class executes Python code in isolated subprocesses with timeout protection and output capture. ### Initialization ```python from aide.interpreter import Interpreter from pathlib import Path interpreter = Interpreter( working_dir=Path("./workspace"), timeout=3600, # 1 hour timeout (default) format_tb_ipython=False, # Use standard Python traceback format agent_file_name="runfile.py" # Name for the executed file ) ``` ### Executing Code ```python code = """ # Your Python code here import pandas as pd # ... (rest of your code) """ result = interpreter.run(code, reset_session=True) ``` ### Execution Result (`ExecutionResult` object) - **`result.term_out`** (str): Captured standard output and standard error. - **`result.exec_time`** (float): The time taken for execution in seconds. - **`result.exc_type`** (str | None): The type of exception raised, or `None` if execution was successful. - **`result.exc_info`**: Detailed exception information. - **`result.exc_stack`**: The exception traceback. ### Session Management - **`interpreter.run(code, reset_session=True)`**: Executes the provided code. `reset_session=True` clears the session before execution. - **`interpreter.cleanup_session()`**: Cleans up the interpreter's session resources. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.