/
Custom Agent Tutorial 2 - Sales Bot with Proposal Generation
  • In progress
  • Custom Agent Tutorial 2 - Sales Bot with Proposal Generation

    Introduction

    In this tutorial, we will make a Custom AI Agent to execute a basic requirements gathering and quote generation AI Agent. The AI Agent needs to have the following behaviours:

    1. Talk to the customer and ask a series of questions to understand the customers requirements in depth

    2. When all questions are asked, a proposal is generated, emailed to the user, and attached to the conversation

    3. The bot can answer follow up questions related to the proposal, both via the same conversation and via email

    To build our AI sales agent, we are going to go through the following steps:

    1. Create a custom intake to ask the questions to the user

    2. Define a custom Proposal data schema that will embody the structure and format of our companies proposals

    3. Define a custom Document Template with the format for our proposals

    4. Define a custom agent action with its own smart chain, that will first generate & update the associated Proposal data, then regenerate the associated PDF document using the Document Template

    Step 1 - Creating a Custom Intake

    To get started, we are going to setup the intake to define the list of questions that our chatbot needs to ask. So let’s start by going to the Custom Agent environment where we can play around with customizing our agent. That can be found at this URL: https://custom.prosperalabs.ai/app/ If your account is blank, you may get a screenshot that looks like this.

    image-20250107-011419.png

    To create a new Intake so the bot will ask questions, you can go here:

     

    image-20250107-011634.png

    Let’s give our new Intake a name and description to describe its purpose.

    image-20250107-011907.png

    The title and description are only used for internal reference by you and have no impact on the behaviour of the AI agent.

    The introduction on the other hand represents how the bot will begin the conversation. For our demo sales bot, we will keep it simple. Remember that how the AI Agent starts the conversation can set the tone for the whole conversation, so make sure you set the introduction right.

    image-20250107-012830.png

    Then we need to dive into the specific questions that the bot will ask. For our purposes, we are going to use the following list of common questions for requirements gathering:

    1. What is the purpose of the application you are looking to build?

    2. What are the key features you would like the application to have?

    3. Is this a new product you are building, or are you looking to enhance or modify an existing product?

    4. What is the target audience for the application?

    5. Who are the customers / users for the product?

    6. What is the quality level you are looking for? Is it a high quality product build or a quick and dirty MVP?

    7. What is the budget for the project?

    8. What is the timeline for the project? When do you want to start? When do you want to finish?

    9. Are there any third party systems that the product needs to integrate with?

    10. User interface requirements for the product?

    For now we are going to ignore the datapoints and just fill in the questions. Punch them in one-by-one in the Questions section. Mark all the questions as required.

    image-20250107-014712.png

    Step 2 - Set the default intake and smart chain

    At this point, we need to set our default intake and change the default smart chain to ensure our bot configuration takes effect. Start with the default intake. That can be set on this screen:

    image-20250107-015058.png

    Once it has set, press the Save button.

     

    image-20250107-015158.png

    Next we need to set the default smart chain for our AI Agent. The binding that is used for the Custom Agent environment is the custom_agent binding. By default, this usually points to a Receptionist agent configuration, so we are going to need to change this to the intake agent.

    image-20250107-015419.png

    Search for the Intake smart chain and assign it to the custom_agent binding.

    image-20250107-015604.png

    Once you have set the smart chain, the default behaviour of the agent will be updated.

    Step 3 - Test the behaviour of the intake bot

    Our AI Agent should now adopt the behaviour of an Intake bot, asking the questions we defined. We can test this by going to the “Chat with your Bot”. If you already have a conversation, you may need to reset it to start fresh.

    image-20250107-020313.png

    If your agent does not automatically start the conversation, you can trigger it by saying something simple like “Hello!”

    image-20250107-020732.png

    After you exchange a few messages back and forth with your new AI agent, you can validate that the filled intake object gets created with the appropriate data.

    image-20250107-020922.png

     

    image-20250107-021141.png

    Step 4 - Create a Custom Data Schema

    The next step in creating our sales bot will be to create a format to contain all of the data required for a proposal, and a table for our AI Agent to store the generated proposals in.

     

    To do this, we will go over to Custom Data Schemas:

    image-20250107-022633.png

    We will create a new data schema here. Punch in the machine name, title and description.

    image-20250107-022816.png

    In the Schema section, punch in the following text for the JSON schema. For now you don’t need to know precisely how to configure this section as we are redesigning the user interface. Just copy and paste in the following text for the schema of your proposal:

    { "properties": { "title": { "show_in_table_view": true, "table_view_order": 1, "title": "Title", "type": "string" }, "brief": { "description": "A brief description of the project described in the proposal", "multiline": true, "rows": 4, "show_in_table_view": true, "table_view_order": 3, "title": "Brief", "type": "string" }, "description": { "show_in_table_view": false, "table_view_order": 10, "title": "Description", "type": "string" }, "requirements": { "description": "Each sub-section of the proposal lists out the requirements of a single module", "items": { "properties": { "section_title": { "title": "Section Title", "type": "string" }, "section_description": { "multiline": true, "rows": 8, "title": "Section Description", "type": "string" }, "section_price": { "title": "Section Price", "type": "number" } }, "type": "object" }, "title": "Requirements", "type": "array" }, "total_price": { "show_in_table_view": true, "table_view_order": 2, "title": "Total Price", "type": "number" } }, "type": "object" }

    After that, you will need to set an icon for the sales-bot and activate it to show up in the left side menu. For now, just use the text description for the icon. But you can find other options here: Material Icons - Material UI

    image-20250107-023541.png

    Once you create the data schema and refresh the page, you should see it show up in the left side menu.

    image-20250107-023709.png

    Step 5 - Define a Custom Document Format

    The next step is to define the format of the final document. To do that, we will go to the AI Document Generation menu and create a new format.

    image-20250107-032811.png

    You should now see the editor that allows you to edit the format of your generated proposal. You may need to make your browser full-screen in order for the format editor to render properly.

    image-20250107-033013.png

    We will now try to put together a format for our proposal. To add new elements to your document format, you will need to use the plus button to access the Blocks menu.

    image-20250107-033507.png

    We first add several “Text” elements in a column layout. For the “Text” blocks that need to have data substituted into them, you will need to set the variable binding under the Properties menu on the right hand side.

    image-20250107-033916.png

    Now we should be able to test our AI document generation by going to the Settings tab. You will be provided with a form that you can type data into.

    image-20250107-034313.png

    If you type in some data and press the “Submit” button, the system will generate an example of the document, so you can see what it looks like after it has been rendered.

    Step 6 - Create the document generation smart chain

    Now that we have our document format created, the next step is to create the smart chain that will generate our proposal object. This is step is pivotal because we may need to apply various bits of business logic that depends on the specifics of the company and product offerings.

    For the purposes of this tutorial, we are going to skip trying to make the AI generate a good proposal and instead just focus on getting it functioning.

    So to get started, we will use the empty document generation smart chain as our starting point and modify it. To do that, go to the smart chains section and search for “empty” to bring up the empty document generation smart chain.

    image-20250107-172803.png

    We will want to change the chain name to something new to reflect its usage as our Proposal generator.

    image-20250107-173032.png

    We will give it the name of proposal_generator

     

    image-20250107-173110.png

    Then we will rename the first step in the smart chain:

     

    image-20250107-173225.png

    We will name this step literally generate_proposal.

    image-20250107-173335.png

    Now we need to switch the step type to one which uses AI to generate a structured JSON object. We are going to take, as input, the Filled Intake object that is created automatically by the system when a user has a conversation with the intake bot. This isn’t the only way you could design this AI Agent - you could try to generate the proposal using the conversation directly as the input. However, we will usually get more consistent proposal generations if we use a clean intermediary as our input, rather then directly generating the proposal.

    So to start, lets switch the step type. Use the Step Type menu to find the Structured Output One Off Prompt type.

    image-20250107-175757.png

    You will be prompted like this, reminding you that the options will get overridden. This is fine. Press Change Type anyhow.

    image-20250107-175858.png

    Now we need to configure the schema for our structured output. This needs to match the same schema that we used in Step 4, except for a few key differences. The Description field we attach to each of the fields needs to describe to the AI what should go into that field. Often times its also valuable to change the variable names to be different then what you might store in the database. Again the idea is to be very verbose and explicit to the AI. The requirements of your data schema for AI generation are different than the requirements of your data schema for your database, even though they are technically the same schema describing the same structure.

    So to get started, we go to the output schema tab:

    image-20250122-163457.png

     

    For Schema Name, we can use “proposal”. The Schema name is fed into the AI system, so make sure that it is succinct and descriptive of the data that its supposed to be generating.

    Next we type in the Schema Description. This is also fed into the AI system. It should contain a high level description of the data that you want generated. For our system, you can use this:

    A proposal for a custom AI software development project.

    Putting in those details, your screen should look like this:

    image-20250122-163612.png

    Now we need to add each of the fields for our proposal, similar to the data schema we punched into Custom Data Schemas.

    Let’s start with the title field. To add it, click on ADD SCHEMA FIELD button.

    image-20250122-163818.png

    Update the name of the schema key to title For more settings related to the schema field, you can expand it by clicking on the Expand button, as highlighted.

    image-20250122-164122.png

    Set the type of the field to String

    image-20250122-164630.png

    In the description field, we need to put some language on what exactly the AI is supposed to generate within this field. So in our case, we just need some instructions on what the title should look like. So we will enter in the following:

    A title for the proposed project. No longer than 3-4 words.

    Note that this is different then the description we used for the Custom Data Schema. That is because this description is part of the AI prompt that will generate the data.

    Punching that in, your screen should look like this:

    image-20250122-164722.png

    Next we will do the field ‘brief’, repeating the same process. Use the following description:

    A short 2-3 sentence description of the project.

    image-20250122-164933.png

    At this point its probably best to Save your smart chain, just as a caution to avoid losing anything you punch in. Saving is not automatic.

    image-20250122-165014.png

    Next, we will do the description field exactly the same way. We will use the following description for it:

    A one paragraph description of the project and its value to the client.

    image-20250122-165056.png

    Next we need to add the part that generates multiple different requirements sections. This is a bit more complex schema wise.

    We will start by adding the requirementsfield and setting its type to “Array”. We will add in the following description:

    A list of sections describing the various requirements of the proposal

    So you should see this:

    image-20250122-165351.png

    If you click on Items Schema, you can define your items for the specific field. Now for our items set the type as Object field. But we need to set a description for that sub object. Use the following description:

    A single section describing a single requirement from the bot

    So you should see this:

    image-20250122-165659.png

     

    Now we need to add the properties of the sub-object, by clicking pm ADD SUB-FIELD.

    Let’s start by adding section_title.We will add this field, set the type to String, and add the following description:

    The title of the requirement, in three to four words.

    So you should see this:

    image-20250122-165919.png

    Next we will add section_description. We will also give it type String and use the following description:

    The detailed list of features and requirements that are needed for this section

    image-20250122-165958.png

    Lastly, we will do section_price. This time, the field type needs to be Number. Use the following description:

    The price to complete all of the requirements in this section

    image-20250122-170035.png

    Now lastly, we will add the total_price field to the root schema. Note the order here is critical. The total_price field is after the fields for the individual sections which have their own individual prices. This is because the AI generates output in the same order that you define in your schema. So when the AI is generating the total_price field, it is receiving as input all of the fields it generated previously. This means that our AI only needs to do some simple calculations to predict the total_price field.

    If we had put the total_price field first, the AI would first predict a total_price, then try to generate the requirements sections in order to fit that total price. This might be appropriate in some types of sales - starting with a target price and then working backwards to the requirements that fulfill that total price. But that's not what we want to do here. We want the AI to objectively predict each of the individual sub-sections of the proposal, and the total price should just be a simple calculation based on that.

    So lets add in this field. We will use the following simple description.

    The total price made by adding together the individual prices of the requirements

    Now you have click on ADD SCHEMA FIELD to add total_price schema field.

    image-20250122-170132.png

    So you should see this:

    image-20250122-170317.png

    Now we have to do the main part of the prompt. This can vary widely depending on the product that you are selling. The AI does not intrinsically know how to set prices - you have to teach it. You can teach it by putting it into the description field that we set above. But usually its better to put it into the main prompt. So that is what we are going to do. The following prompt uses a technique known variously as in-context learning.

    Go back to the Content tab:

    image-20250109-033826.png

    Now copy the following prompt, in its entirety, into the content section. This prompt is very long because it has a ton of prior examples. The prompt has been attached as a file because it is very long.

    You should see the following now:

    image-20250109-040122.png

    Step 7 - Creating a Smart Chain Binding

    In order to use the created document template and generate the document, firstly we need to set the smart chain binding to the smart chain which we have created in above step.

    To create the smart chain binding, follow the below steps:

    • Navigate to the Smart chain Binding by going to Configuration → Advanced → Smart chain Bindings.

    image-20250122-170855.png
    • Click on Creating New Binding to create new smart chain binding.

    image-20250122-171046.png
    • Give the Binding Name and Template Name, then click on Create.

    image-20250122-171251.png
    • You have successfully created the smart chain binding. You should now see the created smart chain binding, which looks like this:

    image-20250122-171551.png
    • Now, you need to bind the smart chain which you have created in Step 6 to this binding. To do that, double-click on the Chain Name column for your created smart chain binding. You will see a list of smart chains. Select the smart chain that you created earlier.

    image-20250122-171843.png

    Once you make your selection, click your mouse somewhere on the screen and then press Shift + Reload to refresh your page and see the changes. You will see something like this:

    image-20250122-172109.png

    Step 8 - Linking a Smart Chain Binding

    Now, we need to add this smart chain binding to our document.
    To do this, navigate to Document Generation → Document Template, and then click on Settings at the bottom. You will see a screen similar to this:

     

    image-20250122-172558.png

    Now, give a Title to your document. Under Smart Chain Binding, select the smart chain binding that you created in Step 7. After making your selection, press Shift + Reload to apply the changes.

    Yay!! Our setup is done. Let’s test it now:

    Step 9 - Testing Sales Bot

    To test our setup, lets go to Web Chat and click Chat with your Bot

     

    image-20250122-174621.png

    You can start the conversation by providing your details. The agent will then ask you a set of questions that you have configured in the Intake form. Once you have answered all the questions, you can ask the agent to generate the document.

    image-20250122-181421.png

    Finally, the document has been generated and will be sent to your email.

     

    Related content