🐫 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
fix: Record all tool calls from LLM response (#1928)
Wendong-Fandd92c900aacf
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.ymlindex 30cdd22e1..9c11b7181 100644--- a/.github/ISSUE_TEMPLATE/bug_report.yml+++ b/.github/ISSUE_TEMPLATE/bug_report.yml@@ -26,7 +26,7 @@ body:attributes:label: What version of camel are you using?description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.- placeholder: E.g., 0.2.34+ placeholder: E.g., 0.2.35validations:required: truediff --git a/camel/__init__.py b/camel/__init__.pyindex d6a0aac9c..935fa72dd 100644--- a/camel/__init__.py+++ b/camel/__init__.py@@ -14,7 +14,7 @@from camel.logger import disable_logging, enable_logging, set_log_level-__version__ = '0.2.34'+__version__ = '0.2.35'__all__ = ['__version__',diff --git a/camel/agents/_types.py b/camel/agents/_types.pyindex 0ce37c6d1..ad6881726 100644--- a/camel/agents/_types.py+++ b/camel/agents/_types.py@@ -34,7 +34,7 @@ class ModelResponse(BaseModel):model_config = ConfigDict(arbitrary_types_allowed=True)response: Union[ChatCompletion, Stream, AsyncStream]- tool_call_request: Optional[ToolCallRequest]+ tool_call_requests: Optional[List[ToolCallRequest]]output_messages: List[BaseMessage]finish_reasons: List[str]usage_dict: Dict[str, Any]diff --git a/camel/agents/_utils.py b/camel/agents/_utils.pyindex 4989e1394..edae57681 100644--- a/camel/agents/_utils.py+++ b/camel/agents/_utils.py@@ -136,7 +136,7 @@ def get_info_dict(termination_reasons: List[str],num_tokens: int,tool_calls: List[ToolCallingRecord],- external_tool_call_request: Optional[ToolCallRequest] = None,+ external_tool_call_requests: Optional[List[ToolCallRequest]] = None,) -> Dict[str, Any]:r"""Returns a dictionary containing information about the chat session.@@ -149,8 +149,8 @@ def get_info_dict(num_tokens (int): The number of tokens used in the chat session.tool_calls (List[ToolCallingRecord]): The list of functioncalling records, containing the information of called tools.- external_tool_call_request (Optional[ToolCallRequest]): The- request for external tool call.+ external_tool_call_requests (Optional[List[ToolCallRequest]]): The+ requests for external tool calls.Returns:@@ -162,7 +162,7 @@ def get_info_dict("termination_reasons": termination_reasons,"num_tokens": num_tokens,"tool_calls": tool_calls,- "external_tool_call_request": external_tool_call_request,+ "external_tool_call_requests": external_tool_call_requests,}diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.pyindex 54d7fd91d..b79a49771 100644--- a/camel/agents/chat_agent.py+++ b/camel/agents/chat_agent.py@@ -582,7 +582,7 @@ class ChatAgent(BaseAgent):self.update_memory(input_message, OpenAIBackendRole.USER)tool_call_records: List[ToolCallingRecord] = []- external_tool_call_request: Optional[ToolCallRequest] = None+ external_tool_call_requests: Optional[List[ToolCallRequest]] = Nonewhile True:try:@@ -602,12 +602,26 @@ class ChatAgent(BaseAgent):if self.single_iteration:break- if tool_call_request := response.tool_call_request:- if tool_call_request.tool_name in self._external_tool_schemas:- external_tool_call_request = tool_call_request+ if tool_call_requests := response.tool_call_requests:+ # Process all tool calls+ for tool_call_request in tool_call_requests:+ if (+ tool_call_request.tool_name+ in self._external_tool_schemas+ ):+ if external_tool_call_requests is None:+ external_tool_call_requests = []+ external_tool_call_requests.append(tool_call_request)+ else:+ tool_call_records.append(+ self._execute_tool(tool_call_request)+ )++ # If we found external tool calls, break the loop+ if external_tool_call_requests:break- tool_call_records.append(self._execute_tool(tool_call_request))+ # If we're still here, continue the loopcontinuebreak@@ -616,7 +630,10 @@ class ChatAgent(BaseAgent):self._record_final_output(response.output_messages)return self._convert_to_chatagent_response(- response, tool_call_records, num_tokens, external_tool_call_request+ response,+ tool_call_records,+ num_tokens,+ external_tool_call_requests,)@property@@ -658,7 +675,7 @@ class ChatAgent(BaseAgent):self.update_memory(input_message, OpenAIBackendRole.USER)tool_call_records: List[ToolCallingRecord] = []- external_tool_call_request: Optional[ToolCallRequest] = None+ external_tool_call_requests: Optional[List[ToolCallRequest]] = Nonewhile True:try:openai_messages, num_tokens = self.memory.get_context()@@ -677,13 +694,27 @@ class ChatAgent(BaseAgent):if self.single_iteration:break- if tool_call_request := response.tool_call_request:- if tool_call_request.tool_name in self._external_tool_schemas:- external_tool_call_request = tool_call_request+ if tool_call_requests := response.tool_call_requests:+ # Process all tool calls+ for tool_call_request in tool_call_requests:+ if (+ tool_call_request.tool_name+ in self._external_tool_schemas+ ):+ if external_tool_call_requests is None:+ external_tool_call_requests = []+ external_tool_call_requests.append(tool_call_request)++ tool_call_record = await self._aexecute_tool(+ tool_call_request+ )+ tool_call_records.append(tool_call_record)++ # If we found an external tool call, break the loop+ if external_tool_call_requests:break- tool_call_record = await self._aexecute_tool(tool_call_request)- tool_call_records.append(tool_call_record)+ # If we're still here, continue the loopcontinuebreak@@ -692,7 +723,10 @@ class ChatAgent(BaseAgent):self._record_final_output(response.output_messages)return self._convert_to_chatagent_response(- response, tool_call_records, num_tokens, external_tool_call_request+ response,+ tool_call_records,+ num_tokens,+ external_tool_call_requests,)def _convert_to_chatagent_response(@@ -700,7 +734,7 @@ class ChatAgent(BaseAgent):response: ModelResponse,tool_call_records: List[ToolCallingRecord],num_tokens: int,- external_tool_call_request: Optional[ToolCallRequest],+ external_tool_call_requests: Optional[List[ToolCallRequest]],) -> ChatAgentResponse:r"""Parse the final model response into the chat agent response."""info = self._step_get_info(@@ -710,7 +744,7 @@ class ChatAgent(BaseAgent):response.response_id,tool_call_records,num_tokens,- external_tool_call_request,+ external_tool_call_requests,)return ChatAgentResponse(@@ -961,7 +995,7 @@ class ChatAgent(BaseAgent):response_id: str,tool_calls: List[ToolCallingRecord],num_tokens: int,- external_tool_call_request: Optional[ToolCallRequest] = None,+ external_tool_call_requests: Optional[List[ToolCallRequest]] = None,) -> Dict[str, Any]:r"""Process the output of a chat step and gather information about thestep.@@ -1018,7 +1052,7 @@ class ChatAgent(BaseAgent):finish_reasons,num_tokens,tool_calls,- external_tool_call_request,+ external_tool_call_requests,)def _handle_batch_response(@@ -1057,18 +1091,21 @@ class ChatAgent(BaseAgent):if response.usage is not None:usage = safe_model_dump(response.usage)- tool_call_request: Optional[ToolCallRequest] = None+ tool_call_requests: Optional[List[ToolCallRequest]] = Noneif tool_calls := response.choices[0].message.tool_calls:- tool_name = tool_calls[0].function.name- tool_call_id = tool_calls[0].id- args = json.loads(tool_calls[0].function.arguments)- tool_call_request = ToolCallRequest(- tool_name=tool_name, args=args, tool_call_id=tool_call_id- )+ tool_call_requests = []+ for tool_call in tool_calls:+ tool_name = tool_call.function.name+ tool_call_id = tool_call.id+ args = json.loads(tool_call.function.arguments)+ tool_call_request = ToolCallRequest(+ tool_name=tool_name, args=args, tool_call_id=tool_call_id+ )+ tool_call_requests.append(tool_call_request)return ModelResponse(response=response,- tool_call_request=tool_call_request,+ tool_call_requests=tool_call_requests,output_messages=output_messages,finish_reasons=finish_reasons,usage_dict=usage,@@ -1108,7 +1145,7 @@ class ChatAgent(BaseAgent):# TODO: Handle tool callsreturn ModelResponse(response=response,- tool_call_request=None,+ tool_call_requests=None,output_messages=output_messages,finish_reasons=finish_reasons,usage_dict=usage_dict,@@ -1148,7 +1185,7 @@ class ChatAgent(BaseAgent):# TODO: Handle tool callsreturn ModelResponse(response=response,- tool_call_request=None,+ tool_call_requests=None,output_messages=output_messages,finish_reasons=finish_reasons,usage_dict=usage_dict,diff --git a/camel/configs/openai_config.py b/camel/configs/openai_config.pyindex ee895c941..c58ef342a 100644--- a/camel/configs/openai_config.py+++ b/camel/configs/openai_config.py@@ -15,7 +15,7 @@ from __future__ import annotationsfrom typing import Dict, Optional, Sequence, Type, Union-from pydantic import BaseModel, Field+from pydantic import BaseModelfrom camel.configs.base_config import BaseConfig@@ -28,14 +28,14 @@ class ChatGPTConfig(BaseConfig):temperature (float, optional): Sampling temperature to use, between:obj:`0` and :obj:`2`. Higher values make the output more random,while lower values make it more focused and deterministic.- (default: :obj:`0.2`)+ (default: :obj:`None`)top_p (float, optional): An alternative to sampling with temperature,called nucleus sampling, where the model considers the results ofthe tokens with top_p probability mass. So :obj:`0.1` means onlythe tokens comprising the top 10% probability mass are considered.- (default: :obj:`1.0`)+ (default: :obj:`None`)n (int, optional): How many chat completion choices to generate for- each input message. (default: :obj:`1`)+ each input message. (default: :obj:`None`)response_format (object, optional): An object specifying the formatthat the model must output. Compatible with GPT-4 Turbo and allGPT-3.5 Turbo models newer than gpt-3.5-turbo-1106. Setting to@@ -51,7 +51,7 @@ class ChatGPTConfig(BaseConfig):max context length.stream (bool, optional): If True, partial message deltas will be sentas data-only server-sent events as they become available.- (default: :obj:`False`)+ (default: :obj:`None`)stop (str or list, optional): Up to :obj:`4` sequences where the APIwill stop generating further tokens. (default: :obj:`None`)max_tokens (int, optional): The maximum number of tokens to generate@@ -62,12 +62,12 @@ class ChatGPTConfig(BaseConfig)::obj:`2.0`. Positive values penalize new tokens based on whetherthey appear in the text so far, increasing the model's likelihoodto talk about new topics. See more information about frequency and- presence penalties. (default: :obj:`0.0`)+ presence penalties. (default: :obj:`None`)frequency_penalty (float, optional): Number between :obj:`-2.0` and:obj:`2.0`. Positive values penalize new tokens based on theirexisting frequency in the text so far, decreasing the model'slikelihood to repeat the same line verbatim. See more information- about frequency and presence penalties. (default: :obj:`0.0`)+ about frequency and presence penalties. (default: :obj:`None`)logit_bias (dict, optional): Modify the likelihood of specified tokensappearing in the completion. Accepts a json object that maps tokens(specified by their token ID in the tokenizer) to an associated@@ -76,7 +76,7 @@ class ChatGPTConfig(BaseConfig):The exact effect will vary per model, but values between:obj:` -1`and :obj:`1` should decrease or increase likelihood of selection;values like :obj:`-100` or :obj:`100` should result in a ban or- exclusive selection of the relevant token. (default: :obj:`{}`)+ exclusive selection of the relevant token. (default: :obj:`None`)user (str, optional): A unique identifier representing your end-user,which can help OpenAI to monitor and detect abuse.(default: :obj:`""`)@@ -101,21 +101,25 @@ class ChatGPTConfig(BaseConfig)::obj:`o1mini`, :obj:`o1preview`, :obj:`o3mini`). If not providedor if the model type does not support it, this parameter isignored. (default: :obj:`None`)+ parallel_tool_calls (bool, optional): A parameter specifying whether+ the model should call tools in parallel or not. (default:+ :obj:`None`)"""- temperature: float = 0.2 # openai default: 1.0- top_p: float = 1.0- n: int = 1- stream: bool = False+ temperature: Optional[float] = None+ top_p: Optional[float] = None+ n: Optional[int] = None+ stream: Optional[bool] = Nonestop: Optional[Union[str, Sequence[str]]] = Nonemax_tokens: Optional[int] = None- presence_penalty: float = 0.0+ presence_penalty: Optional[float] = Noneresponse_format: Optional[Union[Type[BaseModel], Dict]] = None- frequency_penalty: float = 0.0- logit_bias: Dict = Field(default_factory=dict)- user: str = ""+ frequency_penalty: Optional[float] = None+ logit_bias: Optional[Dict] = None+ user: Optional[str] = Nonetool_choice: Optional[Union[Dict[str, str], str]] = Nonereasoning_effort: Optional[str] = None+ parallel_tool_calls: Optional[bool] = NoneOPENAI_API_PARAMS = {param for param in ChatGPTConfig.model_fields.keys()}diff --git a/docs/conf.py b/docs/conf.pyindex 0be0f670c..67a164517 100644--- a/docs/conf.py+++ b/docs/conf.py@@ -27,7 +27,7 @@ sys.path.insert(0, os.path.abspath('..'))project = 'CAMEL'copyright = '2024, CAMEL-AI.org'author = 'CAMEL-AI.org'-release = '0.2.34'+release = '0.2.35'html_favicon = ('https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'diff --git a/docs/key_modules/loaders.md b/docs/key_modules/loaders.mdindex f6da9f6f2..664bc575f 100644--- a/docs/key_modules/loaders.md+++ b/docs/key_modules/loaders.md@@ -340,14 +340,14 @@ response = jina_reader.read_content("https://docs.camel-ai.org/")print(response)``````markdown->>>Welcome to CAMEL’s documentation! — CAMEL 0.2.34 documentation+>>>Welcome to CAMEL’s documentation! — CAMEL 0.2.35 documentation===============[Skip to main content](https://docs.camel-ai.org/#main-content)Back to top Ctrl+K- [ CAMEL 0.2.34](https://docs.camel-ai.org/#)+ [ CAMEL 0.2.35](https://docs.camel-ai.org/#)Search Ctrl+Kdiff --git a/pyproject.toml b/pyproject.tomlindex 76d62b808..32bc76a46 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "camel-ai"-version = "0.2.34"+version = "0.2.35"description = "Communicative Agents for AI Society Study"authors = [{ name = "CAMEL-AI.org" }]requires-python = ">=3.10,<3.13"diff --git a/test/agents/test_chat_agent.py b/test/agents/test_chat_agent.pyindex 3e4923138..0f29c8e0b 100644--- a/test/agents/test_chat_agent.py+++ b/test/agents/test_chat_agent.py@@ -361,11 +361,11 @@ def test_chat_agent_step_with_external_tools(step_call_count=3):response = external_tool_agent.step(usr_msg)assert not response.msg.content- external_tool_call_request = response.info[- "external_tool_call_request"+ external_tool_call_requests = response.info[+ "external_tool_call_requests"]assert (- external_tool_call_request.tool_name == "sub"+ external_tool_call_requests[0].tool_name == "sub"), f"Error in calling round {i+1}"diff --git a/uv.lock b/uv.lockindex dd6776954..3f6cfe392 100644--- a/uv.lock+++ b/uv.lock@@ -510,7 +510,7 @@ wheels = [[[package]]name = "camel-ai"-version = "0.2.34"+version = "0.2.35"source = { editable = "." }dependencies = [{ name = "colorama" },