Skip to content

Commit 56b40d1

Browse files
feat(models): Add Claude Sonnet 4.5 support (#3229)
Co-authored-by: Wendong-Fan <133094783+Wendong-Fan@users.noreply.github.com>
1 parent ab66bd1 commit 56b40d1

File tree

4 files changed

+119
-1
lines changed

4 files changed

+119
-1
lines changed

camel/types/enums.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class ModelType(UnifiedModelType, Enum):
207207
CLAUDE_3_5_SONNET = "claude-3-5-sonnet-latest"
208208
CLAUDE_3_5_HAIKU = "claude-3-5-haiku-latest"
209209
CLAUDE_3_7_SONNET = "claude-3-7-sonnet-latest"
210+
CLAUDE_4_5_SONNET = "claude-4-5-sonnet-latest"
210211
CLAUDE_SONNET_4 = "claude-sonnet-4-20250514"
211212
CLAUDE_OPUS_4 = "claude-opus-4-20250514"
212213
CLAUDE_OPUS_4_1 = "claude-opus-4-1-20250805"
@@ -641,6 +642,7 @@ def is_anthropic(self) -> bool:
641642
ModelType.CLAUDE_3_5_SONNET,
642643
ModelType.CLAUDE_3_5_HAIKU,
643644
ModelType.CLAUDE_3_7_SONNET,
645+
ModelType.CLAUDE_4_5_SONNET,
644646
ModelType.CLAUDE_SONNET_4,
645647
ModelType.CLAUDE_OPUS_4,
646648
ModelType.CLAUDE_OPUS_4_1,
@@ -1421,6 +1423,7 @@ def token_limit(self) -> int:
14211423
ModelType.CLAUDE_3_5_SONNET,
14221424
ModelType.CLAUDE_3_5_HAIKU,
14231425
ModelType.CLAUDE_3_7_SONNET,
1426+
ModelType.CLAUDE_4_5_SONNET,
14241427
ModelType.CLAUDE_SONNET_4,
14251428
ModelType.CLAUDE_OPUS_4,
14261429
ModelType.CLAUDE_OPUS_4_1,

docs/mintlify/key_modules/models.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ CAMEL supports a wide range of models, including [OpenAI’s GPT series](https:/
4040
| **Azure OpenAI** | gpt-4o, gpt-4-turbo<br/>gpt-4, gpt-3.5-turbo |
4141
| **Mistral AI** | mistral-large-latest, pixtral-12b-2409<br/>ministral-8b-latest, ministral-3b-latest<br/>open-mistral-nemo, codestral-latest<br/>open-mistral-7b, open-mixtral-8x7b<br/>open-mixtral-8x22b, open-codestral-mamba<br/>mistral-small-2506, mistral-medium-2508<br/>magistral-small-1.2, magistral-medium-1.2 |
4242
| **Moonshot** | moonshot-v1-8k<br/>moonshot-v1-32k<br/>moonshot-v1-128k |
43-
| **Anthropic** | claude-2.1, claude-2.0, claude-instant-1.2<br/>claude-3-opus-latest, claude-3-sonnet-20240229, claude-3-haiku-20240307<br/>claude-3-5-sonnet-latest, claude-3-5-haiku-latest |
43+
| **Anthropic** | claude-2.1, claude-2.0, claude-instant-1.2<br/>claude-3-opus-latest, claude-3-sonnet-20240229, claude-3-haiku-20240307<br/>claude-3-5-sonnet-latest, claude-3-5-haiku-latest, claude-3-7-sonnet-latest<br/>claude-4-5-sonnet-latest, claude-sonnet-4-20250514, claude-opus-4-20250514, claude-opus-4-1-20250805 |
4444
| **Gemini** | gemini-2.5-pro, gemini-2.5-flash<br/>gemini-2.0-flash, gemini-2.0-flash-thinking<br/> gemini-2.0-flash-lite|
4545
| **Lingyiwanwu** | yi-lightning, yi-large, yi-medium<br/>yi-large-turbo, yi-vision, yi-medium-200k<br/>yi-spark, yi-large-rag, yi-large-fc |
4646
| **Qwen** | qwen3-coder-plus,qwq-32b-preview, qwen-max, qwen-plus, qwen-turbo, qwen-long<br/>qwen-vl-max, qwen-vl-plus, qwen-math-plus, qwen-math-turbo, qwen-coder-turbo<br/>qwen2.5-coder-32b-instruct, qwen2.5-72b-instruct, qwen2.5-32b-instruct, qwen2.5-14b-instruct |
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14+
15+
from camel.agents import ChatAgent
16+
from camel.configs import AnthropicConfig
17+
from camel.models import ModelFactory
18+
from camel.toolkits import FunctionTool
19+
from camel.types import ModelPlatformType, ModelType
20+
21+
"""
22+
Claude Sonnet 4.5 Example
23+
24+
Please set the environment variable:
25+
export ANTHROPIC_API_KEY="your-api-key-here"
26+
"""
27+
28+
print("Testing Claude Sonnet 4.5 Integration...")
29+
30+
# Create Claude Sonnet 4.5 model
31+
model = ModelFactory.create(
32+
model_platform=ModelPlatformType.ANTHROPIC,
33+
model_type=ModelType.CLAUDE_4_5_SONNET,
34+
model_config_dict=AnthropicConfig(temperature=0.2).as_dict(),
35+
)
36+
37+
# Define system message
38+
sys_msg = "You are a helpful AI assistant powered by Claude Sonnet 4.5."
39+
40+
# Set agent
41+
camel_agent = ChatAgent(system_message=sys_msg, model=model)
42+
43+
print(f"Model Type: {model.model_type}")
44+
print(f"Model Platform: {ModelPlatformType.ANTHROPIC}")
45+
print(f"Is Anthropic: {model.model_type.is_anthropic}")
46+
print(f"Token Limit: {model.model_type.token_limit}")
47+
48+
# Test basic conversation
49+
user_msg = """Hello Claude Sonnet 4.5! Can you tell me about your \
50+
capabilities and how you differ from previous versions?"""
51+
52+
print(f"\nUser: {user_msg}")
53+
print("Assistant:", end=" ")
54+
55+
try:
56+
response = camel_agent.step(user_msg)
57+
print(response.msgs[0].content)
58+
print("\n✅ Basic conversation test PASSED")
59+
except Exception as e:
60+
print(f"\n❌ Basic conversation test FAILED: {e}")
61+
62+
63+
# Test with tool calling
64+
def calculate_circle_area(radius: float) -> float:
65+
"""Calculate the area of a circle given its radius."""
66+
import math
67+
68+
return math.pi * radius * radius
69+
70+
71+
# Create agent with tools
72+
tool_agent = ChatAgent(
73+
system_message=sys_msg,
74+
model=model,
75+
tools=[FunctionTool(calculate_circle_area)],
76+
)
77+
78+
print("\n" + "=" * 50)
79+
print("Testing Claude Sonnet 4.5 with tool calling:")
80+
81+
user_msg = (
82+
"Please use the calculate_circle_area tool to find the area "
83+
"of a circle with radius 5."
84+
)
85+
86+
print(f"\nUser: {user_msg}")
87+
print("Assistant:", end=" ")
88+
89+
try:
90+
response = tool_agent.step(user_msg)
91+
print(response.msgs[0].content)
92+
93+
# Check if tool was called
94+
if response.info and response.info.get("tool_calls"):
95+
print("\n✅ Tool calling test PASSED")
96+
print(f"Tool calls: {response.info['tool_calls']}")
97+
else:
98+
print(
99+
"\n⚠️ Tool calling may not have been used (expected for this test)"
100+
)
101+
102+
except Exception as e:
103+
print(f"\n❌ Tool calling test FAILED: {e}")
104+
105+
print("\n" + "=" * 50)
106+
print("Claude Sonnet 4.5 integration test completed!")
107+
print(
108+
"If you see this message without errors, "
109+
"the integration is working correctly."
110+
)

test/models/test_anthropic_model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
ModelType.CLAUDE_3_HAIKU,
3333
ModelType.CLAUDE_3_5_SONNET,
3434
ModelType.CLAUDE_3_5_HAIKU,
35+
ModelType.CLAUDE_3_7_SONNET,
36+
ModelType.CLAUDE_4_5_SONNET,
37+
ModelType.CLAUDE_SONNET_4,
38+
ModelType.CLAUDE_OPUS_4,
39+
ModelType.CLAUDE_OPUS_4_1,
3540
],
3641
)
3742
def test_anthropic_model(model_type: ModelType):

0 commit comments

Comments
 (0)