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+ import os
16+
17+ from camel .agents import ChatAgent
18+ from camel .models import ModelFactory
19+ from camel .toolkits import TerminalToolkit
20+ from camel .types import ModelPlatformType , ModelType
21+
22+ # Get current script directory
23+ base_dir = os .path .dirname (os .path .abspath (__file__ ))
24+ # Define workspace directory for the toolkit
25+ workspace_dir = os .path .join (
26+ os .path .dirname (os .path .dirname (base_dir )), "workspace"
27+ )
28+
29+ # Define system message
30+ sys_msg = (
31+ "You are a System Administrator helping with log management tasks. "
32+ "You have access to terminal tools that can help you execute "
33+ "shell commands and search files. "
34+ )
35+
36+ # Set model config
37+ tools = TerminalToolkit (working_directory = workspace_dir ).get_tools ()
38+
39+
40+ model = ModelFactory .create (
41+ model_platform = ModelPlatformType .OPENAI ,
42+ model_type = ModelType .GPT_3_5_TURBO ,
43+ )
44+
45+ # Set agent
46+ camel_agent = ChatAgent (
47+ system_message = sys_msg ,
48+ model = model ,
49+ tools = tools ,
50+ summarize_threshold = 1 ,
51+ summary_window_ratio = 0.02
52+ )
53+ camel_agent .reset ()
54+
55+ # Define a user message for creating logs directory
56+ usr_msg = (
57+ f"Create a 'logs' directory in '{ workspace_dir } ' and list its contents"
58+ )
59+
60+ # simulate a long conversation
61+ for i in range (20 ):
62+ response = camel_agent .step (usr_msg )
63+ print (camel_agent ._summary_token_count )
64+
65+ #handle a large file
66+ usr_msg = (
67+ f"../../uv.lock,read this file"
68+ )
69+
70+ response = camel_agent .step (usr_msg )
0 commit comments