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

[draft] feat: multi-task agents #1270

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

[draft] feat: multi-task agents #1270

wants to merge 15 commits into from

Conversation

longcw
Copy link
Collaborator

@longcw longcw commented Dec 22, 2024

A draft for multi-task agents

An example chat logs on how the conversation transferred between tasks in the restaurant example.

assistant:  Welcome to our restaurant! How may I assist you today?
user: Hello
assistant:  Hello! Thank you for calling our restaurant. Would you like to place an order today? We have Pizza for $10, Salad for $5, Ice Cream for $3, and Coffee for $2.
user: I want a coffee
assistant:  Great choice! Let me transfer you to our order-taking system to process your order for a coffee. Please hold on for a moment.
fnc_calls_collected: [{'transfer_to_order_taking': {}}]
fnc_calls_finished: [{'transfer_to_order_taking': (<__mp_main__.OrderTaking object at 0x7ff1300129d0>, 'Transferred from Greeter to OrderTaking. The current user data is {"order": [], "customer_name": null, "customer_phone": null, "checked_out": false, "expense": null}')}]
assistant:  Your current order includes a Coffee for $2. Would you like to add anything else, or are you ready to confirm your order?
user: I want to checkout
fnc_calls_collected: [{'update_order': {'items': ['Coffee']}}]
fnc_calls_finished: [{'update_order': "Updated order to ['Coffee']"}]
fnc_calls_collected: [{'transfer_to_customer_registration': {}}]
fnc_calls_finished: [{'transfer_to_customer_registration': (<__mp_main__.CustomerRegistration object at 0x7ff12fe1c8d0>, 'Transferred from OrderTaking to CustomerRegistration. The current user data is {"order": ["Coffee"], "customer_name": null, "customer_phone": null, "checked_out": false, "expense": null}')}]
assistant:  Let's start by gathering your information. Could you please tell me your name?
user: Long
assistant:  Could you please confirm the spelling of your name: L-O-N-G?
user: Yes
fnc_calls_collected: [{'collect_name': {'name': 'Long'}}]
fnc_calls_finished: [{'collect_name': 'The name is updated to Long'}]
assistant:  Got it, Long! Now, could you please provide your phone number?
user: 1234567890
assistant:  Please confirm that your phone number is 123-456-7890. Is that correct?
user: Yes
fnc_calls_collected: [{'collect_phone': {'phone': '1234567890'}}]
fnc_calls_finished: [{'collect_phone': 'The phone number is updated to 1234567890'}]
assistant:  Thank you for confirming. Here's the information we have:  - Name: Long - Phone Number: 123-456-7890  If everything looks correct, I'll proceed to checkout. Shall I continue?
user: Yes
fnc_calls_collected: [{'transfer_to_checkout': {}}]
fnc_calls_finished: [{'transfer_to_checkout': (<__mp_main__.Checkout object at 0x7ff12fe6b9d0>, 'Transferred from CustomerRegistration to Checkout. The current user data is {"order": ["Coffee"], "customer_name": "Long", "customer_phone": "1234567890", "checked_out": false, "expense": null}')}]
assistant:  Your current order consists of: - Coffee: $2  The total expense is $2. Would you like to proceed with the checkout, or do you need any modifications to your order?
user: oh I want another coffee with milk
fnc_calls_collected: [{'transfer_to_order_taking': {}}]
fnc_calls_finished: [{'transfer_to_order_taking': (<__mp_main__.OrderTaking object at 0x7ff1300129d0>, 'Transferred from Checkout to OrderTaking. The current user data is {"order": ["Coffee"], "customer_name": "Long", "customer_phone": "1234567890", "checked_out": false, "expense": null}')}]
assistant:  I've added your request for another Coffee, with milk. Would you like to confirm your order now or make any additional changes?
user: and a pizza
fnc_calls_collected: [{'update_order': {'items': ['Coffee', 'Coffee with Milk', 'Pizza']}}]
fnc_calls_finished: [{'update_order': "Updated order to ['Coffee', 'Coffee with Milk', 'Pizza']"}]
assistant:  Your updated order includes: - Coffee: $2 - Coffee with Milk: $2 - Pizza: $10  Would you like to confirm this order, or do you need further adjustments?
user: Yes
fnc_calls_collected: [{'update_order': {'items': ['Coffee', 'Coffee with Milk', 'Pizza']}}]
fnc_calls_finished: [{'update_order': "Updated order to ['Coffee', 'Coffee with Milk', 'Pizza']"}]
fnc_calls_collected: [{'transfer_to_customer_registration': {}}]
fnc_calls_finished: [{'transfer_to_customer_registration': (<__mp_main__.CustomerRegistration object at 0x7ff12fe1c8d0>, 'Transferred from OrderTaking to CustomerRegistration. The current user data is {"order": ["Coffee", "Coffee with Milk", "Pizza"], "customer_name": "Long", "customer_phone": "1234567890", "checked_out": false, "expense": null}')}]
assistant:  I've confirmed your order details. Would you like to proceed to checkout now?
user: Yes
fnc_calls_collected: [{'transfer_to_checkout': {}}]
fnc_calls_finished: [{'transfer_to_checkout': (<__mp_main__.Checkout object at 0x7ff12fe6b9d0>, 'Transferred from CustomerRegistration to Checkout. The current user data is {"order": ["Coffee", "Coffee with Milk", "Pizza"], "customer_name": "Long", "customer_phone": "1234567890", "checked_out": false, "expense": null}')}]
assistant:  Your current order consists of: - Coffee: $2 - Coffee with Milk: $2 - Pizza: $10  The total expense is $14. I will proceed with the checkout now.
fnc_calls_collected: [{'checkout': {'expense': 14.0}}]
fnc_calls_finished: [{'checkout': 'Checked out'}]
fnc_calls_collected: [{'transfer_to_greeter': {}}]
fnc_calls_finished: [{'transfer_to_greeter': (<__mp_main__.Greeter object at 0x7ff12fe0e450>, 'Transferred from Checkout to Greeter. The current user data is {"order": ["Coffee", "Coffee with Milk", "Pizza"], "customer_name": "Long", "customer_phone": "1234567890", "checked_out": true, "expense": 14.0}')}]
assistant:  Your previous order has been successfully checked out. Is there anything else I can assist you with, or would you like to start a new order?
user: No thanks
assistant:  You're welcome! If you need anything else, feel free to call us. Have a great day!

