-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: add termination parameter to ChatAgent step and astep #2285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6942b79
6a96e91
ceb3ec4
8d8fab2
9c09814
1df5ebe
ae419f2
0990d8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| # limitations under the License. | ||
| # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. ========= | ||
| import logging | ||
| import threading | ||
| from typing import Dict, List, Optional, Sequence, Tuple, Union | ||
|
|
||
| from camel.agents import ( | ||
|
|
@@ -77,6 +78,9 @@ class RolePlaying: | |
| task specify meta dict with. (default: :obj:`None`) | ||
| output_language (str, optional): The language to be output by the | ||
| agents. (default: :obj:`None`) | ||
| stop_event (Optional[threading.Event], optional): Event to signal | ||
| termination of the agent's operation. When set, the agent will | ||
| terminate its execution. (default: :obj:`None`) | ||
| """ | ||
|
|
||
| def __init__( | ||
|
|
@@ -101,6 +105,7 @@ def __init__( | |
| extend_sys_msg_meta_dicts: Optional[List[Dict]] = None, | ||
| extend_task_specify_meta_dict: Optional[Dict] = None, | ||
| output_language: Optional[str] = None, | ||
| stop_event: Optional[threading.Event] = None, | ||
| ) -> None: | ||
| if model is not None: | ||
|
Comment on lines
106
to
110
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi there, @Wendong-Fan as suggested I have elevated the stop_event to be part of ChatAgent, thus passing the event turned to:
Since
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, if updating RolePlaying is not appropriate We can revert the last commit ae419f2 and it would constrain changes to OwlRolePlaying only.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks @a7m-1st ! I think current approach is good |
||
| logger.warning( | ||
|
|
@@ -156,6 +161,7 @@ def __init__( | |
| assistant_agent_kwargs=assistant_agent_kwargs, | ||
| user_agent_kwargs=user_agent_kwargs, | ||
| output_language=output_language, | ||
| stop_event=stop_event, | ||
| ) | ||
| self.critic: Optional[Union[CriticAgent, Human]] = None | ||
| self.critic_sys_msg: Optional[BaseMessage] = None | ||
|
|
@@ -316,6 +322,7 @@ def _init_agents( | |
| assistant_agent_kwargs: Optional[Dict] = None, | ||
| user_agent_kwargs: Optional[Dict] = None, | ||
| output_language: Optional[str] = None, | ||
| stop_event: Optional[threading.Event] = None, | ||
| ) -> None: | ||
| r"""Initialize assistant and user agents with their system messages. | ||
|
|
||
|
|
@@ -330,6 +337,9 @@ def _init_agents( | |
| pass to the user agent. (default: :obj:`None`) | ||
| output_language (str, optional): The language to be output by the | ||
| agents. (default: :obj:`None`) | ||
| stop_event (Optional[threading.Event], optional): Event to signal | ||
| termination of the agent's operation. When set, the agent will | ||
| terminate its execution. (default: :obj:`None`) | ||
| """ | ||
| if self.model is not None: | ||
| if assistant_agent_kwargs is None: | ||
|
|
@@ -344,13 +354,15 @@ def _init_agents( | |
| self.assistant_agent = ChatAgent( | ||
| init_assistant_sys_msg, | ||
| output_language=output_language, | ||
| stop_event=stop_event, | ||
| **(assistant_agent_kwargs or {}), | ||
| ) | ||
| self.assistant_sys_msg = self.assistant_agent.system_message | ||
|
|
||
| self.user_agent = ChatAgent( | ||
| init_user_sys_msg, | ||
| output_language=output_language, | ||
| stop_event=stop_event, | ||
| **(user_agent_kwargs or {}), | ||
| ) | ||
| self.user_sys_msg = self.user_agent.system_message | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_step_token_exceedis a bit confusing since the agent is not terminated since the number of token exceeding the context windows. Could we improve this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes thanks I forgot to mention.
@lightaime Since the function is generic, how about we rename it to
_step_terminatebecause it terminates then returns token number and called functions?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in #2347
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Wendong-Fan and @lightaime !