Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

feat: Simplify Tool setting (#891)

Wendong-Fan5fc6b37fe87b
diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.py
index ca8fd7b68..ce1e55884 100644
--- a/camel/agents/chat_agent.py
+++ b/camel/agents/chat_agent.py
@@ -181,6 +181,16 @@ class ChatAgent(BaseAgent):
tool.get_function_name(): tool.func for tool in all_tools
}
+ # If the user hasn't configured tools in `BaseModelBackend`,
+ # the tools set from `ChatAgent` will be used.
+ # This design simplifies the interface while retaining tool-running
+ # capabilities for `BaseModelBackend`.
+ if all_tools and not self.model_backend.model_config_dict['tools']:
+ tool_schema_list = [
+ tool.get_openai_tool_schema() for tool in all_tools
+ ]
+ self.model_backend.model_config_dict['tools'] = tool_schema_list
+
self.model_config_dict = self.model_backend.model_config_dict
self.model_token_limit = token_limit or self.model_backend.token_limit
diff --git a/docs/tutorials_and_cookbooks/agents_with_tools.md b/docs/tutorials_and_cookbooks/agents_with_tools.md
index f5e4112a7..6725985e8 100644
--- a/docs/tutorials_and_cookbooks/agents_with_tools.md
+++ b/docs/tutorials_and_cookbooks/agents_with_tools.md
@@ -79,7 +79,6 @@ model=ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_3_5_TURBO,
model_config_dict=ChatGPTConfig(
- tools=tool_list,
temperature=0.0,
).as_dict(),
)
@@ -92,7 +91,6 @@ assistant_sys_msg = BaseMessage.make_assistant_message(
# Set the config parameter for the model
assistant_model_config = ChatGPTConfig(
- tools=tool_list,
temperature=0.0,
)
diff --git a/docs/tutorials_and_cookbooks/agents_with_tools_from_Composio.md b/docs/tutorials_and_cookbooks/agents_with_tools_from_Composio.md
index 3b9fb4b61..9066b9f49 100644
--- a/docs/tutorials_and_cookbooks/agents_with_tools_from_Composio.md
+++ b/docs/tutorials_and_cookbooks/agents_with_tools_from_Composio.md
@@ -69,7 +69,7 @@ Set models for user agent and assistant agent, give tool to the assistant
assistant_agent_model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_3_5_TURBO,
- model_config_dict=ChatGPTConfig(tools=tools).as_dict(),
+ model_config_dict=ChatGPTConfig().as_dict(),
)
user_agent_model = ModelFactory.create(
diff --git a/examples/function_call/code_execution.py b/examples/function_call/code_execution.py
index f54cfb401..1b937406b 100644
--- a/examples/function_call/code_execution.py
+++ b/examples/function_call/code_execution.py
@@ -29,7 +29,6 @@ tools = toolkit.get_tools()
# set up LLM model
assistant_model_config = ChatGPTConfig(
temperature=0.0,
- tools=tools,
)
model = ModelFactory.create(
diff --git a/examples/function_call/github_examples.py b/examples/function_call/github_examples.py
index 9fdc2e64a..48ac5b5aa 100644
--- a/examples/function_call/github_examples.py
+++ b/examples/function_call/github_examples.py
@@ -59,9 +59,7 @@ def write_weekly_pr_summary(repo_name, model=None):
of an open source project {repo_name} on the project's blog.
""",
)
- assistant_model_config_dict = ChatGPTConfig(
- tools=[OpenAIFunction(toolkit.retrieve_pull_requests)], temperature=0.0
- ).as_dict()
+ assistant_model_config_dict = ChatGPTConfig(temperature=0.0).as_dict()
assistant_model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
@@ -114,7 +112,6 @@ def solve_issue(
specializes on data structures and algorithms tasks.""",
)
assistant_model_config_dict = ChatGPTConfig(
- tools=toolkit.get_tools(),
temperature=0.0,
).as_dict()
diff --git a/examples/function_call/openapi_function.py b/examples/function_call/openapi_function.py
index 967ca3353..7b1499b61 100644
--- a/examples/function_call/openapi_function.py
+++ b/examples/function_call/openapi_function.py
@@ -26,7 +26,6 @@ sys_msg = BaseMessage.make_assistant_message(
# Set model config
tools = OpenAPIToolkit().get_tools()
model_config_dict = ChatGPTConfig(
- tools=tools,
temperature=0.0,
).as_dict()
@@ -40,7 +39,7 @@ model = ModelFactory.create(
camel_agent = ChatAgent(
system_message=sys_msg,
model=model,
- tools=OpenAPIToolkit().get_tools(),
+ tools=tools,
)
camel_agent.reset()
diff --git a/examples/function_call/role_playing_with_functions.py b/examples/function_call/role_playing_with_functions.py
index 873ceecf6..aef45236d 100644
--- a/examples/function_call/role_playing_with_functions.py
+++ b/examples/function_call/role_playing_with_functions.py
@@ -48,7 +48,6 @@ def main(
*SearchToolkit().get_tools(),
]
assistant_model_config = ChatGPTConfig(
- tools=tools_list,
temperature=0.0,
)
diff --git a/examples/models/role_playing_with_mistral.py b/examples/models/role_playing_with_mistral.py
index e1df143ac..ef752b29b 100644
--- a/examples/models/role_playing_with_mistral.py
+++ b/examples/models/role_playing_with_mistral.py
@@ -46,7 +46,6 @@ def main(
*SearchToolkit().get_tools(),
]
assistant_model_config = MistralConfig(
- tools=tools_list,
temperature=0.2,
)
diff --git a/examples/models/samba_model_example.py b/examples/models/samba_model_example.py
index afb8c3ad0..64fd53dad 100644
--- a/examples/models/samba_model_example.py
+++ b/examples/models/samba_model_example.py
@@ -37,7 +37,7 @@ sambaverse_api_model = ModelFactory.create(
url="https://sambaverse.sambanova.ai/api/predict",
)
-sambacloud_api_model = ModelFactory.create(
+samba_cloud_api_model = ModelFactory.create(
model_platform=ModelPlatformType.SAMBA,
model_type="Meta-Llama-3.1-405B-Instruct",
model_config_dict=SambaCloudAPIConfig(max_tokens=800).as_dict(),
@@ -68,8 +68,8 @@ camel_agent_sambaverse_api = ChatAgent(
system_message=sys_msg, model=sambaverse_api_model
)
-camel_agent_sambacloud_api = ChatAgent(
- system_message=sys_msg, model=sambacloud_api_model
+camel_agent_samba_cloud_api = ChatAgent(
+ system_message=sys_msg, model=samba_cloud_api_model
)
# Get response information
@@ -103,7 +103,7 @@ of assistance.
'''
# Get response information
-response = camel_agent_sambacloud_api.step(user_msg)
+response = camel_agent_samba_cloud_api.step(user_msg)
print(response.msgs[0].content)
'''
===============================================================================
diff --git a/examples/observability/agentops_track_roleplaying_with_function.py b/examples/observability/agentops_track_roleplaying_with_function.py
index 6d86334ee..fe4d5e4eb 100644
--- a/examples/observability/agentops_track_roleplaying_with_function.py
+++ b/examples/observability/agentops_track_roleplaying_with_function.py
@@ -53,7 +53,6 @@ tools_list = [
*SearchToolkit().get_tools(),
]
assistant_model_config = ChatGPTConfig(
- tools=tools_list,
temperature=0.0,
)
diff --git a/examples/structured_response/json_format_reponse_with_tools.py b/examples/structured_response/json_format_reponse_with_tools.py
index 8e5a20ee0..03cb662fc 100644
--- a/examples/structured_response/json_format_reponse_with_tools.py
+++ b/examples/structured_response/json_format_reponse_with_tools.py
@@ -29,7 +29,6 @@ tools_list = [
*SearchToolkit().get_tools(),
]
assistant_model_config = ChatGPTConfig(
- tools=tools_list,
temperature=0.0,
)
diff --git a/examples/vision/image_crafting.py b/examples/vision/image_crafting.py
index 389be2dce..1a3c3df48 100644
--- a/examples/vision/image_crafting.py
+++ b/examples/vision/image_crafting.py
@@ -43,12 +43,10 @@ def main():
content="Draw a picture of a camel.",
)
- model_config = ChatGPTConfig(tools=DalleToolkit().get_tools())
-
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
- model_config_dict=model_config.as_dict(),
+ model_config_dict=ChatGPTConfig().as_dict(),
)
dalle_agent = ChatAgent(
diff --git a/examples/vision/multi_condition_image_crafting.py b/examples/vision/multi_condition_image_crafting.py
index 966717646..89ef9885f 100644
--- a/examples/vision/multi_condition_image_crafting.py
+++ b/examples/vision/multi_condition_image_crafting.py
@@ -40,12 +40,10 @@ def main(image_paths: list[str]) -> list[str]:
content=sys_msg,
)
- model_config = ChatGPTConfig(tools=DalleToolkit().get_tools())
-
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
- model_config_dict=model_config.as_dict(),
+ model_config_dict=ChatGPTConfig().as_dict(),
)
dalle_agent = ChatAgent(
diff --git a/examples/vision/multi_turn_image_refining.py b/examples/vision/multi_turn_image_refining.py
index 764093c13..4a9ef1c2f 100644
--- a/examples/vision/multi_turn_image_refining.py
+++ b/examples/vision/multi_turn_image_refining.py
@@ -68,13 +68,10 @@ PROMPT: here is the updated prompt!
def init_agents(self):
r"""Initialize artist and critic agents with their system messages."""
-
- model_config = ChatGPTConfig(tools=DalleToolkit().get_tools())
-
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
- model_config_dict=model_config.as_dict(),
+ model_config_dict=ChatGPTConfig().as_dict(),
)
self.artist = ChatAgent(
diff --git a/examples/workforce/multiple_single_agents.py b/examples/workforce/multiple_single_agents.py
index 32c16238d..ecd28d6ad 100644
--- a/examples/workforce/multiple_single_agents.py
+++ b/examples/workforce/multiple_single_agents.py
@@ -33,7 +33,6 @@ def main():
]
# configure the model of tool_agent
model_config_dict = ChatGPTConfig(
- tools=tools_list,
temperature=0.0,
).as_dict()
diff --git a/examples/workforce/role_playing_with_agents.py b/examples/workforce/role_playing_with_agents.py
index 2903da521..0efeabe53 100644
--- a/examples/workforce/role_playing_with_agents.py
+++ b/examples/workforce/role_playing_with_agents.py
@@ -49,7 +49,6 @@ def main():
]
user_model_config = ChatGPTConfig(temperature=0.0)
assistant_model_config = ChatGPTConfig(
- tools=tools_list,
temperature=0.0,
)
model_platform = ModelPlatformType.OPENAI
diff --git a/test/agents/test_chat_agent.py b/test/agents/test_chat_agent.py
index a64445382..01f6860cc 100644
--- a/test/agents/test_chat_agent.py
+++ b/test/agents/test_chat_agent.py
@@ -421,11 +421,10 @@ def test_function_enabled():
meta_dict=None,
content="You are a help assistant.",
)
- model_config = ChatGPTConfig(tools=MathToolkit().get_tools())
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
- model_config_dict=model_config.as_dict(),
+ model_config_dict=ChatGPTConfig().as_dict(),
)
agent_no_func = ChatAgent(system_message=system_message)
agent_with_funcs = ChatAgent(
@@ -446,11 +445,10 @@ def test_tool_calling_sync():
meta_dict=None,
content="You are a help assistant.",
)
- model_config = ChatGPTConfig(tools=MathToolkit().get_tools())
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
- model_config_dict=model_config.as_dict(),
+ model_config_dict=ChatGPTConfig().as_dict(),
)
agent = ChatAgent(
system_message=system_message,
@@ -492,11 +490,10 @@ async def test_tool_calling_math_async():
content="You are a help assistant.",
)
math_funcs = sync_funcs_to_async(MathToolkit().get_tools())
- model_config = ChatGPTConfig(tools=[*math_funcs])
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
- model_config_dict=model_config.as_dict(),
+ model_config_dict=ChatGPTConfig().as_dict(),
)
agent = ChatAgent(
system_message=system_message,
@@ -548,12 +545,10 @@ async def test_tool_calling_async():
await asyncio.sleep(second)
return second
- model_config = ChatGPTConfig(tools=[OpenAIFunction(async_sleep)])
-
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
- model_config_dict=model_config.as_dict(),
+ model_config_dict=ChatGPTConfig().as_dict(),
)
agent = ChatAgent(
diff --git a/test/agents/test_role_playing.py b/test/agents/test_role_playing.py
index 72acf3ff6..b6a68a739 100644
--- a/test/agents/test_role_playing.py
+++ b/test/agents/test_role_playing.py
@@ -138,11 +138,10 @@ def test_role_playing_step(
@pytest.mark.model_backend
def test_role_playing_with_function():
tools = MathToolkit().get_tools()
- assistant_model_config = ChatGPTConfig(tools=tools)
model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O_MINI,
- model_config_dict=assistant_model_config.as_dict(),
+ model_config_dict=ChatGPTConfig().as_dict(),
)
role_playing = RolePlaying(