From 370b87bd0158c284dff93e9f6c78ed3287103840 Mon Sep 17 00:00:00 2001 From: Mandeep Singh Date: Sun, 2 Feb 2025 12:03:06 -0800 Subject: [PATCH 1/6] Update to use o3-mini --- ...code_interpreter_tool_for_LLM_agents.ipynb | 275 +++++++++++------- .../registry/agents/python_code_exec_agent.py | 9 +- 2 files changed, 181 insertions(+), 103 deletions(-) diff --git a/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb b/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb index 6eaf0b7528..8d74b69fae 100644 --- a/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb +++ b/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb @@ -5,18 +5,9 @@ "id": "5fde7616369c1e1e", "metadata": {}, "source": [ - "## Build Your Own Code Interpreter: Empowering LLM Agents with Dynamic Tool Calling\n", + "## Build Your Own Code Interpreter - Dynamic Tool Generation and Execution With o3-mini\n", "\n", - "Many API providers—such as OpenAI’s Assistants API—offer built-in code interpreter functionality. These built-in tools can be immensely powerful, but there are situations where developers may need to create their own custom code interpreter. For example:\n", - "\n", - "1. **Language or library support**: The built-in interpreter may not support the specific programming language (e.g., C++, Java, etc.) or libraries required for your task.\n", - "2. **Task compatibility**: Your use case may not be compatible with the provider’s built-in solution.\n", - "3. **Model constraints**: You might require a language model that isn’t supported by the provider’s interpreter.\n", - "4. **Cost considerations**: The cost structure for code execution or model usage may not fit your budget or constraints. \n", - "5. **File size**: The file size of input data is too large or not supported by the provider's interpreter.\n", - "6. **Integrating with internal systems**: The provider's interpreter may not be able to integrate with your internal systems.\n", - "\n", - "At the core of this approach is “function (or tool) calling,” where a Large Language Model (LLM) can invoke a function with arguments. Typically, these functions are predefined by the developer, along with their expected arguments and outputs. However, in this Cookbook, we explore a more flexible paradigm.\n", + "At the core of providing an LLM based Agent capability to interact with the outside world or other Agents is “tool (or function) calling,” where a Large Language Model (LLM) can invoke a function, a block of code, with arguments. Typically, these functions are predefined by the developer, along with their expected inputs and outputs. However, in this Cookbook, we explore a more flexible paradigm - to **dynamically generate tools** using **o3-mini**, with ability to execute the tool.\n", "\n", "### Dynamically Generated Tool Calling with Code Interpreter\n", "A Dynamically Generated Tool is a function or code block created by the LLM itself at runtime based on the user’s prompt. This means you don’t have to predefine every possible scenario in your codebase—enabling far more open-ended, creative, and adaptive problem-solving.\n", @@ -29,6 +20,25 @@ "- Process automation and scripting\n", "- And much more, as new possibilities emerge through experimentation\n", "\n", + "### Using o3-mini for Dynamic Tool generation\n", + "\n", + "Newly introduced o3-mini model is exceptional STEM capabilities—with particular strength in science, math, and coding—all while maintaining the low cost and reduced latency of smaller models. In this Cookbook, we will demonstrate o3-mini capability to generate python code to interpret data and draw insights.\n", + "\n", + "Reasoning models are particularly good at generating dynamic tools to analyze data since they can reason and do not need an explicit chain-of-thought prompt. In fact, providing explicit chain of thought instructions may interfere with model's internal reasoning and lead to suboptimal outcomes.\n", + "\n", + "You can learn more about o3-mini [here.](https://openai.com/index/openai-o3-mini/)\n", + "\n", + "### Why build your own code interpreter\n", + "\n", + "Many API providers—such as OpenAI’s Assistants API—offer built-in code interpreter functionality. These built-in code interpreters can be immensely powerful, but there are situations where developers may need to create their own custom code interpreter. For example:\n", + "\n", + "1. **Language or library support**: The built-in interpreter may not support the specific programming language (e.g., C++, Java, etc.) or libraries required for your task.\n", + "2. **Task compatibility**: Your use case may not be compatible with the provider’s built-in solution.\n", + "3. **Model constraints**: You might require a language model that isn’t supported by the provider’s interpreter.\n", + "4. **Cost considerations**: The cost structure for code execution or model usage may not fit your budget or constraints.\n", + "5. **File size**: The file size of input data is too large or not supported by the provider's interpreter.\n", + "6. **Integrating with internal systems**: The provider's interpreter may not be able to integrate with your internal systems.\n", + "\n", "### What You’ll Learn\n", "By following this Cookbook, you will learn how to:\n", "\n", @@ -241,7 +251,8 @@ "- Instructions to understand the contents of the file to provide as context to Agent 2.\n", "- Has access to the host machine’s file system. \n", "- Can read a file from the host and copy it into the Docker container.\n", - "- Cannot access the code interpreter tool. \n", + "- Cannot access the code interpreter tool.\n", + "- Uses gpt-4o model.\n", "\n", "2.\t**Agent 2: Python Code Generator and Executor (with Dynamically Generated Tool Calling and Code Execution)**\n", "- Recieve the file content's context from Agent 1.\n", @@ -249,6 +260,7 @@ "- Has access to the code interpreter within the Docker container, which is used to execute Python code.\n", "- Has access only to the file system inside the Docker container (not the host).\n", "- Cannot access the host machine’s file system or the network.\n", + "- Uses our newest **o3-mini** model that excels at code generation.\n", "\n", "This separation concerns of the File Access (Agent 1) and the Code Generator and Executor (Agent 2) is crucial to prevent the LLM from directly accessing or modifying the host machine. \n", "\n", @@ -311,7 +323,8 @@ "- A concrete implementation of the BaseAgent class. \n", "- Initialized with the developer prompt, model name, logger, and language model interface. These values can be overridden by the developer if needed. \n", "- Has a setup_tools method that registers the FileAccessTool to the tool manager. \n", - "- Has a `task` method that calls the FileAccessTool to read the file and provide the context to the PythonCodeExecAgent. \n" + "- Has a `task` method that calls the FileAccessTool to read the file and provide the context to the PythonCodeExecAgent.\n", + "- `model_name='gpt-4o'` that provides sufficient reasoning and tool calling ability for the task.\n" ] }, { @@ -328,7 +341,8 @@ "- A concrete implementation of the BaseAgent class. \n", "- Initialized with the developer prompt, model name, logger, and language model interface. These values can be overridden by the developer if needed. \n", "- Has a setup_tools method that registers the PythonExecTool to the tool manager. \n", - "- Has a `task` method that calls the OpenAI API to perform the user's task, which in this case involves generating a Python script to answer the user's question and run it with Code Interpretter tool. " + "- Has a `task` method that calls the OpenAI API to perform the user's task, which in this case involves generating a Python script to answer the user's question and run it with Code Interpreter tool.\n", + "- `model_name='o3-mini'` that excels at STEM tasks such as code generation." ] }, { @@ -346,14 +360,77 @@ }, { "cell_type": "code", - "execution_count": 4, "id": "866b7eb2", "metadata": { "ExecuteTime": { - "end_time": "2025-01-27T00:16:03.490020Z", - "start_time": "2025-01-27T00:15:36.487115Z" + "end_time": "2025-02-02T20:02:01.744619Z", + "start_time": "2025-02-02T20:00:26.688229Z" } }, + "source": [ + "# Import the agents from registry/agents\n", + "\n", + "from resources.registry.agents.file_access_agent import FileAccessAgent\n", + "from resources.registry.agents.python_code_exec_agent import PythonExecAgent\n", + "\n", + "\n", + "prompt = \"\"\"Use the file traffic_accidents.csv for your analysis. The column names are:\n", + "Variable\tDescription\n", + "accidents\tNumber of recorded accidents, as a positive integer.\n", + "traffic_fine_amount\tTraffic fine amount, expressed in thousands of USD.\n", + "traffic_density\tTraffic density index, scale from 0 (low) to 10 (high).\n", + "traffic_lights\tProportion of traffic lights in the area (0 to 1).\n", + "pavement_quality\tPavement quality, scale from 0 (very poor) to 5 (excellent).\n", + "urban_area\tUrban area (1) or rural area (0), as an integer.\n", + "average_speed\tAverage speed of vehicles in km/h.\n", + "rain_intensity\tRain intensity, scale from 0 (no rain) to 3 (heavy rain).\n", + "vehicle_count\tEstimated number of vehicles, in thousands, as an integer.\n", + "time_of_day\tTime of day in 24-hour format (0 to 24).\n", + "accidents\ttraffic_fine_amount\n", + "\"\"\"\n", + "\n", + "\n", + "print(\"Setup: \")\n", + "print(prompt)\n", + "\n", + "print(\"Setting up the agents... \")\n", + "\n", + "# Instantiate the agents with the default constructor defined values\n", + "# Developer may override the default values - prompt, model, logger, and language model interface if needed\n", + "\n", + "# This agent use gpt-4o by default\n", + "file_ingestion_agent = FileAccessAgent()\n", + "\n", + "# This agent uses o3-mini model by default\n", + "data_analysis_agent = PythonExecAgent(model_name='o3-mini')\n", + "\n", + "print(\"Understanding the contents of the file...\")\n", + "# Give a task to the file ingestion agent to read the file and provide the context to the data analysis agent \n", + "file_ingestion_agent_output = file_ingestion_agent.task(prompt)\n", + "\n", + "# Add the file content as context to the data analysis agent\n", + "# The context is added to the agent's tool manager so that the tool manager can use the context to generate the code \n", + "\n", + "data_analysis_agent.add_context(prompt)\n", + "data_analysis_agent.add_context(file_ingestion_agent_output)\n", + "\n", + "while True:\n", + "\n", + " print(\"Type your question related to the data in the file. Type 'exit' to exit.\")\n", + " user_input = input(\"Type your question.\")\n", + "\n", + " if user_input == \"exit\":\n", + " print(\"Exiting the application.\")\n", + " break\n", + "\n", + " print(f\"User question: {user_input}\")\n", + "\n", + " print(\"Generating dynamic tools and using code interpreter...\")\n", + " data_analysis_agent_output = data_analysis_agent.task(user_input)\n", + "\n", + " print(\"Output...\")\n", + " print(data_analysis_agent_output)\n" + ], "outputs": [ { "name": "stdout", @@ -382,9 +459,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "2025-01-26 16:15:37,348 - MyApp - INFO - Handling tool call: safe_file_access\n", - "2025-01-26 16:15:37,350 - MyApp - INFO - Tool arguments: {'filename': './resources/data/traffic_accidents.csv'}\n", - "2025-01-26 16:15:37,512 - MyApp - INFO - Tool 'safe_file_access' response: Copied ./resources/data/traffic_accidents.csv into sandbox:/home/sandboxuser/.\n", + "2025-02-02 12:00:27,749 - MyApp - INFO - Handling tool call: safe_file_access\n", + "2025-02-02 12:00:27,749 - MyApp - INFO - Tool arguments: {'filename': './resources/data/traffic_accidents.csv'}\n", + "2025-02-02 12:00:28,223 - MyApp - INFO - Tool 'safe_file_access' response: Copied ./resources/data/traffic_accidents.csv into sandbox:/home/sandboxuser/.\n", "The file content for the first 15 rows is:\n", " accidents traffic_fine_amount traffic_density traffic_lights pavement_quality urban_area average_speed rain_intensity vehicle_count time_of_day\n", "0 20 4.3709 2.3049 753.000 0.7700 1 321.592 1.1944 290.8570 160.4320\n", @@ -417,19 +494,72 @@ "name": "stderr", "output_type": "stream", "text": [ - "2025-01-26 16:15:50,144 - MyApp - INFO - Handling tool call: execute_python_code\n", - "2025-01-26 16:15:50,144 - MyApp - INFO - Tool arguments: {'python_code': \"import pandas as pd\\nimport numpy as np\\nfrom sklearn.ensemble import RandomForestRegressor\\n\\n# 1. Load the CSV file\\nfile_path = '/home/sandboxuser/traffic_accidents.csv'\\ndf = pd.read_csv(file_path)\\n\\n# 2. Prepare the data\\n# We'll treat 'accidents' as our target.\\nX = df.drop('accidents', axis=1)\\ny = df['accidents']\\n\\n# 3. Train a simple Random Forest Regressor to estimate feature importance.\\nrf = RandomForestRegressor(random_state=0)\\nrf.fit(X, y)\\n\\n# 4. Extract feature importances\\nfeature_importances = rf.feature_importances_\\ncolumns = X.columns\\n\\n# 5. Combine feature names and importances, and sort\\nimportances_df = pd.DataFrame({'Feature': columns, 'Importance': feature_importances})\\nimportances_df = importances_df.sort_values(by='Importance', ascending=False)\\n\\n# 6. Print the results\\nprint('Feature importances based on Random Forest Regressor:')\\nprint(importances_df.to_string(index=False))\"}\n", - "2025-01-26 16:15:53,260 - MyApp - INFO - Tool 'execute_python_code' response: Feature importances based on Random Forest Regressor:\n", - " Feature Importance\n", - "traffic_fine_amount 0.580858\n", - " traffic_density 0.164679\n", - " rain_intensity 0.095392\n", - " time_of_day 0.035838\n", - " average_speed 0.035590\n", - " pavement_quality 0.032545\n", - " traffic_lights 0.022789\n", - " vehicle_count 0.021246\n", - " urban_area 0.011062\n", + "2025-02-02 12:00:46,338 - MyApp - INFO - Handling tool call: execute_python_code\n", + "2025-02-02 12:00:46,339 - MyApp - INFO - Tool arguments: {'python_code': \"import pandas as pd\\nimport numpy as np\\nimport matplotlib.pyplot as plt\\nimport seaborn as sns\\nfrom sklearn.ensemble import RandomForestRegressor\\nfrom sklearn.model_selection import train_test_split\\nfrom sklearn.metrics import mean_squared_error\\n\\n# Load the data\\nfile_path = '/home/sandboxuser/traffic_accidents.csv'\\ndf = pd.read_csv(file_path)\\n\\n# Display head (first few rows) and dataframe info for debugging\\nprint('Data Head:')\\nprint(df.head())\\nprint('\\\\nData Info:')\\nprint(df.info())\\n\\n# Check for duplicate columns in case of mislabel (the description had duplicate variable names)\\nprint('\\\\nColumns:', df.columns.tolist())\\n\\n# Define target and features. assuming 'accidents' is the response.\\n# We use all the other columns as predictors.\\n\\ntarget = 'accidents'\\nfeatures = [col for col in df.columns if col != target]\\n\\n# Exploratory analysis: Compute correlation between accidents and other features\\ncorr = df.corr()\\nprint('\\\\nCorrelation matrix:')\\nprint(corr[target].sort_values(ascending=False))\\n\\n# Plot correlation heatmap\\nplt.figure(figsize=(10,8))\\nsns.heatmap(corr, annot=True, cmap='coolwarm', fmt='.2f')\\nplt.title('Correlation Heatmap')\\nplt.tight_layout()\\nplt.savefig('correlation_heatmap.png')\\nplt.close()\\n\\n# Use a RandomForestRegressor to evaluate feature importances\\n# Prepare the data (if any missing values, fill with median for simplicity)\\ndf = df.fillna(df.median())\\n\\nX = df[features]\\ny = df[target]\\n\\n# Split the dataset into training and test set\\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\\n\\n# Train the model\\nmodel = RandomForestRegressor(n_estimators=100, random_state=42)\\nmodel.fit(X_train, y_train)\\n\\n# Predict\\ny_pred = model.predict(X_test)\\nmse = mean_squared_error(y_test, y_pred)\\nprint('\\\\nRandom Forest Model Mean Squared Error:', mse)\\n\\n# Get feature importances\\nimportances = model.feature_importances_\\nfeat_importance = pd.Series(importances, index=features).sort_values(ascending=False)\\nprint('\\\\nFeature Importances from Random Forest:')\\nprint(feat_importance)\\n\\n# Plot feature importances\\nplt.figure(figsize=(10,6))\\nfeat_importance.plot(kind='bar')\\nplt.ylabel('Importance')\\nplt.title('Feature Importances for Accident Frequency Prediction')\\nplt.tight_layout()\\nplt.savefig('feature_importances.png')\\nplt.close()\\n\\nprint('\\\\nAnalysis Summary:')\\nprint('The correlation analysis and the random forest model indicate which factors are most associated with accident frequency. Factors with high correlation (absolute value) and high importance in the random forest model are likely significant contributors to accident frequency. Review the printed correlation values and the feature importance rankings to identify the key factors.')\\n\\n# The code also saved correlation heatmap and feature importance plots to PNG files.\\n\\n# For quick view, print both images paths:\\nprint('\\\\nCorrelation heatmap saved as correlation_heatmap.png')\\nprint('Feature importance plot saved as feature_importances.png')\\n\"}\n", + "2025-02-02 12:00:49,502 - MyApp - INFO - Tool 'execute_python_code' response: Data Head:\n", + " accidents traffic_fine_amount ... vehicle_count time_of_day\n", + "0 20 4.3709 ... 290.8570 160.4320\n", + "1 11 9.5564 ... 931.8120 8.9108\n", + "2 19 7.5879 ... 830.0860 5.5727\n", + "3 23 6.3879 ... 813.1590 131.4520\n", + "4 23 2.4042 ... 1.4663 6.9610\n", + "\n", + "[5 rows x 10 columns]\n", + "\n", + "Data Info:\n", + "\n", + "RangeIndex: 8756 entries, 0 to 8755\n", + "Data columns (total 10 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 accidents 8756 non-null int64 \n", + " 1 traffic_fine_amount 8756 non-null float64\n", + " 2 traffic_density 8756 non-null float64\n", + " 3 traffic_lights 8756 non-null float64\n", + " 4 pavement_quality 8756 non-null float64\n", + " 5 urban_area 8756 non-null int64 \n", + " 6 average_speed 8756 non-null float64\n", + " 7 rain_intensity 8756 non-null float64\n", + " 8 vehicle_count 8756 non-null float64\n", + " 9 time_of_day 8756 non-null float64\n", + "dtypes: float64(8), int64(2)\n", + "memory usage: 684.2 KB\n", + "None\n", + "\n", + "Columns: ['accidents', 'traffic_fine_amount', 'traffic_density', 'traffic_lights', 'pavement_quality', 'urban_area', 'average_speed', 'rain_intensity', 'vehicle_count', 'time_of_day']\n", + "\n", + "Correlation matrix:\n", + "accidents 1.000000\n", + "urban_area 0.145092\n", + "time_of_day 0.101995\n", + "average_speed 0.093923\n", + "vehicle_count 0.068399\n", + "pavement_quality 0.064694\n", + "traffic_lights -0.026642\n", + "traffic_density -0.059265\n", + "rain_intensity -0.091673\n", + "traffic_fine_amount -0.745161\n", + "Name: accidents, dtype: float64\n", + "\n", + "Random Forest Model Mean Squared Error: 5.559347659817352\n", + "\n", + "Feature Importances from Random Forest:\n", + "traffic_fine_amount 0.580211\n", + "traffic_density 0.169094\n", + "rain_intensity 0.095742\n", + "time_of_day 0.036433\n", + "average_speed 0.033714\n", + "pavement_quality 0.030789\n", + "traffic_lights 0.023037\n", + "vehicle_count 0.021283\n", + "urban_area 0.009697\n", + "dtype: float64\n", + "\n", + "Analysis Summary:\n", + "The correlation analysis and the random forest model indicate which factors are most associated with accident frequency. Factors with high correlation (absolute value) and high importance in the random forest model are likely significant contributors to accident frequency. Review the printed correlation values and the feature importance rankings to identify the key factors.\n", + "\n", + "Correlation heatmap saved as correlation_heatmap.png\n", + "Feature importance plot saved as feature_importances.png\n", "\n" ] }, @@ -438,83 +568,32 @@ "output_type": "stream", "text": [ "Output...\n", - "Based on a simple Random Forest analysis, the factor with the highest feature importance is “traffic_fine_amount.” The next most influential factors are “traffic_density” and “rain_intensity,” followed by “time_of_day” and “average_speed.”\n", + "The analysis (both the correlation study and the random forest feature importance) indicates that the traffic fine amount is the single most influential factor related to accident frequency. Here’s a summary of the key results:\n", + "\n", + "1. The Pearson correlation between accidents and traffic fine amount is about –0.75 (a strong negative relationship), which implies that as fine amount increases, accident frequency tends to decrease.\n", + "\n", + "2. In the random forest model, the traffic fine amount had the highest feature importance (approximately 58% importance), followed by traffic density (about 17%) and rain intensity (around 10%). These three predictors drive most of the model’s ability to predict accident frequency.\n", + "\n", + "3. Other factors such as average speed, pavement quality, traffic lights, vehicle count, urban area, and time of day contribute less significantly according to both the correlation and feature importance analysis.\n", + "\n", + "This suggests that factors impacting or reflecting traffic fine regimes (and, by extension, traffic law enforcement or penalties) are critically related to accident frequency, with additional contributions from aspects representing the local traffic conditions (density) and environmental factors (rain intensity).\n", + "\n", + "The code below was used to load the CSV data, perform the analysis, generate correlation heatmaps, and compute the random forest’s feature importances for accident frequency prediction.\n", "Type your question related to the data in the file. Type 'exit' to exit.\n", "Exiting the application.\n" ] } ], - "source": [ - "# Import the agents from registry/agents\n", - "\n", - "from resources.registry.agents.file_access_agent import FileAccessAgent\n", - "from resources.registry.agents.python_code_exec_agent import PythonExecAgent\n", - "\n", - "\n", - "prompt = \"\"\"Use the file traffic_accidents.csv for your analysis. The column names are:\n", - "Variable\tDescription\n", - "accidents\tNumber of recorded accidents, as a positive integer.\n", - "traffic_fine_amount\tTraffic fine amount, expressed in thousands of USD.\n", - "traffic_density\tTraffic density index, scale from 0 (low) to 10 (high).\n", - "traffic_lights\tProportion of traffic lights in the area (0 to 1).\n", - "pavement_quality\tPavement quality, scale from 0 (very poor) to 5 (excellent).\n", - "urban_area\tUrban area (1) or rural area (0), as an integer.\n", - "average_speed\tAverage speed of vehicles in km/h.\n", - "rain_intensity\tRain intensity, scale from 0 (no rain) to 3 (heavy rain).\n", - "vehicle_count\tEstimated number of vehicles, in thousands, as an integer.\n", - "time_of_day\tTime of day in 24-hour format (0 to 24).\n", - "accidents\ttraffic_fine_amount\n", - "\"\"\"\n", - "\n", - "\n", - "print(\"Setup: \")\n", - "print(prompt)\n", - "\n", - "print(\"Setting up the agents... \")\n", - "\n", - "# Instantiate the agents with the default constructor defined values\n", - "\n", - "# Developer override the default values - prompt, model, logger, and language model interface if needed\n", - "\n", - "file_ingestion_agent = FileAccessAgent()\n", - "data_analysis_agent = PythonExecAgent()\n", - "\n", - "print(\"Understanding the contents of the file...\")\n", - "# Give a task to the file ingestion agent to read the file and provide the context to the data analysis agent \n", - "file_ingestion_agent_output = file_ingestion_agent.task(prompt)\n", - "\n", - "# Add the file content as context to the data analysis agent\n", - "# The context is added to the agent's tool manager so that the tool manager can use the context to generate the code \n", - "\n", - "data_analysis_agent.add_context(prompt)\n", - "data_analysis_agent.add_context(file_ingestion_agent_output)\n", - "\n", - "while True:\n", - "\n", - " print(\"Type your question related to the data in the file. Type 'exit' to exit.\")\n", - " user_input = input(\"Type your question.\")\n", - "\n", - " if user_input == \"exit\":\n", - " print(\"Exiting the application.\")\n", - " break\n", - "\n", - " print(f\"User question: {user_input}\")\n", - "\n", - " print(\"Generating dynamic tools and using code interpreter...\")\n", - " data_analysis_agent_output = data_analysis_agent.task(user_input)\n", - "\n", - " print(\"Output...\")\n", - " print(data_analysis_agent_output)\n" - ] + "execution_count": 12 }, { "cell_type": "markdown", "id": "29f96b97", "metadata": {}, "source": [ - "In this example, the LLM dynamically generated a tool (a Python script) to analyze the data and answer the user's question that show cases the following:\n", + "In this example, the **o3-mini** dynamically generated a tool (Python script) based on user's question to analyze the data. This approach showcases the following:\n", "\n", - "**Dynamically Generated Tool Calling**: This tool (the Python script) to analyze the data was not manually written or predetermined by the developer. Instead, the LLM itself created the relevant data exploration, correlation analysis, and machine learning code at runtime.\n", + "**Dynamically Generated Tool Calling**: The tool (Python script) to analyze the data was not manually written or predetermined by the developer. Instead, the o3-mini model created the relevant data exploration, correlation analysis, and machine learning code at runtime.\n", "\n", "**Isolated Code Execution**: To ensure security and avoid running untrusted code on the host machine, the Python script was executed inside a Docker container using the `execute_python_code` tool. This container had restricted resource access (e.g., no network and limited filesystem access), minimizing potential risks posed by arbitrary code execution.\n" ] diff --git a/examples/object_oriented_agentic_approach/resources/registry/agents/python_code_exec_agent.py b/examples/object_oriented_agentic_approach/resources/registry/agents/python_code_exec_agent.py index a125325f5d..6e5ceee78a 100644 --- a/examples/object_oriented_agentic_approach/resources/registry/agents/python_code_exec_agent.py +++ b/examples/object_oriented_agentic_approach/resources/registry/agents/python_code_exec_agent.py @@ -30,13 +30,12 @@ def __init__( 2. The user will also supply context, including: - Column names and their descriptions. - Sample data from the CSV (headers and a few rows) to help understand data types. - 3. Analyze the provided data using Python machine learning libraries and generate appropriate code to fulfill the user's request. - 4. Generate Python code to analyze the data and call the tool `execute_python_code` to run the code inside a Docker container. - 5. Execute the code in the container and return the output. + 3. Generate Python code to analyze the data and call the tool `execute_python_code` to run the code and get results. + 4. You can use Python libraries pandas, numpy, matplotlib, seaborn, and scikit-learn. + 5. Interpret the results of the code execution and provide analysis to the user. - Note: All files referenced in the prompt are located in `/home/sandboxuser`. """, - model_name: str = "o1", + model_name: str = "o3-mini", logger=myapp_logger, language_model_interface = language_model_api_interface ): From 299e07b8e78a5a7b1b22c22a63ff2620e331e003 Mon Sep 17 00:00:00 2001 From: Mandeep Singh Date: Sun, 2 Feb 2025 12:35:30 -0800 Subject: [PATCH 2/6] Minor updates --- ...re_code_interpreter_tool_for_LLM_agents.ipynb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb b/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb index 8d74b69fae..c20db19c27 100644 --- a/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb +++ b/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb @@ -7,7 +7,7 @@ "source": [ "## Build Your Own Code Interpreter - Dynamic Tool Generation and Execution With o3-mini\n", "\n", - "At the core of providing an LLM based Agent capability to interact with the outside world or other Agents is “tool (or function) calling,” where a Large Language Model (LLM) can invoke a function, a block of code, with arguments. Typically, these functions are predefined by the developer, along with their expected inputs and outputs. However, in this Cookbook, we explore a more flexible paradigm - to **dynamically generate tools** using **o3-mini**, with ability to execute the tool.\n", + "At the core of providing a Large Language Model (LLM) based Agent capability to interact with the outside world or other Agents is “tool (or function) calling,” where a LLM can invoke a function (a block of code) with arguments. Typically, these functions are predefined by the developer, along with their expected inputs and outputs. However, in this Cookbook, we explore a more flexible paradigm - to **dynamically generate tools** using LLM models (in this case **o3-mini**), with ability to execute the tool using a code interpreter.\n", "\n", "### Dynamically Generated Tool Calling with Code Interpreter\n", "A Dynamically Generated Tool is a function or code block created by the LLM itself at runtime based on the user’s prompt. This means you don’t have to predefine every possible scenario in your codebase—enabling far more open-ended, creative, and adaptive problem-solving.\n", @@ -22,7 +22,7 @@ "\n", "### Using o3-mini for Dynamic Tool generation\n", "\n", - "Newly introduced o3-mini model is exceptional STEM capabilities—with particular strength in science, math, and coding—all while maintaining the low cost and reduced latency of smaller models. In this Cookbook, we will demonstrate o3-mini capability to generate python code to interpret data and draw insights.\n", + "Released on 31-Jan-25, o3-mini model has exceptional STEM capabilities—with particular strength in science, math, and coding—all while maintaining the low cost and reduced latency of smaller models. In this Cookbook, we will demonstrate o3-mini capability to generate python code to interpret data and draw insights.\n", "\n", "Reasoning models are particularly good at generating dynamic tools to analyze data since they can reason and do not need an explicit chain-of-thought prompt. In fact, providing explicit chain of thought instructions may interfere with model's internal reasoning and lead to suboptimal outcomes.\n", "\n", @@ -134,7 +134,7 @@ "source": [ "### Step 1: Set up an Isolated Code Execution Environment \n", "\n", - "Lets define a Dockerized container environment that will be used to execute our code. I have defined the **[dockerfile](./resources/docker/dockerfile)** under `resources/docker` directory that will be used to create the container environment with the following specifications:\n", + "Lets define a Dockerized container environment that will be used to execute our code. I have defined the **[dockerfile](https://github.com/openai/openai-cookbook/blob/main/examples/object_oriented_agentic_approach/resources/docker/dockerfile)** under `resources/docker` directory that will be used to create the container environment with the following specifications:\n", "- Python 3.10 as the base \n", "- A non-root user \n", "- Preinstall the packages in requirements.txt \n", @@ -307,7 +307,7 @@ "source": [ "**Define Agent 1: FileAccessAgent with FileAccessTool**\n", "\n", - "Let's start with definin the FileAccessTool that inherits from the ToolInterface class. The **FileAccessTool** tool is defined in the [file_access_agent.py](./resources/registry/tools/file_access_tool.py) file in the `resources/registry/tools` directory. \n", + "Let's start with definin the FileAccessTool that inherits from the ToolInterface class. The **FileAccessTool** tool is defined in the [file_access_tool.py](https://github.com/openai/openai-cookbook/blob/main/examples/object_oriented_agentic_approach/resources/registry/tools/file_access_tool.py) file in the `resources/registry/tools` directory.\n", "\n", "- FileAccessTool implements the ToolInterface class, which ensures that the tools will have a consistent interface. \n", "- Binding the tool definition for the OpenAI Function Calling API in the `get_definition` method and the tool's `run` method ensures maintainability, scalability, and reusability. " @@ -318,7 +318,7 @@ "id": "643f349e", "metadata": {}, "source": [ - "Now, let's define the **FileAccessAgent** that extends the BaseAgent class and bind the **FileAccessTool** to the agent. The FileAccessAgent is defined in the [file_acess_agent.py](./resources/registry/agents/file_access_agent.py) file in `resources/registry/agents` directory. The FileAccessAgent is: \n", + "Now, let's define the **FileAccessAgent** that extends the BaseAgent class and bind the **FileAccessTool** to the agent. The FileAccessAgent is defined in the [file_acess_agent.py](https://github.com/openai/openai-cookbook/blob/main/examples/object_oriented_agentic_approach/resources/registry/agents/file_access_agent.py) file in `resources/registry/agents` directory. The FileAccessAgent is:\n", "\n", "- A concrete implementation of the BaseAgent class. \n", "- Initialized with the developer prompt, model name, logger, and language model interface. These values can be overridden by the developer if needed. \n", @@ -334,9 +334,9 @@ "source": [ "**Define Agent 2: PythonExecAgent with PythonExecTool** \n", "\n", - "Similarly, PythonExecTool inherits from the ToolInterface class and implements the get_definition and run methods. The get_definition method returns the tool definition in the format expected by the OpenAI Function Calling API. The run method executes the Python code in a Docker container and returns the output. This tool is defined in the [python_code_interpreter_tool.py](./resources/registry/tools/python_code_interpreter_tool.py) file in the `resources/registry/tools` directory. \n", + "Similarly, PythonExecTool inherits from the ToolInterface class and implements the get_definition and run methods. The get_definition method returns the tool definition in the format expected by the OpenAI Function Calling API. The run method executes the Python code in a Docker container and returns the output. This tool is defined in the [python_code_interpreter_tool.py](https://github.com/openai/openai-cookbook/blob/main/examples/object_oriented_agentic_approach/resources/registry/tools/python_code_interpreter_tool.py) file in the `resources/registry/tools` directory.\n", "\n", - "Likewise, PythonExecAgent is a concrete implementation of the BaseAgent class. It is defined in the [python_code_exec_agent.py](./resources/registry/agents/python_code_exec_agent.py) file in the `resources/registry/agents` directory. The PythonExecAgent is: \n", + "Likewise, PythonExecAgent is a concrete implementation of the BaseAgent class. It is defined in the [python_code_exec_agent.py](https://github.com/openai/openai-cookbook/blob/main/examples/object_oriented_agentic_approach/resources/registry/agents/python_code_exec_agent.py) file in the `resources/registry/agents` directory. The PythonExecAgent is:\n", "\n", "- A concrete implementation of the BaseAgent class. \n", "- Initialized with the developer prompt, model name, logger, and language model interface. These values can be overridden by the developer if needed. \n", @@ -607,7 +607,7 @@ "\n", "The Cookbook provides a guide for developing a **custom code interpreter** tailored to specific application needs, addressing limitations found in vendor-provided solutions such as language constraints, cost considerations, and the need for flexibility with different LLMs or models.\n", "\n", - "**Approach for Managing Agents and Tools**: We also defined a set of core classes to manage the agents and tools. This approach ensures that the agents and tools will have a consistent interface and can be reused across different applications. A repository of agents and tools such as the [registry](./resources/registry) folder can be created to manage the agents and tools.\n", + "**Approach for Managing Agents and Tools**: We also defined a set of core classes to manage the agents and tools. This approach ensures that the agents and tools will have a consistent interface and can be reused across different applications. A repository of agents and tools such as the [registry](https://github.com/openai/openai-cookbook/tree/main/examples/object_oriented_agentic_approach/resources/registry) folder can be created to manage the agents and tools.\n", "\n", "To recap, the three steps to build an Agentic Application with Dynamic Tool Calling are:\n", "1. Set up an isolated code execution container environment\n", From a7dee3601c51a10164a4c4c36b8bc9d5b9a5d8ce Mon Sep 17 00:00:00 2001 From: Mandeep Singh Date: Sun, 2 Feb 2025 12:48:32 -0800 Subject: [PATCH 3/6] Minor updates --- ...ure_code_interpreter_tool_for_LLM_agents.ipynb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb b/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb index c20db19c27..ab79dc25f3 100644 --- a/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb +++ b/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb @@ -7,7 +7,7 @@ "source": [ "## Build Your Own Code Interpreter - Dynamic Tool Generation and Execution With o3-mini\n", "\n", - "At the core of providing a Large Language Model (LLM) based Agent capability to interact with the outside world or other Agents is “tool (or function) calling,” where a LLM can invoke a function (a block of code) with arguments. Typically, these functions are predefined by the developer, along with their expected inputs and outputs. However, in this Cookbook, we explore a more flexible paradigm - to **dynamically generate tools** using LLM models (in this case **o3-mini**), with ability to execute the tool using a code interpreter.\n", + "At the core of providing a LLM Agent capability to interact with the outside world or other Agents is “tool (or function) calling,” where a LLM can invoke a function (a block of code) with arguments. Typically, these functions are predefined by the developer, along with their expected inputs and outputs. However, in this Cookbook, we explore a more flexible paradigm - to **dynamically generate tools** using LLM models (in this case **o3-mini**), with ability to execute the tool using a code interpreter.\n", "\n", "### Dynamically Generated Tool Calling with Code Interpreter\n", "A Dynamically Generated Tool is a function or code block created by the LLM itself at runtime based on the user’s prompt. This means you don’t have to predefine every possible scenario in your codebase—enabling far more open-ended, creative, and adaptive problem-solving.\n", @@ -22,11 +22,9 @@ "\n", "### Using o3-mini for Dynamic Tool generation\n", "\n", - "Released on 31-Jan-25, o3-mini model has exceptional STEM capabilities—with particular strength in science, math, and coding—all while maintaining the low cost and reduced latency of smaller models. In this Cookbook, we will demonstrate o3-mini capability to generate python code to interpret data and draw insights.\n", + "Released on 31-Jan-25, o3-mini model has exceptional STEM capabilities—with particular strength in science, math, and coding—all while maintaining the low cost and reduced latency of smaller models. In this Cookbook, we will demonstrate o3-mini's capabilities to generate python code to interpret data and draw insights.\n", "\n", - "Reasoning models are particularly good at generating dynamic tools to analyze data since they can reason and do not need an explicit chain-of-thought prompt. In fact, providing explicit chain of thought instructions may interfere with model's internal reasoning and lead to suboptimal outcomes.\n", - "\n", - "You can learn more about o3-mini [here.](https://openai.com/index/openai-o3-mini/)\n", + "Reasoning models are particularly good at generating dynamic tools to analyze data since they can reason on their own, without the need of an explicit chain-of-thought prompt. In fact, providing explicit chain of thought instructions may interfere with model's internal reasoning and lead to suboptimal outcomes. You can learn more about o3-mini [here.](https://openai.com/index/openai-o3-mini/)\n", "\n", "### Why build your own code interpreter\n", "\n", @@ -45,10 +43,11 @@ "- Set up an isolated Python code execution environment using Docker\n", "- Configure your own code interpreter tool for LLM agents\n", "- Establish a clear separation of “Agentic” concerns for security and safety\n", + "- Using **o3-mini** model to dynamically generate code for data analysis\n", "- Orchestrate agents to efficiently accomplish a given task\n", "- Design an agentic application that can dynamically generate and execute code\n", "\n", - "You’ll see how to build a custom code interpreter tool from the ground up, leverage the power of LLMs to generate sophisticated code, and safely execute that code in an isolated environment—all in pursuit of making your AI-powered applications more flexible, powerful, and cost-effective." + "You’ll learn how to build a custom code interpreter tool from the ground up, leverage the power of LLMs to generate sophisticated code, and safely execute that code in an isolated environment—all in pursuit of making your AI-powered applications more flexible, powerful, and cost-effective." ] }, { @@ -591,9 +590,9 @@ "id": "29f96b97", "metadata": {}, "source": [ - "In this example, the **o3-mini** dynamically generated a tool (Python script) based on user's question to analyze the data. This approach showcases the following:\n", + "In this example, the **o3-mini** dynamically generated a tool (Python script) based on user's question to analyze the data. Note that **o3-mini** examined the problem using multiple approaches such as Pearson correlation and random forest models. This approach showcases the following:\n", "\n", - "**Dynamically Generated Tool Calling**: The tool (Python script) to analyze the data was not manually written or predetermined by the developer. Instead, the o3-mini model created the relevant data exploration, correlation analysis, and machine learning code at runtime.\n", + "**Dynamically Generated Tool Calling**: The tool (Python script) to analyze the data was not manually written or predetermined by the developer. Instead, the o3-mini model created the relevant data exploration and correlation analysis code at runtime.\n", "\n", "**Isolated Code Execution**: To ensure security and avoid running untrusted code on the host machine, the Python script was executed inside a Docker container using the `execute_python_code` tool. This container had restricted resource access (e.g., no network and limited filesystem access), minimizing potential risks posed by arbitrary code execution.\n" ] From 95c0e745285461576e590d34798d9bcf81732565 Mon Sep 17 00:00:00 2001 From: Mandeep Singh Date: Sun, 2 Feb 2025 13:06:58 -0800 Subject: [PATCH 4/6] Minor updates --- .../Secure_code_interpreter_tool_for_LLM_agents.ipynb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb b/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb index ab79dc25f3..ce6e54289f 100644 --- a/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb +++ b/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb @@ -608,7 +608,9 @@ "\n", "**Approach for Managing Agents and Tools**: We also defined a set of core classes to manage the agents and tools. This approach ensures that the agents and tools will have a consistent interface and can be reused across different applications. A repository of agents and tools such as the [registry](https://github.com/openai/openai-cookbook/tree/main/examples/object_oriented_agentic_approach/resources/registry) folder can be created to manage the agents and tools.\n", "\n", - "To recap, the three steps to build an Agentic Application with Dynamic Tool Calling are:\n", + "**o3-mini model**: We demonstrated o3-mini model's ability to generate sophisticated code to analyze data on the fly based on user's minimal prompt to answer question.\n", + "\n", + "Finally, **to recap**, the three steps to build an Agentic Application with Dynamic Tool Calling are:\n", "1. Set up an isolated code execution container environment\n", "2. Define and Test the Agents\n", "3. Set up Agentic Orchestration to run the application \n", From c3e0bb94893be46744327c4f483e712321e62c98 Mon Sep 17 00:00:00 2001 From: Mandeep Singh Date: Sun, 2 Feb 2025 13:09:09 -0800 Subject: [PATCH 5/6] Renumbered cells --- ...code_interpreter_tool_for_LLM_agents.ipynb | 130 +++++++++--------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb b/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb index ce6e54289f..0fb9a27629 100644 --- a/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb +++ b/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb @@ -359,6 +359,7 @@ }, { "cell_type": "code", + "execution_count": 4, "id": "866b7eb2", "metadata": { "ExecuteTime": { @@ -366,70 +367,6 @@ "start_time": "2025-02-02T20:00:26.688229Z" } }, - "source": [ - "# Import the agents from registry/agents\n", - "\n", - "from resources.registry.agents.file_access_agent import FileAccessAgent\n", - "from resources.registry.agents.python_code_exec_agent import PythonExecAgent\n", - "\n", - "\n", - "prompt = \"\"\"Use the file traffic_accidents.csv for your analysis. The column names are:\n", - "Variable\tDescription\n", - "accidents\tNumber of recorded accidents, as a positive integer.\n", - "traffic_fine_amount\tTraffic fine amount, expressed in thousands of USD.\n", - "traffic_density\tTraffic density index, scale from 0 (low) to 10 (high).\n", - "traffic_lights\tProportion of traffic lights in the area (0 to 1).\n", - "pavement_quality\tPavement quality, scale from 0 (very poor) to 5 (excellent).\n", - "urban_area\tUrban area (1) or rural area (0), as an integer.\n", - "average_speed\tAverage speed of vehicles in km/h.\n", - "rain_intensity\tRain intensity, scale from 0 (no rain) to 3 (heavy rain).\n", - "vehicle_count\tEstimated number of vehicles, in thousands, as an integer.\n", - "time_of_day\tTime of day in 24-hour format (0 to 24).\n", - "accidents\ttraffic_fine_amount\n", - "\"\"\"\n", - "\n", - "\n", - "print(\"Setup: \")\n", - "print(prompt)\n", - "\n", - "print(\"Setting up the agents... \")\n", - "\n", - "# Instantiate the agents with the default constructor defined values\n", - "# Developer may override the default values - prompt, model, logger, and language model interface if needed\n", - "\n", - "# This agent use gpt-4o by default\n", - "file_ingestion_agent = FileAccessAgent()\n", - "\n", - "# This agent uses o3-mini model by default\n", - "data_analysis_agent = PythonExecAgent(model_name='o3-mini')\n", - "\n", - "print(\"Understanding the contents of the file...\")\n", - "# Give a task to the file ingestion agent to read the file and provide the context to the data analysis agent \n", - "file_ingestion_agent_output = file_ingestion_agent.task(prompt)\n", - "\n", - "# Add the file content as context to the data analysis agent\n", - "# The context is added to the agent's tool manager so that the tool manager can use the context to generate the code \n", - "\n", - "data_analysis_agent.add_context(prompt)\n", - "data_analysis_agent.add_context(file_ingestion_agent_output)\n", - "\n", - "while True:\n", - "\n", - " print(\"Type your question related to the data in the file. Type 'exit' to exit.\")\n", - " user_input = input(\"Type your question.\")\n", - "\n", - " if user_input == \"exit\":\n", - " print(\"Exiting the application.\")\n", - " break\n", - "\n", - " print(f\"User question: {user_input}\")\n", - "\n", - " print(\"Generating dynamic tools and using code interpreter...\")\n", - " data_analysis_agent_output = data_analysis_agent.task(user_input)\n", - "\n", - " print(\"Output...\")\n", - " print(data_analysis_agent_output)\n" - ], "outputs": [ { "name": "stdout", @@ -583,7 +520,70 @@ ] } ], - "execution_count": 12 + "source": [ + "# Import the agents from registry/agents\n", + "\n", + "from resources.registry.agents.file_access_agent import FileAccessAgent\n", + "from resources.registry.agents.python_code_exec_agent import PythonExecAgent\n", + "\n", + "\n", + "prompt = \"\"\"Use the file traffic_accidents.csv for your analysis. The column names are:\n", + "Variable\tDescription\n", + "accidents\tNumber of recorded accidents, as a positive integer.\n", + "traffic_fine_amount\tTraffic fine amount, expressed in thousands of USD.\n", + "traffic_density\tTraffic density index, scale from 0 (low) to 10 (high).\n", + "traffic_lights\tProportion of traffic lights in the area (0 to 1).\n", + "pavement_quality\tPavement quality, scale from 0 (very poor) to 5 (excellent).\n", + "urban_area\tUrban area (1) or rural area (0), as an integer.\n", + "average_speed\tAverage speed of vehicles in km/h.\n", + "rain_intensity\tRain intensity, scale from 0 (no rain) to 3 (heavy rain).\n", + "vehicle_count\tEstimated number of vehicles, in thousands, as an integer.\n", + "time_of_day\tTime of day in 24-hour format (0 to 24).\n", + "accidents\ttraffic_fine_amount\n", + "\"\"\"\n", + "\n", + "\n", + "print(\"Setup: \")\n", + "print(prompt)\n", + "\n", + "print(\"Setting up the agents... \")\n", + "\n", + "# Instantiate the agents with the default constructor defined values\n", + "# Developer may override the default values - prompt, model, logger, and language model interface if needed\n", + "\n", + "# This agent use gpt-4o by default\n", + "file_ingestion_agent = FileAccessAgent()\n", + "\n", + "# This agent uses o3-mini model by default\n", + "data_analysis_agent = PythonExecAgent(model_name='o3-mini')\n", + "\n", + "print(\"Understanding the contents of the file...\")\n", + "# Give a task to the file ingestion agent to read the file and provide the context to the data analysis agent \n", + "file_ingestion_agent_output = file_ingestion_agent.task(prompt)\n", + "\n", + "# Add the file content as context to the data analysis agent\n", + "# The context is added to the agent's tool manager so that the tool manager can use the context to generate the code \n", + "\n", + "data_analysis_agent.add_context(prompt)\n", + "data_analysis_agent.add_context(file_ingestion_agent_output)\n", + "\n", + "while True:\n", + "\n", + " print(\"Type your question related to the data in the file. Type 'exit' to exit.\")\n", + " user_input = input(\"Type your question.\")\n", + "\n", + " if user_input == \"exit\":\n", + " print(\"Exiting the application.\")\n", + " break\n", + "\n", + " print(f\"User question: {user_input}\")\n", + "\n", + " print(\"Generating dynamic tools and using code interpreter...\")\n", + " data_analysis_agent_output = data_analysis_agent.task(user_input)\n", + "\n", + " print(\"Output...\")\n", + " print(data_analysis_agent_output)\n" + ] }, { "cell_type": "markdown", From 561ae8db346a21a33003c2fea7f56f861ace250c Mon Sep 17 00:00:00 2001 From: Mandeep Singh Date: Sun, 2 Feb 2025 14:04:17 -0800 Subject: [PATCH 6/6] Minor changes --- .../Secure_code_interpreter_tool_for_LLM_agents.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb b/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb index 0fb9a27629..728e798d0e 100644 --- a/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb +++ b/examples/object_oriented_agentic_approach/Secure_code_interpreter_tool_for_LLM_agents.ipynb @@ -608,7 +608,7 @@ "\n", "**Approach for Managing Agents and Tools**: We also defined a set of core classes to manage the agents and tools. This approach ensures that the agents and tools will have a consistent interface and can be reused across different applications. A repository of agents and tools such as the [registry](https://github.com/openai/openai-cookbook/tree/main/examples/object_oriented_agentic_approach/resources/registry) folder can be created to manage the agents and tools.\n", "\n", - "**o3-mini model**: We demonstrated o3-mini model's ability to generate sophisticated code to analyze data on the fly based on user's minimal prompt to answer question.\n", + "**o3-mini model**: We demonstrated o3-mini model's ability to generate sophisticated code at run time to analyze data based on user's minimal prompt. o3-mini model then reasoned over the outcome of the analysis to explain the results to the user.\n", "\n", "Finally, **to recap**, the three steps to build an Agentic Application with Dynamic Tool Calling are:\n", "1. Set up an isolated code execution container environment\n",