Add UserProxyAgent in AgentChat API
While current tutorial shows how to create custom agents, a UserProxyAgent seems to be a common preset and it would be good to have an implementation that can be easily reused as part of the api instead of apps having multiple implementations (e.g., AGS) . This PR is meant to start a design conversation around this.
This PR does the following:
- Inherits from BaseChatAgent
- Takes in an
input_funcin constructor that defaults to consoleinputif nothing is passed. input_funcgets called when the UserProxyAgent gets a message, and returns a string
# defaults to built-in input
user_proxy = UserProxyAgent(name="user_agent")
result = await user_proxy.run(task="what is the height of the eiffel tower")
print(result.messages[-1].content
Stuff entered by the user
# uses a custom input function (could stream to a websocket)
def input_fn(input_text: str) -> str:
return "The height of the eiffel tower is 324 meters. Aloha!"
user_proxy = UserProxyAgent(name="user_agent", input_func=input_fn)
result = await user_proxy.run(task="what is the height of the eiffel tower")
print(result.messages[-1].content)
The height of the eiffel tower is 324 meters. Aloha!
To be done:
- [x] Handling handoff message (or other message types)
- [x] Adding tests
- [x] Pass cancellation token to input func ,
- [x] Should input_func get a list of all messages? - No
Why are these changes needed?
Provide some standard/guidance around creating a UserProxyAgent.
Related issue number
Related to #3614
Checks
- [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://microsoft.github.io/autogen/docs/Contribute#documentation to build and test documentation locally.
- [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR.
- [ ] I've made sure all auto checks have passed.
Should cancellation_token be passed to the input_func etc? ,
I think it may be worth checking if the cancellation token is set in the input function, so user who was asked to provide the input can get feedback when their input was cancelled. The user what was asked to provide the input may not be the user that runs the application. So having the cancellation token as part of the input function's argument is good.
Should input_func get a list of all messages?
Not necessary for now, right?
@ekzhu , @husseinmozannar . This is ready for review. We may need a separate PR down the line on where to add it in the documentation.
I will do my best to take a look today, worst case tomorrow/sunday