camel-ai 0.2.69a7__py3-none-any.whl → 0.2.71a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of camel-ai might be problematic. Click here for more details.

camel/__init__.py CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  from camel.logger import disable_logging, enable_logging, set_log_level
16
16
 
17
- __version__ = '0.2.69a7'
17
+ __version__ = '0.2.71a1'
18
18
 
19
19
  __all__ = [
20
20
  '__version__',
@@ -556,13 +556,12 @@ class RolePlaying:
556
556
  )
557
557
  user_msg = self._reduce_message_options(user_response.msgs)
558
558
 
559
- # To prevent recording the same memory more than once (once in chat
560
- # step and once in role play), and the model generates only one
561
- # response when multi-response support is enabled.
562
- if (
563
- 'n' in self.user_agent.model_backend.model_config_dict.keys()
564
- and self.user_agent.model_backend.model_config_dict['n'] > 1
565
- ):
559
+ # To prevent recording missing messages: ChatAgent.step automatically
560
+ # saves the response to memory only when a single message is returned.
561
+ # When multi-response support is enabled (n > 1), it is the caller's
562
+ # responsibility to record the selected message. Therefore, we record
563
+ # it here after choosing one message via `_reduce_message_options()`.
564
+ if self._is_multi_response(self.user_agent):
566
565
  self.user_agent.record_message(user_msg)
567
566
 
568
567
  assistant_response = self.assistant_agent.step(user_msg)
@@ -579,13 +578,7 @@ class RolePlaying:
579
578
  )
580
579
  assistant_msg = self._reduce_message_options(assistant_response.msgs)
581
580
 
582
- # To prevent recording the same memory more than once (once in chat
583
- # step and once in role play), and the model generates only one
584
- # response when multi-response support is enabled.
585
- if (
586
- 'n' in self.assistant_agent.model_backend.model_config_dict.keys()
587
- and self.assistant_agent.model_backend.model_config_dict['n'] > 1
588
- ):
581
+ if self._is_multi_response(self.assistant_agent):
589
582
  self.assistant_agent.record_message(assistant_msg)
590
583
 
591
584
  return (
@@ -639,13 +632,7 @@ class RolePlaying:
639
632
  )
640
633
  user_msg = self._reduce_message_options(user_response.msgs)
641
634
 
642
- # To prevent recording the same memory more than once (once in chat
643
- # step and once in role play), and the model generates only one
644
- # response when multi-response support is enabled.
645
- if (
646
- 'n' in self.user_agent.model_backend.model_config_dict.keys()
647
- and self.user_agent.model_backend.model_config_dict['n'] > 1
648
- ):
635
+ if self._is_multi_response(self.user_agent):
649
636
  self.user_agent.record_message(user_msg)
650
637
 
651
638
  assistant_response = await self.assistant_agent.astep(user_msg)
@@ -662,13 +649,7 @@ class RolePlaying:
662
649
  )
663
650
  assistant_msg = self._reduce_message_options(assistant_response.msgs)
664
651
 
665
- # To prevent recording the same memory more than once (once in chat
666
- # step and once in role play), and the model generates only one
667
- # response when multi-response support is enabled.
668
- if (
669
- 'n' in self.assistant_agent.model_backend.model_config_dict.keys()
670
- and self.assistant_agent.model_backend.model_config_dict['n'] > 1
671
- ):
652
+ if self._is_multi_response(self.assistant_agent):
672
653
  self.assistant_agent.record_message(assistant_msg)
673
654
 
674
655
  return (
@@ -730,3 +711,20 @@ class RolePlaying:
730
711
  new_instance.critic = self.critic.clone(with_memory)
731
712
 
732
713
  return new_instance
714
+
715
+ def _is_multi_response(self, agent: ChatAgent) -> bool:
716
+ r"""Checks if the given agent supports multi-response.
717
+
718
+ Args:
719
+ agent (ChatAgent): The agent to check for multi-response support.
720
+
721
+ Returns:
722
+ bool: True if the agent supports multi-response, False otherwise.
723
+ """
724
+ if (
725
+ 'n' in agent.model_backend.model_config_dict.keys()
726
+ and agent.model_backend.model_config_dict['n'] is not None
727
+ and agent.model_backend.model_config_dict['n'] > 1
728
+ ):
729
+ return True
730
+ return False
@@ -27,7 +27,7 @@ from camel.societies.workforce.prompts import (
27
27
  )
28
28
  from camel.societies.workforce.utils import TaskResult
29
29
  from camel.societies.workforce.worker import Worker
30
- from camel.tasks.task import Task, TaskState, validate_task_content
30
+ from camel.tasks.task import Task, TaskState, is_task_result_insufficient
31
31
 
32
32
 
33
33
  class RolePlayingWorker(Worker):
@@ -178,14 +178,14 @@ class RolePlayingWorker(Worker):
178
178
  result_dict = json.loads(response.msg.content)
179
179
  task_result = TaskResult(**result_dict)
180
180
 
181
- if not validate_task_content(task_result.content, task.id):
181
+ task.result = task_result.content
182
+
183
+ if is_task_result_insufficient(task):
182
184
  print(
183
185
  f"{Fore.RED}Task {task.id}: Content validation failed - "
184
186
  f"task marked as failed{Fore.RESET}"
185
187
  )
186
188
  return TaskState.FAILED
187
189
 
188
- task.result = task_result.content
189
-
190
190
  print(f"Task result: {task.result}\n")
191
191
  return TaskState.DONE
@@ -26,7 +26,7 @@ from camel.agents import ChatAgent
26
26
  from camel.societies.workforce.prompts import PROCESS_TASK_PROMPT
27
27
  from camel.societies.workforce.utils import TaskResult
28
28
  from camel.societies.workforce.worker import Worker
29
- from camel.tasks.task import Task, TaskState, validate_task_content
29
+ from camel.tasks.task import Task, TaskState, is_task_result_insufficient
30
30
 
31
31
 
32
32
  class AgentPool:
@@ -352,14 +352,14 @@ class SingleAgentWorker(Worker):
352
352
  if task_result.failed:
353
353
  return TaskState.FAILED
354
354
 
355
- if not validate_task_content(task_result.content, task.id):
355
+ task.result = task_result.content
356
+
357
+ if is_task_result_insufficient(task):
356
358
  print(
357
359
  f"{Fore.RED}Task {task.id}: Content validation failed - "
358
360
  f"task marked as failed{Fore.RESET}"
359
361
  )
360
362
  return TaskState.FAILED
361
-
362
- task.result = task_result.content
363
363
  return TaskState.DONE
364
364
 
365
365
  async def _listen_to_channel(self):