Skip to content
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

Use groupchat for websurfer team #767

Merged
merged 5 commits into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions captn/captn_agents/backend/tools/_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ def get_get_info_from_the_web_page(
websurfer_navigator_llm_config: Optional[Dict[str, Any]] = None,
timestamp: Optional[str] = None,
max_retires_before_give_up_message: int = 7,
max_round: int = 50,
) -> Callable[[str, int, int], str]:
fx = summarizer_llm_config, websurfer_llm_config, websurfer_navigator_llm_config

Expand Down Expand Up @@ -833,6 +834,16 @@ def get_info_from_the_web_page(
# is_termination_msg=_is_termination_msg,
)

groupchat = autogen.GroupChat(
agents=[web_surfer, web_surfer_navigator],
messages=[],
max_round=max_round,
speaker_selection_method="round_robin",
)
manager = autogen.GroupChatManager(
groupchat=groupchat,
)

initial_message = (
f"Time now is {timestamp_copy}." if timestamp_copy else ""
)
Expand All @@ -844,15 +855,13 @@ def get_info_from_the_web_page(
"""

try:
web_surfer_navigator.initiate_chat(
web_surfer, message=initial_message
)
manager.initiate_chat(recipient=manager, message=initial_message)
except Exception as e:
print(f"Exception '{type(e)}' in initiating chat: {e}")

for i in range(inner_retries):
print(f"Inner retry {i + 1}/{inner_retries}")
last_message = str(web_surfer_navigator.last_message()["content"])
last_message = str(groupchat.messages[-1]["content"])

try:
if "I GIVE UP" in last_message:
Expand All @@ -868,20 +877,19 @@ def get_info_from_the_web_page(
current_retries=i,
max_retires_before_give_up_message=max_retires_before_give_up_message,
)
web_surfer.send(
retry_message,
recipient=web_surfer_navigator,
manager.send(
message=retry_message,
recipient=manager,
)
continue
if last_message.strip() == "":
retry_message = """Reminder to myself: we do not have any bad attempts, we are just trying to get the information from the web page.

Message to web_surfer: Please click on the link which you think is the most relevant for the task.
After that, I will guide you through the next steps."""
# In this case, web_surfer_navigator is sending the message to web_surfer
web_surfer_navigator.send(
retry_message,
recipient=web_surfer,
manager.send(
message=retry_message,
recipient=manager,
)
continue

Expand All @@ -899,9 +907,9 @@ def get_info_from_the_web_page(
current_retries=i,
max_retires_before_give_up_message=max_retires_before_give_up_message,
)
web_surfer.send(
retry_message,
recipient=web_surfer_navigator,
manager.send(
message=retry_message,
recipient=manager,
)
continue
last_message = _format_last_message(url=url, summary=summary)
Expand All @@ -923,9 +931,9 @@ def get_info_from_the_web_page(
current_retries=i,
max_retires_before_give_up_message=max_retires_before_give_up_message,
)
web_surfer.send(
retry_message,
recipient=web_surfer_navigator,
manager.send(
message=retry_message,
recipient=manager,
)

except Exception as e:
Expand All @@ -935,7 +943,7 @@ def get_info_from_the_web_page(
current_retries=i,
max_retires_before_give_up_message=max_retires_before_give_up_message,
)
web_surfer.send(retry_message, recipient=web_surfer_navigator)
manager.send(message=retry_message, recipient=manager)
except Exception as e:
# todo: log the exception
failure_message = str(e)
Expand Down