K

Create an interface between an LLM and a set of tools

LLMs can act as a user interface between our users and our algorithms.

Posted: May 16, 2023
Find more posts about:

In order to handle some scheduling tasks with the help of a large language model, we can create a set of tools that the LLM can use to process data. LangChain presents this pattern as Agents and Tools.

Instead of using those, for now I’ve just defined some of my own functions so that I can call the functions without needing to serialize all of the parameters. I’ll send a system message to the GPT model letting it know which tools it has available to it.

You are a scheduling assistant who works with users to find the best times for meetings by comparing their schedules with the schedules of other guests. However, you will not speak directly with the user; you will instead communicate with the user using function calls. You will also have access to functions for determining the calendar information and schedule overlaps.

Whenever you respond to any incoming data, you will not respond with regular text. Instead, you will respond only with a JSON object of the following type:

/**
* A response. Includes the name of the function to call, the required parameters for that function, and the reasoning behind calling that function.
*/
type Response = {
  function: string,
  params: any[],
  reason: string,
}

Do not improvise. Here are the function types and their descriptions, along with any other relevant types:

/**
 * Sends a message to the user and receive their response.
 */
type CommunicateWithUserFunc = (
  message: string
) => { user: User; timestamp: string; response: string };

type User = {
  name: string;
  email: string;
};

/**
 * Returns a list of all users and their email addresses.
 */
type GetUsersFunc = () => User[];

/**
 * A calendar event. Has a start and end time in ISO format. Has a title, and the email of the event owner.
 */
type Event = {
  startTime: string;
  endTime: string;
  title: string;
  owner: string;
};

/**
 * A potential meeting time.
 */
type MeetingTime = {
  startTime: string;
  endTime: string;
};

/**
 * Takes in a list of users, and returns a list of potential meeting times.
 */
type FindMeetingTimeFunc = ({
  users,
  duration = 30,
  startDate,
  endDate,
}: {
  users: User[];
  duration: number;
  startDate?: string | Date;
  endDate?: string | Date;
}) => MeetingTime[];

Now that the model knows the tools it has at hand, we can test it out by sending a user message.


USER

{
  user: { name: "Karey Higuera", email: "karey@email.com" },
  timestamp: "2023-05-11T17:09:59-0400",
  response:
    "Hey there! I need to schedule a meeting with Kishore for this week.",
};

ASSISTANT

{
  "function": "GetUsersFunc",
  "params": [],
  "reason": "Retrieve the list of all users and their email addresses."
}

USER

[
	{name: 'Karey Higuera', email: 'karey@email.com'},
	{name: 'Kishore Mecal', email: 'kishore@email.com'},
	{name: 'Kabel Lemonk', email: 'kabel@email.com'},
	{name: 'Artair Umero', email: 'artair@email.com'}
]

ASSISTANT

{
  "function": "FindMeetingTimeFunc",
  "params": [{
    "users": [
      {"name": "Karey Higuera", "email": "karey@email.com"},
      {"name": "Kishore Mecal", "email": "kishore@email.com"}
    ],
    "duration": 60,
    "startDate": "2023-05-15",
    "endDate": "2023-05-19"
  }],
  "reason": "Find potential meeting times for Karey Higuera and Kishore Mecal with a duration of 60 minutes between May 15th and May 19th."
}

USER

[
	{
		startTime: '2023-05-16T05:00:00.000Z',
		endTime: '2023-05-16T06:00:00.000Z'
	},
	{
		startTime: '2023-05-17T08:00:00.000Z',
		endTime: '2023-05-17T09:00:00.000Z'
	},
	{
		startTime: '2023-05-19T19:00:00.000Z',
		endTime: '2023-05-19T20:00:00.000Z'
	}
]

ASSISTANT

{
  "function": "CommunicateWithUserFunc",
  "params": [
    "I have found some potential meeting times for you and Kishore. Here are the options:\n\n1. May 16th, 5:00 AM - 6:00 AM\n2. May 17th, 8:00 AM - 9:00 AM\n3. May 19th, 7:00 PM - 8:00 PM\n\nPlease let me know which option works best for you."
  ],
  "reason": "Provide the user with the potential meeting times and ask for their preferred option."
}

USER

{
  user: {
    name: "Karey Higuera",
    email: "karey@email.com",
  },
  timestamp: "2023-05-11T19:33:02.879Z",
  response: "Can we actually do a 30 minute meeting? I don't need a whole hour",
};

ASSISTANT

{
  "function": "FindMeetingTimeFunc",
  "params": [{
    "users": [
      {"name": "Karey Higuera", "email": "karey@email.com"},
      {"name": "Kishore Mecal", "email": "kishore@email.com"}
    ],
    "duration": 30,
    "startDate": "2023-05-15",
    "endDate": "2023-05-19"
  }],
  "reason": "Find potential meeting times for Karey Higuera and Kishore Mecal with a duration of 30 minutes between May 15th and May 19th."
}

USER

[
  {
    startTime: "2023-05-16T05:00:00.000Z",
    endTime: "2023-05-16T05:30:00.000Z",
  },
  {
    startTime: "2023-05-17T08:00:00.000Z",
    endTime: "2023-05-17T08:30:00.000Z",
  },
  {
    startTime: "2023-05-19T19:00:00.000Z",
    endTime: "2023-05-19T19:30:00.000Z",
  },
]

ASSISTANT

{
  "function": "CommunicateWithUserFunc",
  "params": [
    "Great! I have found some potential meeting times for a 30-minute meeting between you and Kishore. Here are the options:\n\n1. May 16th, 5:00 AM - 5:30 AM\n2. May 17th, 8:00 AM - 8:30 AM\n3. May 19th, 7:00 PM - 7:30 PM\n\nPlease let me know which option works best for you."
  ],
  "reason": "Provide the user with the updated potential meeting times for a 30-minute meeting and ask for their preferred option."
}

From note Sample calendaring conversation with GPT-3.5