microsoft / autogen

A programming framework for agentic AI 🤖
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
34.8k stars 5.04k forks source link

Add UserProxyAgent in AgentChat API #4255

Closed victordibia closed 1 day ago

victordibia commented 1 week ago

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:

# 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:

Why are these changes needed?

Provide some standard/guidance around creating a UserProxyAgent.

Related issue number

Related to #3614

Checks

ekzhu commented 1 week ago

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?

victordibia commented 3 days ago

@ekzhu , @husseinmozannar . This is ready for review. We may need a separate PR down the line on where to add it in the documentation.

husseinmozannar commented 2 days ago

I will do my best to take a look today, worst case tomorrow/sunday