Skip to main content

Delivery Agent

The following lab combines features from the Retool enterprise AppGen platform including Retool Database, an app generated using Assist in Retool, and an Agent to optimize delivery provider selection based on customer and warehouse locations. The customer service representative has a delivery app displaying current unscheduled orders and then can use a chat interface to initate the delivery agent. Using an LLM provider and Tools, the Agent selects the appropriate provider and updates the database.

Example delivery optimization
Example delivery optimization

Requirements

  • Retool Cloud
  • Retool Database

Retool Self-hosted will be supported with a quarterly stable release in October.

Steps

Create schemas in Retool Database

This required portion of the lab is available as a separate artifact in Retool AI AppGen: Setup. Complete this first before continuing with the rest of the instructions.

Create Delivery App

This required portion of the lab is available as a separate artifact in Retool AI AppGen:Prompt a delivery application. Complete this first before continuing with the rest of the instructions.

Create Delivery Agent

Create an agent configuration, tools to optimize delivery and update the int_delivery_summary table with the selected delivery provider.

  • Select Agents > New Agent > Start from scratch
  • Select an icon, color and then specify a Agent name of Simulated Delivery Agent.
  • Select Create that will then display the agent Configuration page.

Under Configuration Assistant on the right panel allows us to prompt what we want the agent to complete. The following prompt is used to define the agent’s purpose.

You are a delivery agent that is focused on optimizing the delivery of an order by 
selecting the proper provider that is in proximity of the order address and warehouse
address. Use the order id to get the customer_location from the int_order table and
the warehouse_locaton from the int_warehouse table. Compare those locations with the
int_provider table to optimize the closest provider_location. Update the int_delivery_summary
table with today’s date for delivery and the provider id. Limit the number of tools to three,
one to get the order,warehouse information, one to get the provider information,
and one to update the delivery data.

The following video shows the initial creation of the agent and using the Configuration Assistant.

Tool 1: Get customer and warehouse locations

Select Finish and in the editor view for the tool, enter in the following prompt in the Function Generator:

Query @Retool Database int_delivery_summary table passing in the order id and return 
the warehouse id. Use the order id to query @Retool Database int_orders to get the
customer_location. Use the warehouse id to query @Retool Database int_warehouse to
get the warehouse_location. Return the customer_location and warehouse_location.

This query resulted in a function with params feeding in the order_id and subsequent Resource Query blocks to interact with Retool Database tables. The following video demonstrate how the tool was built.

Tool 2: Get all providers

This tool focuses on getting all the providers so the agent make a determination as to which is appropriate based on warehouse and customer location.

  • Select Finish and in the editor view for the tool, enter in the following prompt in the Function Generator:
Query @Retool Database and the int_provider to get all available providers. 
Return the id and provider_location only.

The following video demonstrate how the tool was built.

Tool 3: Update int_delivery_summary table

This tool focuses on updating the delivery_date and provider columns for the order specified.

  • Select Finish and in the editor view for the tool, enter in the following prompt in the Function Generator:
For @Retool Database int_delivery_summary update the row whose order is order_id 
with a delivery_date of Now() and provider of provider_id.

The following video demonstrate how the tool was built.

Chat with Delivery Agent

Now let's do an initial test to observe the behavior of the agent and what it does. Within Configuration > Chat the customer service agent is able to enter the following prompt:

schedule delivery for order 3

The following video demonstrate using Chat with the Agent and validation of the results.

To show the execution results, you can also Share thread and View. It also provides a public URL that can be shared with team members, customer, or partners.

Summary

Once a team has developed a working example and manually tested / examined the results the team can then move to developing datasets, test cases and evals. Similar to traditional software, testing is important aspect to move an agent from development to production. Access to these tools is provided within Agents under Datasets, Datasets/Testcase, Evals. The Agents Lab demonstrates this manual testing and then creating the dataset, testcase, and evals.