🐫 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: support gpt 5.2 and clean example code (#3564)
Wendong-Fan8cbe9cffa304
diff --git a/camel/types/enums.py b/camel/types/enums.pyindex 7c0a94d5c..e05ee9097 100644--- a/camel/types/enums.py+++ b/camel/types/enums.py@@ -50,6 +50,7 @@ class ModelType(UnifiedModelType, Enum):O3 = "o3"O3_PRO = "o3-pro"GPT_5_1 = "gpt-5.1"+ GPT_5_2 = ("gpt-5.2",)GPT_5 = "gpt-5"GPT_5_MINI = "gpt-5-mini"GPT_5_NANO = "gpt-5-nano"@@ -597,6 +598,7 @@ class ModelType(UnifiedModelType, Enum):ModelType.O4_MINI,ModelType.O3,ModelType.GPT_5_1,+ ModelType.GPT_5_2,}@property@@ -1542,6 +1544,7 @@ class ModelType(UnifiedModelType, Enum):return 320_000elif self in {ModelType.GPT_5_1,+ ModelType.GPT_5_2,ModelType.GPT_5_MINI,ModelType.GPT_5_NANO,ModelType.GPT_5,diff --git a/examples/models/openai_gpt_5_example.py b/examples/models/openai_example.pysimilarity index 57%rename from examples/models/openai_gpt_5_example.pyrename to examples/models/openai_example.pyindex adf6b2416..337947afd 100644--- a/examples/models/openai_gpt_5_example.py+++ b/examples/models/openai_example.py@@ -15,28 +15,52 @@from camel.agents import ChatAgentfrom camel.configs import ChatGPTConfigfrom camel.models import ModelFactory+from camel.toolkits import TerminalToolkitfrom camel.types import ModelPlatformType, ModelType+tools = [+ *TerminalToolkit().get_tools(),+]+gpt_5_model = ModelFactory.create(model_platform=ModelPlatformType.OPENAI,- model_type=ModelType.GPT_5,+ model_type=ModelType.GPT_5_2,model_config_dict=ChatGPTConfig().as_dict(),)# Set agent-camel_agent = ChatAgent(model=gpt_5_model)+camel_agent = ChatAgent(model=gpt_5_model, tools=tools)# Set user message-user_msg = """Say hi to CAMEL AI, one open-source community- dedicated to the study of autonomous and communicative agents."""+user_msg = """Use tool to create an interactive HTML webpage that allows users+to play with a Rubik's Cube, and saved it to local file.+"""# Get response informationresponse = camel_agent.step(user_msg)print(response.msgs[0].content)'''===============================================================================-Hello, CAMEL AI! Great to connect with an open-source community advancing-autonomous and communicative agents. Wishing you continued success—excited to-see what you build next!+Created an interactive Rubik's Cube webpage and saved it locally as:++- `rubiks_cube.html`++It includes:+- 3D cube rendering (drag to orbit, wheel to zoom)+- Face turns via buttons or keyboard (U/D/L/R/F/B, Shift for prime)+- Scramble, reset, random move+- Undo/redo+- Copyable moves log++Open it by double-clicking the file or serving it locally+(recommended due to browser module/security policies):++```bash+python3 -m http.server+# then visit http://localhost:8000/rubiks_cube.html+```++If you want a **fully offline** version (no CDN usage), tell me and+I'll modify it to bundle the required libraries locally or inline them.==============================================================================='''diff --git a/examples/models/openai_gpt_4.1_example.py b/examples/models/openai_gpt_4.1_example.pydeleted file mode 100644index e2980e4ed..000000000--- a/examples/models/openai_gpt_4.1_example.py+++ /dev/null@@ -1,44 +0,0 @@-# ========= 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. =========--from camel.agents import ChatAgent-from camel.configs import ChatGPTConfig-from camel.models import ModelFactory-from camel.types import ModelPlatformType, ModelType--gpt_4_1_model = ModelFactory.create(- model_platform=ModelPlatformType.OPENAI,- model_type=ModelType.GPT_4_1,- model_config_dict=ChatGPTConfig().as_dict(),-)--# Set agent-camel_agent = ChatAgent(model=gpt_4_1_model)--# Set user message-user_msg = """Say hi to CAMEL AI, one open-source community- dedicated to the study of autonomous and communicative agents."""--# Get response information-response = camel_agent.step(user_msg)-print(response.msgs[0].content)-'''-===============================================================================-Hi CAMEL AI! 👋 It's great to see an open-source community dedicated to-advancing the study of autonomous and communicative agents. Your efforts help-push the boundaries of what's possible in AI collaboration and agentic-systems. Looking forward to seeing the innovations and insights your community-brings to the field! 🚀-===============================================================================-'''diff --git a/examples/models/openai_gpt_4.5_preview_example.py b/examples/models/openai_gpt_4.5_preview_example.pydeleted file mode 100644index e69d98e48..000000000--- a/examples/models/openai_gpt_4.5_preview_example.py+++ /dev/null@@ -1,94 +0,0 @@-# ========= 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. =========--from camel.agents import ChatAgent-from camel.configs import ChatGPTConfig-from camel.models import ModelFactory-from camel.types import ModelPlatformType, ModelType--gpt_4_5_preview_model = ModelFactory.create(- model_platform=ModelPlatformType.OPENAI,- model_type=ModelType.GPT_4_5_PREVIEW,- model_config_dict=ChatGPTConfig().as_dict(),-)--# Set agent-camel_agent = ChatAgent(model=gpt_4_5_preview_model)--# Set user message-user_msg = """Please write inspirational poems-that make people feel hopeful and enthusiastic about life"""--# Get response information-response = camel_agent.step(user_msg)-print(response.msgs[0].content)-'''-===============================================================================--### Poem 1: Embrace the Dawn--Awaken now, the dawn is near,-A fresh new day, release your fear.-Yesterday's shadows fade away,-Hope blooms bright, embrace today.--Rise with courage, dreams in sight,-Your heart ablaze, your spirit bright.-Each step forward, strength you find,-A brighter future, yours to bind.--Believe in you, your path is clear,-Trust your journey, hold it dear.-Life's beauty shines, a guiding star,-You're stronger now than ever you are.-------### Poem 2: The Power Within--Within your heart, a spark resides,-A strength that never truly hides.-Through storms and trials, you will rise,-With hope and courage in your eyes.--Your dreams are seeds, plant them deep,-Nurture faith, your promise keep.-Life's journey vast, adventure grand,-Hold tight to hope, take life's hand.--Enthusiasm fuels your way,-Brightens every single day.-Believe, persist, your spirit free,-The power within—your destiny.-------### Poem 3: A New Beginning--Each sunrise brings a fresh new start,-A chance to heal, renew your heart.-Let go of doubts, embrace the light,-Your future shines, forever bright.--Life's canvas blank, your colors bold,-Paint your dreams, let joy unfold.-Hope whispers softly, "You can soar,"-Open wide life's wondrous door.--Enthusiasm fills your soul,-Guiding you toward your goal.-With hope alive, your spirit strong,-Life's melody—your hopeful song.-===============================================================================-'''diff --git a/examples/models/openai_o1_example.py b/examples/models/openai_o1_example.pydeleted file mode 100644index 5a3583acb..000000000--- a/examples/models/openai_o1_example.py+++ /dev/null@@ -1,173 +0,0 @@-# ========= 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. =========--from camel.agents import ChatAgent-from camel.configs import ChatGPTConfig-from camel.models import ModelFactory-from camel.types import ModelPlatformType, ModelType--o1_model = ModelFactory.create(- model_platform=ModelPlatformType.OPENAI,- model_type=ModelType.O1_MINI, # Or ModelType.O1- model_config_dict=ChatGPTConfig().as_dict(),-)--# Set agent-camel_agent = ChatAgent(model=o1_model)--# Set user message-user_msg = """Write a bash script that takes a matrix represented as a string- with format '[1,2],[3,4],[5,6]' and prints the transpose in the same- format."""--# Get response information-response = camel_agent.step(user_msg)-print(response.msgs[0].content)-'''-===============================================================================-Here's a bash script that transposes a matrix represented as the string format-specified. It handles matrices of various sizes, including those with varying-numbers of columns.--```bash-#!/bin/bash--# Read input string from argument or stdin-if [ -n "$1" ]; then- input="$1"-else- read input-fi--# Preprocess the input string to facilitate parsing-# Replace '],[' with '];[' to use ';' as row separator-input="${input//],[/];[}"--# Remove leading and trailing square brackets if any-input="${input#[}"-input="${input%]}"--# Split the input into rows-IFS=';' read -ra rows <<< "$input"--declare -A matrix--nrows=${#rows[@]}-ncols=0--# Parse each row-for ((i=0; i<nrows; i++)); do- row="${rows[i]}"- # Remove leading '[' and trailing ']'- row="${row#[}"- row="${row%]}"- # Split row into elements- IFS=',' read -ra elems <<< "$row"- num_elems=${#elems[@]}- if (( num_elems > ncols )); then- ncols=$num_elems- fi- # Store elements in matrix associative array- for ((j=0; j<num_elems; j++)); do- matrix[$i,$j]="${elems[j]}"- done-done--# Function to join array elements with a delimiter-join_by() {- local d=$1; shift- if [ "$#" -gt 0 ]; then- printf %s "$1" "${@/#/$d}"- fi-}--# Now, build the transposed matrix-transposed_rows=()-for ((j=0; j<ncols; j++)); do- tr_row_elements=()- for ((i=0; i<nrows; i++)); do- e="${matrix[$i,$j]:-}" # Use empty string if element is missing- tr_row_elements+=("$e")- done- tr_row_elements_str=$(join_by ',' "${tr_row_elements[@]}")- tr_row="[${tr_row_elements_str}]"- transposed_rows+=("$tr_row")-done--# Build output string-output=$(join_by ',' "${transposed_rows[@]}")--# Print the output-echo "$output"-```--**Usage:**--Save the script to a file, for example, `transpose_matrix.sh`, and make it-executable:--```bash-chmod +x transpose_matrix.sh-```--You can run the script by passing the matrix string as an argument:--```bash-./transpose_matrix.sh '[1,2],[3,4],[5,6]'-```--Output:--```-[1,3,5],[2,4,6]-```--**Explanation:**--The script performs the following steps:--1. **Input Preprocessing:**- - Replaces `],[` with `];[` to use `;` as a separator between rows.- - Removes any leading or trailing square brackets.--2. **Parsing the Input into a Matrix:**- - Splits the input string into rows using `IFS`.- - For each row:- - Removes the leading `[` and trailing `]`.- - Splits the row into its elements.- - Stores the elements into an associative array `matrix` with keys as- `row,column`.--3. **Determining the Matrix Dimensions:**- - Counts the number of rows (`nrows`).- - Determines the maximum number of columns (`ncols`) across all rows.--4. **Transposing the Matrix:**- - Iterates over each column index.- - For each column, collects the elements from each row at that column index.- - Builds the transposed row string and adds it to `transposed_rows`.--5. **Generating the Output:**- - Joins the transposed rows using commas to form the final output string.- - Prints the output.--**Notes:**--- The script supports matrices where rows have different numbers of columns.-- Missing elements in the matrix (due to irregular column sizes) are handled-by inserting empty strings in the transposed matrix.-- The `join_by` function is used to handle joining array elements with a-specified delimiter, ensuring proper formatting.-===============================================================================-'''diff --git a/examples/models/openai_o3_mini_example.py b/examples/models/openai_o3_mini_example.pydeleted file mode 100644index eb93ef277..000000000--- a/examples/models/openai_o3_mini_example.py+++ /dev/null@@ -1,92 +0,0 @@-# ========= 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. =========--from camel.agents import ChatAgent-from camel.configs import ChatGPTConfig-from camel.models import ModelFactory-from camel.toolkits import SearchToolkit-from camel.types import ModelPlatformType, ModelType--o3_model = ModelFactory.create(- model_platform=ModelPlatformType.OPENAI,- model_type=ModelType.O3_MINI,- model_config_dict=ChatGPTConfig().as_dict(),-)---# Set agent-camel_agent = ChatAgent(- model=o3_model, tools=[SearchToolkit().search_duckduckgo]-)--# Set user message-user_msg = """Search what is deepseek r1, and do a comparison between deepseek-r1 and openai o3 mini and let me know the advantages and disadvantages of-openai o3 mini"""--# Get response information-response = camel_agent.step(user_msg)-print(str(response.info['tool_calls'])[:1000])-'''-===============================================================================-[ToolCallingRecord(func_name='search_duckduckgo', args={'query': 'what is-deepseek r1, and do a comparison between deepseek r1 and openai o3 mini',-'source': 'text', 'max_results': 5}, result=[{'result_id': 1, 'title':-'DeepSeek R1 vs OpenAI o1: Which One is Better? - Analytics Vidhya',-'description': "The DeepSeek R1 has arrived, and it's not just another AI-model—it's a significant leap in AI capabilities, trained upon the previously-released DeepSeek-V3-Base variant.With the full-fledged release of DeepSeek-R1, it now stands on par with OpenAI o1 in both performance and flexibility.-What makes it even more compelling is its open weight and MIT licensing,-making it commercially ...", 'url': 'https://www.analyticsvidhya.com/blog/2025/-01/deepseek-r1-vs-openai-o1/'}, {'result_id': 2, 'title': 'DeepSeek-R1:-Features, Use Cases, and Comparison with OpenAI', 'description': 'Where-DeepSeek Shines: Mathematical reasoning and code generation, thanks to-RL-driven CoT.; Where OpenAI Has an...-===============================================================================-'''-print(response.msgs[0].content)-# ruff: noqa: RUF001, E501-'''-===============================================================================-Below is an overview of DeepSeek R1, followed by a comparative analysis with OpenAI’s o3-mini model.--• What is DeepSeek R1?-DeepSeek R1 is an AI model that represents a significant leap in reasoning and language capabilities. It stems from prior iterations like DeepSeek-V3-Base but incorporates additional supervised fine-tuning, enabling improvements in mathematical reasoning, logic, and code generation. One of its major selling points is its open nature—released with an open license (MIT) and open weights—making it highly attractive for research, customization, and commercial applications without the traditional licensing barriers. It has been praised for its affordability (with API usage that can be many times cheaper than some competing models) and has been shown on several benchmarks to hold its own against established models.--• What is OpenAI’s o3-mini?-OpenAI’s o3-mini is part of OpenAI’s reasoning model series and is designed to deliver robust performance specifically in STEM areas such as science, mathematics, and coding. Announced as a response to emerging competition (including DeepSeek R1), o3-mini emphasizes cost efficiency while providing competitive reasoning capabilities. It’s integrated into the ChatGPT ecosystem (with availability on ChatGPT’s enterprise and education platforms) and positions itself as a compact yet powerful option that delivers high-quality reasoning at a lower cost than some earlier OpenAI versions.--• Comparing DeepSeek R1 and OpenAI o3-mini:--1. Performance & Capabilities- – Both models are geared toward advanced reasoning tasks, including problem-solving in STEM subjects and code generation.- – DeepSeek R1 has been lauded for its performance enhancements over previous iterations (especially in areas like mathematical reasoning) thanks to intensive fine-tuning, while independent evaluations have pitted it against other high-end models.- – OpenAI o3-mini is tuned to deliver high-quality reasoning with a focus on speed and cost-effectiveness, often showing particularly strong results in STEM benchmarks.--2. Accessibility and Licensing- – DeepSeek R1 is open source with an MIT license. Its openly available weights make it especially attractive for academic research, startups, or any developer who prefers customizable and transparent AI tools without prohibitive licensing fees.- – In contrast, OpenAI o3-mini is available via OpenAI’s platforms (such as ChatGPT and its API). Users generally access it through a subscription or pay-as-you-go model, with pricing structured to remain competitive against both previous OpenAI models and the emerging open-source alternatives.--3. Cost Efficiency- – DeepSeek R1’s open-source nature generally translates into lower entry costs, making it an economical choice for developers and companies that want to deploy advanced reasoning tools without high API fees.- – OpenAI o3-mini, although designed to be more cost-efficient compared to earlier OpenAI releases, is still part of a managed service infrastructure. According to industry reports, it is significantly cheaper (with some mentions of being up to 63% less expensive than some predecessors) and positioned as a competitive alternative in pricing, but it may still come with usage limits tied to subscription tiers.--4. Ecosystem Integration- – With DeepSeek R1, users have the freedom to run the model in customized environments or integrate it within open-source projects—this flexibility can drive innovation in experimental research or bespoke applications.- – OpenAI o3-mini benefits from OpenAI’s established ecosystem and integration into widely used platforms like ChatGPT Enterprise and Education. Its seamless integration means users can quickly leverage its capabilities without dealing with additional infrastructure setups.--In summary, while both DeepSeek R1 and OpenAI o3-mini aim to push forward the frontier of reasoning and STEM-focused AI models, they serve slightly different audiences. DeepSeek R1’s open-weight, open-license approach makes it ideal for those prioritizing versatility and low-cost research or customized product development. On the other hand, OpenAI o3-mini leverages OpenAI’s ecosystem to offer a highly optimized, cost-effective model that is integrated directly into widely used interfaces and platforms, providing a more out-of-the-box solution for end users and enterprise clients.-===============================================================================-'''diff --git a/examples/models/openai_o3_pro_example.py b/examples/models/openai_o3_pro_example.pydeleted file mode 100644index dbc073ea3..000000000--- a/examples/models/openai_o3_pro_example.py+++ /dev/null@@ -1,64 +0,0 @@-# ========= 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. =========--from camel.agents import ChatAgent-from camel.configs import ChatGPTConfig-from camel.models import ModelFactory-from camel.types import ModelPlatformType, ModelType--# Instantiate the O3_PRO reasoning model-o3_pro_model = ModelFactory.create(- model_platform=ModelPlatformType.OPENAI,- model_type=ModelType.O3_PRO,- model_config_dict=ChatGPTConfig().as_dict(),-)--# Set up the chat agent with the O3_PRO model-camel_agent = ChatAgent(model=o3_pro_model)--# Example user message (multi-step reasoning/logic problem)-user_msg = (- "A farmer has a 3-liter jug and a 5-liter jug. Neither jug has any "- "measurement marks on it. How can the farmer measure exactly 4 liters of "- "water using just these two jugs and unlimited water supply? "- "Explain the steps."-)--# Get response from the agent-response = camel_agent.step(user_msg)-print(response.msgs[0].content)--'''-===============================================================================-Sample Output (O3_PRO Reasoning Model):--To measure exactly 4 liters with a 3-liter and a 5-liter jug:--1. Fill the 5-liter jug completely (5 liters).-2. Pour from the 5-liter jug into the 3-liter jug until the 3-liter jug is- full.- - Now, 5-liter jug has 2 liters left; 3-liter jug has 3 liters.-3. Empty the 3-liter jug.- - Now, 5-liter jug has 2 liters; 3-liter jug is empty.-4. Pour the remaining 2 liters from the 5-liter jug into the 3-liter jug.- - Now, 5-liter jug is empty; 3-liter jug has 2 liters.-5. Fill the 5-liter jug again (5 liters).-6. Pour from the 5-liter jug into the 3-liter jug until the 3-liter jug is- full.- - The 3-liter jug already has 2 liters, so you can add only 1 more liter.- - Now, 5-liter jug has 4 liters left; 3-liter jug is full (3 liters).--**Result:** The 5-liter jug now contains exactly 4 liters of water.-===============================================================================-'''