-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
camel/agents/chat_agent.py
Outdated
| self, | ||
| input_message: Union[BaseMessage, str], | ||
| response_format: Optional[Type[BaseModel]] = None, | ||
| stop_event: Optional[threading.Event] = None, |
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 @a7m-1st ! Would it better to add this argument in __init__ instead of step?
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.
Definitely would make the code cleaner! Let me do that.
Thanks @Wendong-Fan .
| 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: |
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.
Hi there, @Wendong-Fan as suggested I have elevated the stop_event to be part of ChatAgent, thus passing the event turned to:
run_society -> society.stop_event = stop_event -> which is passed to ChatAgent in
__init__
Since society:OwlRolePlaying has stop_event now, this resulted in updating OwlRolePlaying in camel-ai/owl#450 which is reflected to its parent class RolePlaying here.
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.
Also, if updating RolePlaying is not appropriate We can revert the last commit ae419f2 and it would constrain changes to OwlRolePlaying only.
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 @a7m-1st ! I think current approach is good
| 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: |
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 @a7m-1st ! I think current approach is good
| return self._step_token_exceed( | ||
| num_tokens, tool_call_records, "termination_triggered" | ||
| ) |
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_exceed is 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_terminate because 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 !
Description
Terminating an agent safely as of now was not possible. That was due to the one-shot nature of the tasks. But when rerunning is required in OWL for instance in camel-ai/owl#450, safe and quick termination is of utmost importance.
This branch is last of three PRs, this one adds a termination event in
chat_agent.pywhich allows atomic termination and patches a runtime error (empty msg) raised byagent_response.pywhen terminating Agents.The other PR is #2194, which fixes issue camel-ai/owl#449 and introduces
terminate_browsertool to browser toolkit.Lastly the PR in owl camel-ai/owl#450, uses the terminate_browser tool and passes the stop_event to the ChatAgent.
Checklist
Go over all the following points, and put an
xin all the boxes that apply.Fixes #issue-numberin the PR description (required)pyproject.tomlanduv lockIf you are unsure about any of these, don't hesitate to ask. We are here to help!