Copy link

changeset-bot bot commented Dec 22, 2024

⚠️ No Changeset found

Latest commit: a94f06d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

llm=openai.LLM(),
tts=openai.TTS(),
initial_task=news_mailer,
available_tasks=[news_mailer, email_collector],
Copy link
Member

Choose a reason for hiding this comment

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

how does it know which tasks to use in this case? is it purely from the instructions indicating Use email_collector to collect the user's email address... does that mean email_collector is represented as a function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

each task has a built in transfer_to method that will be added to fnc_ctx if the can_enter of the task returns true.

"3. Repeat both pieces of information back to ensure accuracy\n"
"Transfer to:\n"
"- checkout: when all details are confirmed\n"
"- order_taking: to modify the order\n"
Copy link
Member

Choose a reason for hiding this comment

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

IMO embedding these in instructions is less than ideal.. it seems fragile (i.e. changing one place and not changing the other) since there are no typechecks/compilers

Copy link
Collaborator Author

@longcw longcw Dec 26, 2024

Choose a reason for hiding this comment

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

I agree.
Currently the default description for a transfer function is just Called to transfer to {task}, this is not enough to prompt the LLM to call the function if there is no detailed instruction in the system prompt.

Ideally we can enhance the description of the transfer function instead of embedding this in separate instructions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the detailed transfer instructions and removed them from the task instructions, but still need to add Transfer to the next step using functions after ... to each task to ensure automatic transfer between tasks.

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.

2 participants