Skip to content

Feature request: Ability to merge flows #24

Open
@xinha-sh

Description

@xinha-sh

I am building a chat tool for my app, a discovery platform for shopify stores.

When the user send messages I am considering the flow to be:

  1. Classify the intent - product recommendation or order enquiry
  2. If product recommendation is the intent
    • I want to first understand if the product needs to be catered towards men or women
    • based on this I want to find if particular category, subcategory is to be fetched -> custom tool that hits my endpoint to get this
    • use above results to finally fetch matching products -> custom tool that hits an endpoint to fetch recommendation
  3. If order enquiry is the intent then
    • ....

At present I am stuck at 2. I can definitely think that it will be sequence of agent calls. But how do I merge this into the original oneOf call.

Current implementaion

const classifyRequestAgent = agent({
  model: openai('gpt-4o'),
  system:
    'You are helpful assistant. You will be given user request and you will classify it as product recommendation or order enquiry.',
});

/*
* Ideally I would like something like
*

  const productRecommendationAgent = sequence([{
    agent: 'determineGenderAgent',
    input: 'Classify the product recommendation request is meant for male or female',
  }, {
    agent: 'populateInputAgent',
    input: 'Populate the missing details in the product recommendation request',
  }, {
    agent: 'productRecommendationAgent',
    input: 'Find the top 3 matching products from Peppyhop',
  }])

 const determineGenderAgent = agent({
   model: openai('gpt-4o'),
   system:
    'You are helpful assistant. You will be given user request and you will classify it as product recommendation or order enquiry.',
 });

 const populateInputAgent = agent({
   model: openai('gpt-4o'),
   system:
     'You are helpful assistant. You will be given user request and you will populate the missing details in the product recommendation request.',
   tools: {populateInputTool},
 })
*/

const productRecommendationAgent = agent({
  model: openai('gpt-4o'),
  system:
    'You are helpful product search agent. You will be given search parameter and you will return matching products from the PeppyHop API.',
  tools: {
    productFetchTool,
  },
});

const orderEnquiryAgent = agent({
  model: openai('gpt-4o'),
  system: 'You are helpful assistant. You will be given user request and you will respond to it.',
});

const processUserChatFlow = sequence([
  {
    agent: 'classifyRequestAgent',
    input: 'Classify the request as product recommendation or order enquiry',
  },
  oneOf([
    {
      when: 'You are asked to recommend products',
      input: {
        agent: 'productRecommendationAgent',
        input: 'Find the top 3 matching products from Peppyhop',
      },
    },
    {
      when: 'You are asked to answer order enquiry',
      input: {
        agent: 'orderEnquiryAgent',
        input: 'Answer the order enquiry',
      },
    },
  ]),
]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions