Skip to main content

Tool Service Setup

Tool Service Setup

A tool service allows you to connect external APIs to Parlant so that your agents can dynamically fetch data and take action in the real world.

Generally speaking, you can connect multiple tool services to Parlant, such that each service is responsible for some external system. For example, a "Google Calendar" service.

For our purposes, we'll build a tool that fetches product data from a database. We’ll support the scenario where a customer needs help choosing laptops. We'll make our agent clarify the customer's needs, and recommend the most relevant laptops.

Here's an outline of what we're going to do:

  1. Clone the tool service starter repo, to get up an running quickly
  2. Create a tool that searches the store for products in a given category
  3. Register the tool service on the Parlant server
  4. Create a guideline for our desired conversational behavior, which uses the tool

Setting Up Your Tool Service

Clone this starter repository to get started with some initial boilerplate:

$ cd parlant-tutorial
$ git clone https://github.com/emcie-co/parlant-tool-service-starter tool-service
$ cd tool-service
$ poetry install

Adding Your Database

For the sake of this tutorial, let's use a straightforward JSON file containing product details such as type, description, tags, quantities, and prices, which will form the database for our tool’s functionality. Here’s an example structure:

[
{
"title": "MSI MPG Z690 Edge WiFi DDR4",
"type": "Motherboard",
"vendor": "MSI",
"description": "Intel Z690 chipset motherboard with PCIe 5.0, WiFi 6E, and robust power delivery.",
"tags": [ "intel", "z690", "wifi", "gaming"],
"qty": 18,
"price": 279.99
},
...
]

To help you get started quickly, we've prepared a JSON file of 100 products.

$ curl -o products.json https://www.parlant.io/files/products.json

Your tree should now look like this:

parlant-tutorial/
├── runtime-data
├── basic-client
└── tool-service/
├── parlant_tool_service_starter/
│ ├── __init__.py
│ └── service.py
├── LICENSE
├── README.md
├── poetry.lock
├── pyproject.toml
└── products.json

With this boilerplate set up, we're now ready to code our tool's logic!