Skip to content

Shopping Helper

Objective

Use the AI Refinery SDK to create and run a simple AI system to help users shop for electronics.

Steps

1. Configuration file

As a first step, you simply need to create a yaml file with all the required configuration.

  1. The agent named Online Shopper is a SearchAgent (built-in) that searches the internet to find the providers and prices of electronics.

  2. The Inventory Reader is a custom agent that helps you check the inventory that you have in stock. This agent expects the data of your stock in a csv file.

orchestrator:
  agent_list:
    - agent_name: Online Shopper
    - agent_name: Inventory Reader

utility_agents:
  - agent_class: SearchAgent
    agent_name: Online Shopper
    agent_description: This agent helps you find on the internet the provider and prices of electronics


  - agent_class: CustomAgent
    agent_name: Inventory Reader
    agent_description: This agent helps you check the inventory of our offices

2. Python file

Now, you can start the development of your assistant. The following code snippet creates the custom agent for checking your inventory, logs in to the AI Refinery service through the DistillerClient, creates the project using the yaml configuration above, and runs the project in interactive mode.

import csv
from typing import Optional
import os
from air import login, DistillerClient
from dotenv import load_dotenv

async def inventory_check(query: Optional[str]=None) -> str:
    """
    Reads a CSV file and returns its contents as a string.
    """
    inventory_path = 'electronic_inventory.csv'
    content = ""
    with open(inventory_path, mode='r', newline='') as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            content += ', '.join(row) + '\n'
    return content.strip()


load_dotenv() # loads your ACCOUNT and API_KEY from a `.env` file

login(
    account=str(os.getenv("ACCOUNT")),
    api_key=str(os.getenv("API_KEY")),
)

distiller_client = DistillerClient()
uuid = "myuser"
project = "Warehouse Management"

distiller_client.create_project(config_path="config.yaml", project=project) # "config.yaml" contains the yaml configuration above

distiller_client.interactive(
    project=project,
    uuid=uuid,
    custom_agent_gallery={"Inventory Reader": inventory_check},
)