From 155df1d7fd62d7cb645e32e2b1a4f06ee8896037 Mon Sep 17 00:00:00 2001 From: JINO-ROHIT Date: Thu, 23 Jan 2025 15:36:18 +0530 Subject: [PATCH 1/8] rename tool call instances --- camel/agents/chat_agent.py | 36 +++++++++---------- .../advanced_features/agents_tracking.ipynb | 4 +-- .../advanced_features/agents_with_rag.ipynb | 6 ++-- .../advanced_features/agents_with_tools.ipynb | 4 +-- .../agents_with_tools_from_Composio.ipynb | 4 +-- .../applications/dynamic_travel_planner.ipynb | 6 ++-- .../applications/roleplaying_scraper.ipynb | 6 ++-- examples/models/role_playing_with_cohere.py | 6 ++-- examples/models/role_playing_with_mistral.py | 6 ++-- examples/models/role_playing_with_ollama.py | 6 ++-- .../models/role_playing_with_sambanova.py | 6 ++-- ...gentops_track_roleplaying_with_function.py | 6 ++-- examples/toolkits/arxiv_toolkit.py | 4 +-- examples/toolkits/google_scholar_toolkit.py | 8 ++--- examples/toolkits/notion_toolkit.py | 6 ++-- examples/toolkits/openapi_toolkit.py | 2 +- .../toolkits/role_playing_with_functions.py | 6 ++-- test/agents/test_chat_agent.py | 4 +-- 18 files changed, 63 insertions(+), 63 deletions(-) diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.py index 49c8ea650f..f78fda6588 100644 --- a/camel/agents/chat_agent.py +++ b/camel/agents/chat_agent.py @@ -86,7 +86,7 @@ from camel.utils import track_agent -class FunctionCallingRecord(BaseModel): +class ToolCallingRecord(BaseModel): r"""Historical records of functions called in the conversation. Attributes: @@ -489,7 +489,7 @@ def get_info( usage: Optional[Dict[str, int]], termination_reasons: List[str], num_tokens: int, - tool_calls: List[FunctionCallingRecord], + tool_calls: List[ToolCallingRecord], external_tool_request: Optional[ChatCompletionMessageToolCall] = None, ) -> Dict[str, Any]: r"""Returns a dictionary containing information about the chat session. @@ -501,7 +501,7 @@ def get_info( termination_reasons (List[str]): The reasons for the termination of the chat session. num_tokens (int): The number of tokens used in the chat session. - tool_calls (List[FunctionCallingRecord]): The list of function + tool_calls (List[ToolCallingRecord]): The list of function calling records, containing the information of called tools. external_tool_request (Optional[ChatCompletionMessageToolCall], optional): @@ -645,7 +645,7 @@ def _handle_step( ) # Record function calls made during the session - tool_call_records: List[FunctionCallingRecord] = [] + tool_call_records: List[ToolCallingRecord] = [] external_tool_request = None @@ -885,7 +885,7 @@ async def step_async( self.update_memory(input_message, OpenAIBackendRole.USER) - tool_call_records: List[FunctionCallingRecord] = [] + tool_call_records: List[ToolCallingRecord] = [] while True: try: openai_messages, num_tokens = self.memory.get_context() @@ -970,7 +970,7 @@ async def step_async( def _step_tool_call_and_update( self, response: ChatCompletion - ) -> FunctionCallingRecord: + ) -> ToolCallingRecord: r"""Processes a function call within the chat completion response, records the function call in the provided list of tool calls and updates the memory of the current agent. @@ -980,7 +980,7 @@ def _step_tool_call_and_update( completion. Returns: - FunctionCallingRecord: The record of calling the function. + ToolCallingRecord: The record of calling the function. """ # Perform function calling @@ -996,7 +996,7 @@ def _step_tool_call_and_update( async def _step_tool_call_and_update_async( self, response: ChatCompletion - ) -> FunctionCallingRecord: + ) -> ToolCallingRecord: ( func_assistant_msg, func_result_msg, @@ -1015,7 +1015,7 @@ def _structure_output_with_function( List[str], Dict[str, int], str, - FunctionCallingRecord, + ToolCallingRecord, int, ]: r"""Internal function of structuring the output of the agent based on @@ -1027,7 +1027,7 @@ def _structure_output_with_function( Returns: Tuple[List[BaseMessage], List[str], Dict[str, int], str, - FunctionCallingRecord, int]: + ToolCallingRecord, int]: A tuple containing the output messages, finish reasons, usage dictionary, response ID, function calling record, and number of tokens. @@ -1141,7 +1141,7 @@ def _step_get_info( finish_reasons: List[str], usage_dict: Dict[str, int], response_id: str, - tool_calls: List[FunctionCallingRecord], + tool_calls: List[ToolCallingRecord], num_tokens: int, external_tool_request: Optional[ChatCompletionMessageToolCall] = None, ) -> Dict[str, Any]: @@ -1160,7 +1160,7 @@ def _step_get_info( usage_dict (Dict[str, int]): Dictionary containing token usage information. response_id (str): The ID of the response from the model. - tool_calls (List[FunctionCallingRecord]): Records of function calls + tool_calls (List[ToolCallingRecord]): Records of function calls made during this step. num_tokens (int): The number of tokens used in this step. external_tool_request (Optional[ChatCompletionMessageToolCall]): @@ -1335,7 +1335,7 @@ def handle_stream_response( def _step_token_exceed( self, num_tokens: int, - tool_calls: List[FunctionCallingRecord], + tool_calls: List[ToolCallingRecord], termination_reason: str, ) -> ChatAgentResponse: r"""Return trivial response containing number of tokens and information @@ -1343,7 +1343,7 @@ def _step_token_exceed( Args: num_tokens (int): Number of tokens in the messages. - tool_calls (List[FunctionCallingRecord]): List of information + tool_calls (List[ToolCallingRecord]): List of information objects of functions called in the current step. termination_reason (str): String of termination reason. @@ -1372,7 +1372,7 @@ def _step_tool_call( self, response: ChatCompletion, ) -> Tuple[ - FunctionCallingMessage, FunctionCallingMessage, FunctionCallingRecord + FunctionCallingMessage, FunctionCallingMessage, ToolCallingRecord ]: r"""Execute the function with arguments following the model's response. @@ -1418,7 +1418,7 @@ def _step_tool_call( ) # Record information about this function call - func_record = FunctionCallingRecord( + func_record = ToolCallingRecord( func_name=func_name, args=args, result=result, @@ -1442,7 +1442,7 @@ async def step_tool_call_async( self, response: ChatCompletion, ) -> Tuple[ - FunctionCallingMessage, FunctionCallingMessage, FunctionCallingRecord + FunctionCallingMessage, FunctionCallingMessage, ToolCallingRecord ]: r"""Execute the async function with arguments following the model's response. @@ -1488,7 +1488,7 @@ async def step_tool_call_async( ) # Record information about this function call - func_record = FunctionCallingRecord( + func_record = ToolCallingRecord( func_name=func_name, args=args, result=result, diff --git a/docs/cookbooks/advanced_features/agents_tracking.ipynb b/docs/cookbooks/advanced_features/agents_tracking.ipynb index 6de324495f..09e0dd311f 100644 --- a/docs/cookbooks/advanced_features/agents_tracking.ipynb +++ b/docs/cookbooks/advanced_features/agents_tracking.ipynb @@ -356,7 +356,7 @@ "\n", "from colorama import Fore\n", "\n", - "from camel.agents.chat_agent import FunctionCallingRecord\n", + "from camel.agents.chat_agent import ToolCallingRecord\n", "from camel.configs import ChatGPTConfig\n", "from camel.models import ModelFactory\n", "from camel.societies import RolePlaying\n", @@ -765,7 +765,7 @@ " # Print output from the assistant, including any function\n", " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n", - " tool_calls: List[FunctionCallingRecord] = assistant_response.info[\n", + " tool_calls: List[ToolCallingRecord] = assistant_response.info[\n", " 'tool_calls'\n", " ]\n", " for func_record in tool_calls:\n", diff --git a/docs/cookbooks/advanced_features/agents_with_rag.ipynb b/docs/cookbooks/advanced_features/agents_with_rag.ipynb index 7d3bb26a82..25f0b8c9e9 100644 --- a/docs/cookbooks/advanced_features/agents_with_rag.ipynb +++ b/docs/cookbooks/advanced_features/agents_with_rag.ipynb @@ -474,7 +474,7 @@ "from typing import List\n", "from colorama import Fore\n", "\n", - "from camel.agents.chat_agent import FunctionCallingRecord\n", + "from camel.agents.chat_agent import ToolCallingRecord\n", "from camel.configs import ChatGPTConfig\n", "from camel.toolkits import (\n", " MathToolkit,\n", @@ -568,8 +568,8 @@ " # Print output from the assistant, including any function\n", " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n", - " tool_calls: List[FunctionCallingRecord] = [\n", - " FunctionCallingRecord(**call.as_dict())\n", + " tool_calls: List[ToolCallingRecord] = [\n", + " ToolCallingRecord(**call.as_dict())\n", " for call in assistant_response.info['tool_calls']\n", " ]\n", " for func_record in tool_calls:\n", diff --git a/docs/cookbooks/advanced_features/agents_with_tools.ipynb b/docs/cookbooks/advanced_features/agents_with_tools.ipynb index 24dd301b9f..1adb7888d1 100644 --- a/docs/cookbooks/advanced_features/agents_with_tools.ipynb +++ b/docs/cookbooks/advanced_features/agents_with_tools.ipynb @@ -378,7 +378,7 @@ "outputs": [], "source": [ "from camel.societies import RolePlaying\n", - "from camel.agents.chat_agent import FunctionCallingRecord\n", + "from camel.agents.chat_agent import ToolCallingRecord\n", "from camel.utils import print_text_animated\n", "from colorama import Fore" ] @@ -566,7 +566,7 @@ " # Print output from the assistant, including any function\n", " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n", - " tool_calls: list[FunctionCallingRecord] = assistant_response.info[\n", + " tool_calls: list[ToolCallingRecord] = assistant_response.info[\n", " 'tool_calls'\n", " ]\n", " for func_record in tool_calls:\n", diff --git a/docs/cookbooks/advanced_features/agents_with_tools_from_Composio.ipynb b/docs/cookbooks/advanced_features/agents_with_tools_from_Composio.ipynb index 71115d1d80..1d2d4c4dae 100644 --- a/docs/cookbooks/advanced_features/agents_with_tools_from_Composio.ipynb +++ b/docs/cookbooks/advanced_features/agents_with_tools_from_Composio.ipynb @@ -235,7 +235,7 @@ "from colorama import Fore\n", "from composio_camel import Action, ComposioToolSet\n", "\n", - "from camel.agents.chat_agent import FunctionCallingRecord\n", + "from camel.agents.chat_agent import ToolCallingRecord\n", "from camel.configs import ChatGPTConfig\n", "from camel.models import ModelFactory\n", "from camel.societies import RolePlaying\n", @@ -486,7 +486,7 @@ " # Print output from the assistant, including any function\n", " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n", - " tool_calls: List[FunctionCallingRecord] = assistant_response.info[\n", + " tool_calls: List[ToolCallingRecord] = assistant_response.info[\n", " 'tool_calls'\n", " ]\n", " for func_record in tool_calls:\n", diff --git a/docs/cookbooks/applications/dynamic_travel_planner.ipynb b/docs/cookbooks/applications/dynamic_travel_planner.ipynb index 3db56970c4..c57ae26351 100644 --- a/docs/cookbooks/applications/dynamic_travel_planner.ipynb +++ b/docs/cookbooks/applications/dynamic_travel_planner.ipynb @@ -379,7 +379,7 @@ "\n", "from colorama import Fore\n", "\n", - "from camel.agents.chat_agent import FunctionCallingRecord\n", + "from camel.agents.chat_agent import ToolCallingRecord\n", "from camel.societies import RolePlaying\n", "from camel.toolkits import FunctionTool\n", "from camel.utils import print_text_animated" @@ -896,8 +896,8 @@ " # Print output from the assistant, including any function\n", " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\", 0.01)\n", - " tool_calls: List[FunctionCallingRecord] = [\n", - " FunctionCallingRecord(**call.as_dict())\n", + " tool_calls: List[ToolCallingRecord] = [\n", + " ToolCallingRecord(**call.as_dict())\n", " for call in assistant_response.info['tool_calls']\n", " ]\n", " for func_record in tool_calls:\n", diff --git a/docs/cookbooks/applications/roleplaying_scraper.ipynb b/docs/cookbooks/applications/roleplaying_scraper.ipynb index 5e42adf03d..a662bed18f 100644 --- a/docs/cookbooks/applications/roleplaying_scraper.ipynb +++ b/docs/cookbooks/applications/roleplaying_scraper.ipynb @@ -840,7 +840,7 @@ "\n", "from colorama import Fore\n", "\n", - "from camel.agents.chat_agent import FunctionCallingRecord\n", + "from camel.agents.chat_agent import ToolCallingRecord\n", "from camel.societies import RolePlaying\n", "from camel.utils import print_text_animated" ] @@ -1288,8 +1288,8 @@ " # Print output from the assistant, including any function\n", " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\", 0.01)\n", - " tool_calls: List[FunctionCallingRecord] = [\n", - " FunctionCallingRecord(**call.as_dict())\n", + " tool_calls: List[ToolCallingRecord] = [\n", + " ToolCallingRecord(**call.as_dict())\n", " for call in assistant_response.info['tool_calls']\n", " ]\n", " for func_record in tool_calls:\n", diff --git a/examples/models/role_playing_with_cohere.py b/examples/models/role_playing_with_cohere.py index ff93313d00..89770e94f3 100644 --- a/examples/models/role_playing_with_cohere.py +++ b/examples/models/role_playing_with_cohere.py @@ -15,7 +15,7 @@ from colorama import Fore -from camel.agents.chat_agent import FunctionCallingRecord +from camel.agents.chat_agent import ToolCallingRecord from camel.configs import CohereConfig from camel.models import ModelFactory from camel.societies import RolePlaying @@ -120,8 +120,8 @@ def main( # Print output from the assistant, including any function # execution information print_text_animated(Fore.GREEN + "AI Assistant:") - tool_calls: List[FunctionCallingRecord] = [ - FunctionCallingRecord(**call.as_dict()) + tool_calls: List[ToolCallingRecord] = [ + ToolCallingRecord(**call.as_dict()) for call in assistant_response.info['tool_calls'] ] for func_record in tool_calls: diff --git a/examples/models/role_playing_with_mistral.py b/examples/models/role_playing_with_mistral.py index e92ade930c..5ef2217d67 100644 --- a/examples/models/role_playing_with_mistral.py +++ b/examples/models/role_playing_with_mistral.py @@ -16,7 +16,7 @@ from colorama import Fore -from camel.agents.chat_agent import FunctionCallingRecord +from camel.agents.chat_agent import ToolCallingRecord from camel.configs import MistralConfig from camel.models import ModelFactory from camel.societies import RolePlaying @@ -120,8 +120,8 @@ def main( # Print output from the assistant, including any function # execution information print_text_animated(Fore.GREEN + "AI Assistant:") - tool_calls: List[FunctionCallingRecord] = [ - FunctionCallingRecord(**call.as_dict()) + tool_calls: List[ToolCallingRecord] = [ + ToolCallingRecord(**call.as_dict()) for call in assistant_response.info['tool_calls'] ] for func_record in tool_calls: diff --git a/examples/models/role_playing_with_ollama.py b/examples/models/role_playing_with_ollama.py index 77eaeec33e..fe58c5a44b 100644 --- a/examples/models/role_playing_with_ollama.py +++ b/examples/models/role_playing_with_ollama.py @@ -16,7 +16,7 @@ from colorama import Fore -from camel.agents.chat_agent import FunctionCallingRecord +from camel.agents.chat_agent import ToolCallingRecord from camel.models import ModelFactory from camel.societies import RolePlaying from camel.types import ModelPlatformType @@ -100,8 +100,8 @@ def main( # Print output from the assistant, including any function # execution information print_text_animated(Fore.GREEN + "AI Assistant:") - tool_calls: List[FunctionCallingRecord] = [ - FunctionCallingRecord(**call.as_dict()) + tool_calls: List[ToolCallingRecord] = [ + ToolCallingRecord(**call.as_dict()) for call in assistant_response.info['tool_calls'] ] for func_record in tool_calls: diff --git a/examples/models/role_playing_with_sambanova.py b/examples/models/role_playing_with_sambanova.py index 2cbba7342d..9b8834fe24 100644 --- a/examples/models/role_playing_with_sambanova.py +++ b/examples/models/role_playing_with_sambanova.py @@ -17,7 +17,7 @@ import agentops from colorama import Fore -from camel.agents.chat_agent import FunctionCallingRecord +from camel.agents.chat_agent import ToolCallingRecord from camel.configs import SambaCloudAPIConfig from camel.models import ModelFactory from camel.societies import RolePlaying @@ -128,8 +128,8 @@ def main( # Print output from the assistant, including any function # execution information print_text_animated(Fore.GREEN + "AI Assistant:") - tool_calls: List[FunctionCallingRecord] = [ - FunctionCallingRecord(**call.as_dict()) + tool_calls: List[ToolCallingRecord] = [ + ToolCallingRecord(**call.as_dict()) for call in assistant_response.info['tool_calls'] ] for func_record in tool_calls: diff --git a/examples/observability/agentops_track_roleplaying_with_function.py b/examples/observability/agentops_track_roleplaying_with_function.py index 800ddfcf3f..4570ae4f6e 100644 --- a/examples/observability/agentops_track_roleplaying_with_function.py +++ b/examples/observability/agentops_track_roleplaying_with_function.py @@ -17,7 +17,7 @@ import agentops from colorama import Fore -from camel.agents.chat_agent import FunctionCallingRecord +from camel.agents.chat_agent import ToolCallingRecord from camel.configs import ChatGPTConfig from camel.models import ModelFactory from camel.societies import RolePlaying @@ -125,8 +125,8 @@ # Print output from the assistant, including any function # execution information print_text_animated(Fore.GREEN + "AI Assistant:") - tool_calls: List[FunctionCallingRecord] = [ - FunctionCallingRecord(**call.as_dict()) + tool_calls: List[ToolCallingRecord] = [ + ToolCallingRecord(**call.as_dict()) for call in assistant_response.info['tool_calls'] ] for func_record in tool_calls: diff --git a/examples/toolkits/arxiv_toolkit.py b/examples/toolkits/arxiv_toolkit.py index ddf3a89ddd..57e2ba99f7 100644 --- a/examples/toolkits/arxiv_toolkit.py +++ b/examples/toolkits/arxiv_toolkit.py @@ -55,7 +55,7 @@ print(str(response.info['tool_calls'])[:1000]) ''' =============================================================================== -[FunctionCallingRecord(func_name='search_papers', args={'query': 'attention is +[ToolCallingRecord(func_name='search_papers', args={'query': 'attention is all you need'}, result=[{'title': "Attention Is All You Need But You Don't Need All Of It For Inference of Large Language Models", 'published_date': '2024-07-22', 'authors': ['Georgy Tyukin', 'Gbetondji J-S Dovonon', 'Jean @@ -85,7 +85,7 @@ print(str(response.info['tool_calls'])[:1000]) ''' =============================================================================== -[FunctionCallingRecord(func_name='download_papers', args={'query': 'attention +[ToolCallingRecord(func_name='download_papers', args={'query': 'attention is all you need', 'output_dir': '/Users/enrei/Desktop/camel0826/camel/examples/ tool_call', 'paper_ids': ['2407.15516v1', '2107.08000v1', '2306.01926v1', '2112.05993v1', '1912.11959v2']}, result='papers downloaded successfully')] diff --git a/examples/toolkits/google_scholar_toolkit.py b/examples/toolkits/google_scholar_toolkit.py index b00a50353b..75137d6fcd 100644 --- a/examples/toolkits/google_scholar_toolkit.py +++ b/examples/toolkits/google_scholar_toolkit.py @@ -58,7 +58,7 @@ print(str(response.info['tool_calls'])[:1000]) """ =============================================================================== -[FunctionCallingRecord(func_name='get_author_detailed_info', args={}, result= +[ToolCallingRecord(func_name='get_author_detailed_info', args={}, result= {'container_type': 'Author', 'filled': ['basics', 'indices', 'counts', 'coauthors', 'publications', 'public_access'], 'scholar_id': 'JicYPdAAAAAJ', 'source': , 'name': @@ -98,7 +98,7 @@ print(str(response.info['tool_calls'])[:1000]) """ =============================================================================== -[FunctionCallingRecord(func_name='get_author_publications', args={}, result= +[ToolCallingRecord(func_name='get_author_publications', args={}, result= ['Imagenet classification with deep convolutional neural networks', 'Deep learning', 'Learning internal representations by error-propagation', 'Dropout: a simple way to prevent neural networks from overfitting', 'Visualizing data @@ -127,7 +127,7 @@ print(response.info['tool_calls']) """ =============================================================================== -[FunctionCallingRecord(func_name='get_publication_by_title', args= +[ToolCallingRecord(func_name='get_publication_by_title', args= {'publication_title': 'Camel: Communicative agents for" mind" exploration of large language model society'}, result={'container_type': 'Publication', 'source': Date: Sun, 26 Jan 2025 20:10:32 +0530 Subject: [PATCH 2/8] attribute naming fix --- camel/agents/chat_agent.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.py index f78fda6588..7f3e941c91 100644 --- a/camel/agents/chat_agent.py +++ b/camel/agents/chat_agent.py @@ -87,17 +87,17 @@ class ToolCallingRecord(BaseModel): - r"""Historical records of functions called in the conversation. + r"""Historical records of tools called in the conversation. Attributes: - func_name (str): The name of the function being called. + tool_name (str): The name of the tool being called. args (Dict[str, Any]): The dictionary of arguments passed to - the function. - result (Any): The execution result of calling this function. + the tools. + result (Any): The execution result of calling this tool. tool_call_id (str): The ID of the tool call, if available. """ - func_name: str + tool_name: str args: Dict[str, Any] result: Any tool_call_id: str @@ -106,10 +106,10 @@ def __str__(self) -> str: r"""Overridden version of the string function. Returns: - str: Modified string to represent the function calling. + str: Modified string to represent the tool calling. """ return ( - f"Function Execution: {self.func_name}\n" + f"Tool Execution: {self.tool_name}\n" f"\tArgs: {self.args}\n" f"\tResult: {self.result}\n" ) @@ -1389,12 +1389,12 @@ def _step_tool_call( choice = response.choices[0] if choice.message.tool_calls is None: raise RuntimeError("Tool call is None") - func_name = choice.message.tool_calls[0].function.name + tool_name = choice.message.tool_calls[0].function.name arguments_str = choice.message.tool_calls[0].function.arguments args = self._safe_json_loads(arguments_str) - tool = self.tool_dict[func_name] + tool = self.tool_dict[tool_name] result = tool(**args) tool_call_id = choice.message.tool_calls[0].id @@ -1403,7 +1403,7 @@ def _step_tool_call( role_type=self.role_type, meta_dict=None, content="", - func_name=func_name, + func_name=tool_name, args=args, tool_call_id=tool_call_id, ) @@ -1412,14 +1412,14 @@ def _step_tool_call( role_type=self.role_type, meta_dict=None, content="", - func_name=func_name, + func_name=tool_name, result=result, tool_call_id=tool_call_id, ) # Record information about this function call func_record = ToolCallingRecord( - func_name=func_name, + tool_name=tool_name, args=args, result=result, tool_call_id=tool_call_id, @@ -1461,10 +1461,10 @@ async def step_tool_call_async( choice = response.choices[0] if choice.message.tool_calls is None: raise RuntimeError("Tool call is None") - func_name = choice.message.tool_calls[0].function.name + tool_name = choice.message.tool_calls[0].function.name args = json.loads(choice.message.tool_calls[0].function.arguments) - tool = self.tool_dict[func_name] + tool = self.tool_dict[tool_name] result = await tool(**args) tool_call_id = choice.message.tool_calls[0].id @@ -1473,7 +1473,7 @@ async def step_tool_call_async( role_type=self.role_type, meta_dict=None, content="", - func_name=func_name, + func_name=tool_name, args=args, tool_call_id=tool_call_id, ) @@ -1482,14 +1482,14 @@ async def step_tool_call_async( role_type=self.role_type, meta_dict=None, content="", - func_name=func_name, + func_name=tool_name, result=result, tool_call_id=tool_call_id, ) # Record information about this function call func_record = ToolCallingRecord( - func_name=func_name, + tool_name=tool_name, args=args, result=result, tool_call_id=tool_call_id, From d2b3afdeccc416a22c7674902655225efb187a94 Mon Sep 17 00:00:00 2001 From: JINO-ROHIT Date: Sun, 26 Jan 2025 20:30:08 +0530 Subject: [PATCH 3/8] fix tests --- test/agents/test_chat_agent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/agents/test_chat_agent.py b/test/agents/test_chat_agent.py index 9be09b2693..4bd797a40c 100644 --- a/test/agents/test_chat_agent.py +++ b/test/agents/test_chat_agent.py @@ -866,7 +866,7 @@ def test_tool_calling_sync(step_call_count=3): "Function Execution" ), f"Error in calling round {i+1}" assert ( - tool_calls[0].func_name == "multiply" + tool_calls[0].tool_name == "multiply" ), f"Error in calling round {i+1}" assert tool_calls[0].args == { "a": 2, @@ -985,7 +985,7 @@ async def test_tool_calling_math_async(step_call_count=3): tool_calls = agent_response.info['tool_calls'] assert ( - tool_calls[0].func_name == "multiply" + tool_calls[0].tool_name == "multiply" ), f"Error in calling round {i+1}" assert tool_calls[0].args == { "a": 2, @@ -1078,7 +1078,7 @@ def mock_run_tool_calling_async(*args, **kwargs): ), f"Error in calling round {i+1}" assert ( - tool_calls[0].func_name == "async_sleep" + tool_calls[0].tool_name == "async_sleep" ), f"Error in calling round {i+1}" assert tool_calls[0].args == { 'second': 1 From c9b496f7ecc4062ca23abfd2af3c26d6abee3914 Mon Sep 17 00:00:00 2001 From: JINO-ROHIT Date: Sun, 26 Jan 2025 20:51:57 +0530 Subject: [PATCH 4/8] fix tests --- test/agents/test_chat_agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/agents/test_chat_agent.py b/test/agents/test_chat_agent.py index 4bd797a40c..29f63819ba 100644 --- a/test/agents/test_chat_agent.py +++ b/test/agents/test_chat_agent.py @@ -863,7 +863,7 @@ def test_tool_calling_sync(step_call_count=3): assert len(tool_calls) > 0, f"Error in calling round {i+1}" assert str(tool_calls[0]).startswith( - "Function Execution" + "Tool Execution" ), f"Error in calling round {i+1}" assert ( tool_calls[0].tool_name == "multiply" @@ -1074,7 +1074,7 @@ def mock_run_tool_calling_async(*args, **kwargs): assert tool_calls, f"Error in calling round {i+1}" assert str(tool_calls[0]).startswith( - "Function Execution" + "Tool Execution" ), f"Error in calling round {i+1}" assert ( From 8449737c60d037efcdb7d94b045097efd09bb51b Mon Sep 17 00:00:00 2001 From: Wendong Date: Tue, 4 Feb 2025 23:56:52 +0800 Subject: [PATCH 5/8] update based on review comment --- camel/agents/chat_agent.py | 20 +++++++++---------- .../advanced_features/agents_with_rag.ipynb | 2 +- .../advanced_features/agents_with_tools.ipynb | 4 ++-- .../agents_with_tools_from_Composio.ipynb | 4 ++-- .../applications/dynamic_travel_planner.ipynb | 6 +++--- .../applications/roleplaying_scraper.ipynb | 6 +++--- examples/models/openai_o3_mini_example.py | 2 +- test/agents/test_chat_agent.py | 6 +++--- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.py index 7f3e941c91..72743bb8a1 100644 --- a/camel/agents/chat_agent.py +++ b/camel/agents/chat_agent.py @@ -1389,12 +1389,12 @@ def _step_tool_call( choice = response.choices[0] if choice.message.tool_calls is None: raise RuntimeError("Tool call is None") - tool_name = choice.message.tool_calls[0].function.name + func_name = choice.message.tool_calls[0].function.name arguments_str = choice.message.tool_calls[0].function.arguments args = self._safe_json_loads(arguments_str) - tool = self.tool_dict[tool_name] + tool = self.tool_dict[func_name] result = tool(**args) tool_call_id = choice.message.tool_calls[0].id @@ -1403,7 +1403,7 @@ def _step_tool_call( role_type=self.role_type, meta_dict=None, content="", - func_name=tool_name, + func_name=func_name, args=args, tool_call_id=tool_call_id, ) @@ -1412,14 +1412,14 @@ def _step_tool_call( role_type=self.role_type, meta_dict=None, content="", - func_name=tool_name, + func_name=func_name, result=result, tool_call_id=tool_call_id, ) # Record information about this function call func_record = ToolCallingRecord( - tool_name=tool_name, + tool_name=func_name, args=args, result=result, tool_call_id=tool_call_id, @@ -1461,10 +1461,10 @@ async def step_tool_call_async( choice = response.choices[0] if choice.message.tool_calls is None: raise RuntimeError("Tool call is None") - tool_name = choice.message.tool_calls[0].function.name + func_name = choice.message.tool_calls[0].function.name args = json.loads(choice.message.tool_calls[0].function.arguments) - tool = self.tool_dict[tool_name] + tool = self.tool_dict[func_name] result = await tool(**args) tool_call_id = choice.message.tool_calls[0].id @@ -1473,7 +1473,7 @@ async def step_tool_call_async( role_type=self.role_type, meta_dict=None, content="", - func_name=tool_name, + func_name=func_name, args=args, tool_call_id=tool_call_id, ) @@ -1482,14 +1482,14 @@ async def step_tool_call_async( role_type=self.role_type, meta_dict=None, content="", - func_name=tool_name, + func_name=func_name, result=result, tool_call_id=tool_call_id, ) # Record information about this function call func_record = ToolCallingRecord( - tool_name=tool_name, + tool_name=func_name, args=args, result=result, tool_call_id=tool_call_id, diff --git a/docs/cookbooks/advanced_features/agents_with_rag.ipynb b/docs/cookbooks/advanced_features/agents_with_rag.ipynb index 25f0b8c9e9..ae4658e14a 100644 --- a/docs/cookbooks/advanced_features/agents_with_rag.ipynb +++ b/docs/cookbooks/advanced_features/agents_with_rag.ipynb @@ -474,7 +474,7 @@ "from typing import List\n", "from colorama import Fore\n", "\n", - "from camel.agents.chat_agent import ToolCallingRecord\n", + "from camel.agents.chat_agent import FunctionCallingRecord\n", "from camel.configs import ChatGPTConfig\n", "from camel.toolkits import (\n", " MathToolkit,\n", diff --git a/docs/cookbooks/advanced_features/agents_with_tools.ipynb b/docs/cookbooks/advanced_features/agents_with_tools.ipynb index 1adb7888d1..24dd301b9f 100644 --- a/docs/cookbooks/advanced_features/agents_with_tools.ipynb +++ b/docs/cookbooks/advanced_features/agents_with_tools.ipynb @@ -378,7 +378,7 @@ "outputs": [], "source": [ "from camel.societies import RolePlaying\n", - "from camel.agents.chat_agent import ToolCallingRecord\n", + "from camel.agents.chat_agent import FunctionCallingRecord\n", "from camel.utils import print_text_animated\n", "from colorama import Fore" ] @@ -566,7 +566,7 @@ " # Print output from the assistant, including any function\n", " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n", - " tool_calls: list[ToolCallingRecord] = assistant_response.info[\n", + " tool_calls: list[FunctionCallingRecord] = assistant_response.info[\n", " 'tool_calls'\n", " ]\n", " for func_record in tool_calls:\n", diff --git a/docs/cookbooks/advanced_features/agents_with_tools_from_Composio.ipynb b/docs/cookbooks/advanced_features/agents_with_tools_from_Composio.ipynb index 1d2d4c4dae..71115d1d80 100644 --- a/docs/cookbooks/advanced_features/agents_with_tools_from_Composio.ipynb +++ b/docs/cookbooks/advanced_features/agents_with_tools_from_Composio.ipynb @@ -235,7 +235,7 @@ "from colorama import Fore\n", "from composio_camel import Action, ComposioToolSet\n", "\n", - "from camel.agents.chat_agent import ToolCallingRecord\n", + "from camel.agents.chat_agent import FunctionCallingRecord\n", "from camel.configs import ChatGPTConfig\n", "from camel.models import ModelFactory\n", "from camel.societies import RolePlaying\n", @@ -486,7 +486,7 @@ " # Print output from the assistant, including any function\n", " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n", - " tool_calls: List[ToolCallingRecord] = assistant_response.info[\n", + " tool_calls: List[FunctionCallingRecord] = assistant_response.info[\n", " 'tool_calls'\n", " ]\n", " for func_record in tool_calls:\n", diff --git a/docs/cookbooks/applications/dynamic_travel_planner.ipynb b/docs/cookbooks/applications/dynamic_travel_planner.ipynb index c57ae26351..3db56970c4 100644 --- a/docs/cookbooks/applications/dynamic_travel_planner.ipynb +++ b/docs/cookbooks/applications/dynamic_travel_planner.ipynb @@ -379,7 +379,7 @@ "\n", "from colorama import Fore\n", "\n", - "from camel.agents.chat_agent import ToolCallingRecord\n", + "from camel.agents.chat_agent import FunctionCallingRecord\n", "from camel.societies import RolePlaying\n", "from camel.toolkits import FunctionTool\n", "from camel.utils import print_text_animated" @@ -896,8 +896,8 @@ " # Print output from the assistant, including any function\n", " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\", 0.01)\n", - " tool_calls: List[ToolCallingRecord] = [\n", - " ToolCallingRecord(**call.as_dict())\n", + " tool_calls: List[FunctionCallingRecord] = [\n", + " FunctionCallingRecord(**call.as_dict())\n", " for call in assistant_response.info['tool_calls']\n", " ]\n", " for func_record in tool_calls:\n", diff --git a/docs/cookbooks/applications/roleplaying_scraper.ipynb b/docs/cookbooks/applications/roleplaying_scraper.ipynb index a662bed18f..5e42adf03d 100644 --- a/docs/cookbooks/applications/roleplaying_scraper.ipynb +++ b/docs/cookbooks/applications/roleplaying_scraper.ipynb @@ -840,7 +840,7 @@ "\n", "from colorama import Fore\n", "\n", - "from camel.agents.chat_agent import ToolCallingRecord\n", + "from camel.agents.chat_agent import FunctionCallingRecord\n", "from camel.societies import RolePlaying\n", "from camel.utils import print_text_animated" ] @@ -1288,8 +1288,8 @@ " # Print output from the assistant, including any function\n", " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\", 0.01)\n", - " tool_calls: List[ToolCallingRecord] = [\n", - " ToolCallingRecord(**call.as_dict())\n", + " tool_calls: List[FunctionCallingRecord] = [\n", + " FunctionCallingRecord(**call.as_dict())\n", " for call in assistant_response.info['tool_calls']\n", " ]\n", " for func_record in tool_calls:\n", diff --git a/examples/models/openai_o3_mini_example.py b/examples/models/openai_o3_mini_example.py index d2d89f77ee..3ee7bbf950 100644 --- a/examples/models/openai_o3_mini_example.py +++ b/examples/models/openai_o3_mini_example.py @@ -40,7 +40,7 @@ print(str(response.info['tool_calls'])[:1000]) ''' =============================================================================== -[FunctionCallingRecord(func_name='search_duckduckgo', args={'query': 'what is +[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', diff --git a/test/agents/test_chat_agent.py b/test/agents/test_chat_agent.py index 29f63819ba..e8f3b894d5 100644 --- a/test/agents/test_chat_agent.py +++ b/test/agents/test_chat_agent.py @@ -866,7 +866,7 @@ def test_tool_calling_sync(step_call_count=3): "Tool Execution" ), f"Error in calling round {i+1}" assert ( - tool_calls[0].tool_name == "multiply" + tool_calls[0].func_name == "multiply" ), f"Error in calling round {i+1}" assert tool_calls[0].args == { "a": 2, @@ -985,7 +985,7 @@ async def test_tool_calling_math_async(step_call_count=3): tool_calls = agent_response.info['tool_calls'] assert ( - tool_calls[0].tool_name == "multiply" + tool_calls[0].func_name == "multiply" ), f"Error in calling round {i+1}" assert tool_calls[0].args == { "a": 2, @@ -1078,7 +1078,7 @@ def mock_run_tool_calling_async(*args, **kwargs): ), f"Error in calling round {i+1}" assert ( - tool_calls[0].tool_name == "async_sleep" + tool_calls[0].func_name == "async_sleep" ), f"Error in calling round {i+1}" assert tool_calls[0].args == { 'second': 1 From c10c2f0a9cb09b54498ef3582fd7c8ba0480eaf1 Mon Sep 17 00:00:00 2001 From: Wendong Date: Wed, 5 Feb 2025 00:11:54 +0800 Subject: [PATCH 6/8] fix --- test/agents/test_chat_agent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/agents/test_chat_agent.py b/test/agents/test_chat_agent.py index e8f3b894d5..29f63819ba 100644 --- a/test/agents/test_chat_agent.py +++ b/test/agents/test_chat_agent.py @@ -866,7 +866,7 @@ def test_tool_calling_sync(step_call_count=3): "Tool Execution" ), f"Error in calling round {i+1}" assert ( - tool_calls[0].func_name == "multiply" + tool_calls[0].tool_name == "multiply" ), f"Error in calling round {i+1}" assert tool_calls[0].args == { "a": 2, @@ -985,7 +985,7 @@ async def test_tool_calling_math_async(step_call_count=3): tool_calls = agent_response.info['tool_calls'] assert ( - tool_calls[0].func_name == "multiply" + tool_calls[0].tool_name == "multiply" ), f"Error in calling round {i+1}" assert tool_calls[0].args == { "a": 2, @@ -1078,7 +1078,7 @@ def mock_run_tool_calling_async(*args, **kwargs): ), f"Error in calling round {i+1}" assert ( - tool_calls[0].func_name == "async_sleep" + tool_calls[0].tool_name == "async_sleep" ), f"Error in calling round {i+1}" assert tool_calls[0].args == { 'second': 1 From f730b7aca1bedee8422c0867534454401840cf89 Mon Sep 17 00:00:00 2001 From: Wendong Date: Wed, 5 Feb 2025 00:16:33 +0800 Subject: [PATCH 7/8] revert change to cookbook --- docs/cookbooks/advanced_features/agents_tracking.ipynb | 4 ++-- docs/cookbooks/advanced_features/agents_with_rag.ipynb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/cookbooks/advanced_features/agents_tracking.ipynb b/docs/cookbooks/advanced_features/agents_tracking.ipynb index 09e0dd311f..6de324495f 100644 --- a/docs/cookbooks/advanced_features/agents_tracking.ipynb +++ b/docs/cookbooks/advanced_features/agents_tracking.ipynb @@ -356,7 +356,7 @@ "\n", "from colorama import Fore\n", "\n", - "from camel.agents.chat_agent import ToolCallingRecord\n", + "from camel.agents.chat_agent import FunctionCallingRecord\n", "from camel.configs import ChatGPTConfig\n", "from camel.models import ModelFactory\n", "from camel.societies import RolePlaying\n", @@ -765,7 +765,7 @@ " # Print output from the assistant, including any function\n", " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n", - " tool_calls: List[ToolCallingRecord] = assistant_response.info[\n", + " tool_calls: List[FunctionCallingRecord] = assistant_response.info[\n", " 'tool_calls'\n", " ]\n", " for func_record in tool_calls:\n", diff --git a/docs/cookbooks/advanced_features/agents_with_rag.ipynb b/docs/cookbooks/advanced_features/agents_with_rag.ipynb index ae4658e14a..f89f870288 100644 --- a/docs/cookbooks/advanced_features/agents_with_rag.ipynb +++ b/docs/cookbooks/advanced_features/agents_with_rag.ipynb @@ -569,7 +569,7 @@ " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n", " tool_calls: List[ToolCallingRecord] = [\n", - " ToolCallingRecord(**call.as_dict())\n", + " FunctionCallingRecord(**call.as_dict())\n", " for call in assistant_response.info['tool_calls']\n", " ]\n", " for func_record in tool_calls:\n", From 7bf740136128cc6ff9d09b1eea526b39e501a6e0 Mon Sep 17 00:00:00 2001 From: Wendong Date: Wed, 5 Feb 2025 00:17:32 +0800 Subject: [PATCH 8/8] revert change to cookbook --- docs/cookbooks/advanced_features/agents_with_rag.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cookbooks/advanced_features/agents_with_rag.ipynb b/docs/cookbooks/advanced_features/agents_with_rag.ipynb index f89f870288..7d3bb26a82 100644 --- a/docs/cookbooks/advanced_features/agents_with_rag.ipynb +++ b/docs/cookbooks/advanced_features/agents_with_rag.ipynb @@ -568,7 +568,7 @@ " # Print output from the assistant, including any function\n", " # execution information\n", " print_text_animated(Fore.GREEN + \"AI Assistant:\")\n", - " tool_calls: List[ToolCallingRecord] = [\n", + " tool_calls: List[FunctionCallingRecord] = [\n", " FunctionCallingRecord(**call.as_dict())\n", " for call in assistant_response.info['tool_calls']\n", " ]\n",