Skip to content

Conversation

@a7m-1st
Copy link
Collaborator

@a7m-1st a7m-1st commented Apr 27, 2025

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.py which allows atomic termination and patches a runtime error (empty msg) raised by agent_response.py when terminating Agents.
The other PR is #2194, which fixes issue camel-ai/owl#449 and introduces terminate_browser tool 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 x in all the boxes that apply.

  • I have read the CONTRIBUTION guide (required)
  • I have linked this PR to an issue using the Development section on the right sidebar or by adding Fixes #issue-number in the PR description (required)
  • I have checked if any dependencies need to be added or updated in pyproject.toml and uv lock
  • I have updated the tests accordingly (required for a bug fix or a new feature)
  • I have updated the documentation if needed:
  • I have added examples if this is a new feature

If you are unsure about any of these, don't hesitate to ask. We are here to help!

@a7m-1st a7m-1st added the enhancement New feature or request label Apr 27, 2025
@a7m-1st a7m-1st requested a review from Wendong-Fan April 27, 2025 14:40
@a7m-1st a7m-1st self-assigned this Apr 27, 2025
@a7m-1st a7m-1st requested a review from raywhoelse April 29, 2025 17:51
self,
input_message: Union[BaseMessage, str],
response_format: Optional[Type[BaseModel]] = None,
stop_event: Optional[threading.Event] = None,
Copy link
Member

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?

Copy link
Collaborator Author

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 .

Comment on lines 106 to 110
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:
Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Member

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

Comment on lines 106 to 110
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:
Copy link
Member

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

@Wendong-Fan Wendong-Fan merged commit 0cd23f6 into master May 4, 2025
4 of 7 checks passed
@Wendong-Fan Wendong-Fan deleted the terminate-chatagent branch May 4, 2025 22:50
Comment on lines +868 to +870
return self._step_token_exceed(
num_tokens, tool_call_records, "termination_triggered"
)
Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in #2347

Copy link
Collaborator Author

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants