🐫 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 Claude 4 (#2463)
Wendong-Fanf16fab1d56d2
diff --git a/camel/configs/anthropic_config.py b/camel/configs/anthropic_config.pyindex f1b00ad09..6847d0e17 100644--- a/camel/configs/anthropic_config.py+++ b/camel/configs/anthropic_config.py@@ -56,14 +56,14 @@ class AnthropicConfig(BaseConfig):metadata about the request. Can include user_id as an externalidentifier for the user associated with the request.(default: :obj:`None`)- thinking (dict, optional): Configuration for enabling- Claude's extended thinking. When enabled, responses include- thinking content blocks showing Claude's thinking process.- (default: :obj:`None`)tool_choice (dict, optional): How the model shoulduse the provided tools. The model can use a specific tool, anyavailable tool, decide by itself, or not use tools at all.(default: :obj:`None`)+ extra_headers (Optional[dict], optional): Additional headers for the+ request. (default: :obj:`None`)+ extra_body (dict, optional): Extra body parameters to be passed to+ the Anthropic API."""max_tokens: Optional[int] = None@@ -73,8 +73,9 @@ class AnthropicConfig(BaseConfig):top_k: Optional[int] = Nonestream: Optional[bool] = Nonemetadata: Optional[dict] = None- thinking: Optional[dict] = Nonetool_choice: Optional[dict] = None+ extra_headers: Optional[dict] = None+ extra_body: Optional[dict] = NoneANTHROPIC_API_PARAMS = {param for param in AnthropicConfig.model_fields.keys()}diff --git a/camel/types/enums.py b/camel/types/enums.pyindex 580cea4a7..f6171ddef 100644--- a/camel/types/enums.py+++ b/camel/types/enums.py@@ -56,6 +56,8 @@ class ModelType(UnifiedModelType, Enum):AWS_LLAMA_3_3_70B_INSTRUCT = "us.meta.llama3-3-70b-instruct-v1:0"AWS_LLAMA_3_2_90B_INSTRUCT = "us.meta.llama3-2-90b-instruct-v1:0"AWS_LLAMA_3_2_11B_INSTRUCT = "us.meta.llama3-2-11b-instruct-v1:0"+ AWS_CLAUDE_SONNET_4 = "anthropic.claude-sonnet-4-20250514-v1:0"+ AWS_CLAUDE_OPUS_4 = "anthropic.claude-opus-4-20250514-v1:0"GLM_4 = "glm-4"GLM_4V = "glm-4v"@@ -145,13 +147,15 @@ class ModelType(UnifiedModelType, Enum):CLAUDE_2_0 = "claude-2.0"CLAUDE_INSTANT_1_2 = "claude-instant-1.2"- # Claude3 models+ # Claude modelsCLAUDE_3_OPUS = "claude-3-opus-latest"CLAUDE_3_SONNET = "claude-3-sonnet-20240229"CLAUDE_3_HAIKU = "claude-3-haiku-20240307"CLAUDE_3_5_SONNET = "claude-3-5-sonnet-latest"CLAUDE_3_5_HAIKU = "claude-3-5-haiku-latest"CLAUDE_3_7_SONNET = "claude-3-7-sonnet-latest"+ CLAUDE_SONNET_4 = "claude-sonnet-4-20250514"+ CLAUDE_OPUS_4 = "claude-opus-4-20250514"# Netmind modelsNETMIND_LLAMA_4_MAVERICK_17B_128E_INSTRUCT = (@@ -469,6 +473,8 @@ class ModelType(UnifiedModelType, Enum):ModelType.AWS_LLAMA_3_3_70B_INSTRUCT,ModelType.AWS_LLAMA_3_2_90B_INSTRUCT,ModelType.AWS_LLAMA_3_2_11B_INSTRUCT,+ ModelType.AWS_CLAUDE_SONNET_4,+ ModelType.AWS_CLAUDE_OPUS_4,}@property@@ -530,6 +536,8 @@ class ModelType(UnifiedModelType, Enum):ModelType.CLAUDE_3_5_SONNET,ModelType.CLAUDE_3_5_HAIKU,ModelType.CLAUDE_3_7_SONNET,+ ModelType.CLAUDE_SONNET_4,+ ModelType.CLAUDE_OPUS_4,}@property@@ -1162,11 +1170,15 @@ class ModelType(UnifiedModelType, Enum):ModelType.CLAUDE_3_5_SONNET,ModelType.CLAUDE_3_5_HAIKU,ModelType.CLAUDE_3_7_SONNET,+ ModelType.CLAUDE_SONNET_4,+ ModelType.CLAUDE_OPUS_4,ModelType.YI_MEDIUM_200K,ModelType.AWS_CLAUDE_3_5_SONNET,ModelType.AWS_CLAUDE_3_HAIKU,ModelType.AWS_CLAUDE_3_SONNET,ModelType.AWS_CLAUDE_3_7_SONNET,+ ModelType.AWS_CLAUDE_SONNET_4,+ ModelType.AWS_CLAUDE_OPUS_4,ModelType.O4_MINI,ModelType.O3,}:diff --git a/examples/models/anthiropic_model_example.py b/examples/models/anthiropic_model_example.pyindex 7a2ca9517..2cc68129f 100644--- a/examples/models/anthiropic_model_example.py+++ b/examples/models/anthiropic_model_example.py@@ -15,6 +15,7 @@from camel.agents import ChatAgentfrom camel.configs import AnthropicConfigfrom camel.models import ModelFactory+from camel.toolkits import FunctionToolfrom camel.types import ModelPlatformType, ModelType"""@@ -46,22 +47,15 @@ Hi CAMEL AI! It's great to meet an open-source community focused on advancing re===============================================================================''' # noqa: E501-# Use the extended thinking model with Claude 3.7 Sonnet-config = AnthropicConfig(- thinking={"type": "enabled", "budget_tokens": 2048}-).as_dict()-model = ModelFactory.create(model_platform=ModelPlatformType.ANTHROPIC,model_type=ModelType.CLAUDE_3_7_SONNET,- model_config_dict=config,)camel_agent = ChatAgent(model=model)-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.-""" # noqa: E501+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."""response = camel_agent.step(user_msg)print(response.msgs[0].content)@@ -69,7 +63,8 @@ print(response.msgs[0].content)===============================================================================# Matrix Transpose Bash Script-Here's a bash script that transposes a matrix from the format `[1,2],[3,4],[5,6]` to `[1,3,5],[2,4,6]`:+Here's a bash script that transposes a matrix from the format `[1,2],[3,4],[5,+6]` to `[1,3,5],[2,4,6]`:```bash#!/bin/bash@@ -91,7 +86,8 @@ IFS='|' read -ra rows <<< "$input"# Determine dimensions of the matrixrow_count="${#rows[@]}"-IFS=',' read -ra first_row <<< "${rows[0]//[\[\]]}" # Remove brackets from first row+IFS=',' read -ra first_row <<< "${rows[0]//[\[\]]}" # Remove brackets from+first rowcol_count="${#first_row[@]}"# Create transpose@@ -135,14 +131,8 @@ The script works by:2. Finding the dimensions of the original matrix3. Creating the transpose by iterating through columns first, then rows4. Formatting the result with proper brackets and commas-''' # noqa: E501--# Tool calling-from camel.agents import ChatAgent # noqa: E402-from camel.configs import AnthropicConfig # noqa: E402-from camel.models import ModelFactory # noqa: E402-from camel.toolkits import FunctionTool # noqa: E402-from camel.types import ModelPlatformType, ModelType # noqa: E402+===============================================================================+'''def my_add(a: int, b: int) -> int:@@ -166,7 +156,9 @@ user_msg = "Use the tool my_add to calculate 2 + 2"response = anthropic_agent.step(user_msg)print(response.msgs[0].content)"""+===============================================================================The result of adding 2 + 2 is 4.+==============================================================================="""# Check if tool was called@@ -177,6 +169,63 @@ else:print("No tool calls were made.")"""+===============================================================================Tool was called successfully!-Tool calls: [ToolCallingRecord(tool_name='my_add', args={'a': 2, 'b': 2}, result=4, tool_call_id='toolu_01L1KV8GZtMEyHUGTudpMg5g')]-""" # noqa: E501+Tool calls: [ToolCallingRecord(tool_name='my_add', args={'a': 2, 'b': 2},+result=4, tool_call_id='toolu_01L1KV8GZtMEyHUGTudpMg5g')]+===============================================================================+"""++model = ModelFactory.create(+ model_platform=ModelPlatformType.ANTHROPIC,+ model_type=ModelType.CLAUDE_SONNET_4,+ model_config_dict={+ "extra_body": {"thinking": {"type": "enabled", "budget_tokens": 2000}}+ },+)++camel_agent = ChatAgent(model=model)++user_msg = """Are there an infinite number of prime numbers such that n mod 4+== 3?"""++response = camel_agent.step(user_msg)+print(response.msgs[0].content)++"""+===============================================================================+Yes, there are infinitely many prime numbers that are congruent to 3 modulo 4.++This can be proven using a technique similar to Euclid's proof of the+infinitude of primes. Here's the proof:++**Proof by contradiction:**++Assume there are only finitely many primes of the form 4k + 3. Let's call them+p₁, p₂, ..., pₙ where each pᵢ ≡ 3 (mod 4).++Consider the number N = 4(p₁ × p₂ × ... × pₙ) - 1.++Note that N ≡ 3 (mod 4) since 4(p₁ × p₂ × ... × pₙ) ≡ 0 (mod 4), so N ≡ -1 ≡ 3+(mod 4).++Now, N must have at least one prime factor. We know that:+- N is not divisible by any of the primes p₁, p₂, ..., pₙ (since N ≡ -1 (mod+pᵢ) for each i)+- N cannot be divisible only by primes of the form 4k + 1, because the product+of numbers that are ≡ 1 (mod 4) is also ≡ 1 (mod 4), but N ≡ 3 (mod 4)++Therefore, N must have at least one prime factor that is congruent to 3 modulo+4, and this prime factor is different from all the primes in our assumed+finite list.++This contradicts our assumption that p₁, p₂, ..., pₙ were all the primes+congruent to 3 modulo 4.++Therefore, there must be infinitely many primes of the form 4k + 3.++This result is part of **Dirichlet's theorem on arithmetic progressions**,+which more generally states that for any arithmetic progression an + b where+gcd(a,b) = 1, there are infinitely many primes in that progression.+===============================================================================+""" # noqa: RUF001