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

Add UserProxyAgent in AgentChat API #4255

Merged
merged 10 commits into from
Nov 24, 2024
Merged

Add UserProxyAgent in AgentChat API #4255

merged 10 commits into from
Nov 24, 2024

Conversation

victordibia
Copy link
Collaborator

@victordibia victordibia commented Nov 18, 2024

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_func in constructor that defaults to console input if nothing is passed.
  • input_func gets 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:

  • Handling handoff message (or other message types)
  • Adding tests
  • Pass cancellation token to input func ,
  • 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

@ekzhu
Copy link
Collaborator

ekzhu commented Nov 18, 2024

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 victordibia marked this pull request as ready for review November 21, 2024 22:59
@victordibia
Copy link
Collaborator Author

@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
Copy link
Contributor

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

Copy link
Contributor

@husseinmozannar husseinmozannar left a comment

Choose a reason for hiding this comment

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

tested works well!

@husseinmozannar husseinmozannar merged commit 0ff1687 into main Nov 24, 2024
41 checks passed
@husseinmozannar husseinmozannar deleted the userproxy_agent_vd branch November 24, 2024 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants