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

Enable human interaction in AutoGenStudio - Solution 2 #3476

Merged

Conversation

SailorJoe6
Copy link
Collaborator

Why are these changes needed?

The AutoGenStudio UI doesn't currently support user input modes 'ALWAYS', or 'TERMINATE' which are vital when allowing agents to generate and run code, so that the user can verify the code before it gets execute in their environment. This is likely due to difficulties encountered with Python's asyncio event loop getting blocked by synchronous calls to the AutoGen chat functions. This PR fixes those issues and adds support for all human input modes:

This code comes in multiple commits so you can follow the logical progression through:

  1. Update the AutoGenStudio to use async through the entire call stack
  2. Leverage the async nature to make adding human input much eassier

Related issue number

Resolves #1358
Resolves #1664
Part of roadmap #737

Checks

Update *WorkflowManager* classes:
- Add async `a_send_message_function` parameter to mirror `send_message_function` param.
- Add async `a_process_message` coroutine to mirror the synchronous `process_message` function.
- Add async `a_run` coroutine to mirror the `run` function
- Add async `_a_run_workflow` coroutine to mirror the synchronous `_run_workflow` function.

Update *ExtendedConversableAgent* and *ExtendedGroupChatManager* classes:
- Override the async `a_receive` coroutines

Update *AutoGenChatManager*:
- Add async `a_send` and `a_chat` coroutines to mirror their sync counterparts.
- Accept the `WebSocketManager` instance as a parameter, so it can do Async comms directly.

Update *app.py*
- Provide the `WebSocketManager` instance to the *AutoGenChatManager* constructor
- Await the manager's `a_chat` coroutine, rather than calling the synchronous `chat` function.
Updates to *ExtendedConversableAgent* and *ExtendedGroupChatManager* classes
- override the `get_human_input` function and async `a_get_human_input` coroutine

Updates to *WorkflowManager* classes:
- add parameters `a_human_input_function` and `a_human_input_timeout` and pass along on to the ExtendedConversableAgent and ExtendedGroupChatManager
- fix for invalid configuration passed from UI when human input mode is not NEVER and no model is attached

Updates to *AutoGenChatManager* class:
- add parameter `human_input_timeout` and pass it along to *WorkflowManager* classes
- add async `a_prompt_for_input` coroutine that relies on `websocket_manager.get_input` coroutine (which snuck into last commit)

Updates to *App.py*
- global var HUMAN_INPUT_TIMEOUT_SECONDS = 180, we can replace this with a configurable value in the future
@SailorJoe6
Copy link
Collaborator Author

SailorJoe6 commented Sep 5, 2024

@victordibia the main reason the other solution didn't work the same in different machines is because it relied on running two separate asyncio event loops in two separate threads. Some googling around suggested doing so is unsupported, and leads to undefined behaviors (due to interaction with the GIL).

This method should work for everyone because it uses only the main asyncio event loop for getting user input. To make that work, I had to convert the call to AutoGen's initiate_chat method to use the async a_initiate_chat coroutine. The rest flowed out of that change quite naturally.

@victordibia victordibia self-requested a review September 5, 2024 22:44
@victordibia victordibia added the studio Related to AutoGen Studio. label Sep 5, 2024
Copy link
Collaborator

@victordibia victordibia left a comment

Choose a reason for hiding this comment

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

Just tested this @SailorJoe6 , works as advertised! I learned a thing or two.
This PR also provides building blocks for many other good ideas e.g., using the same socket style messaging to interrupt or stop agents.

@victordibia victordibia merged commit bb11979 into microsoft:autogenstudio Sep 5, 2024
8 of 9 checks passed
@SailorJoe6 SailorJoe6 deleted the Issue_#1358_Human_Input_soln_2 branch September 6, 2024 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
studio Related to AutoGen Studio.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants