Function calling
In addition to providing answers to customers' questions, Markprompt is able to detect underlying intents and trigger code accordingly, such as to create a case. This is a concept know as function calling. The AI can detect a user's intent (such as "I want to speak with an agent"), make sure the user provides all the required details for the function to run, and display an adequate UI, e.g. to confirm an action.
Anatomy of a function
Here is a basic example of a function definition:
If consists of two mandatory fields:
- A function name
- A function description
The description is important. This is how the LLM is able to match a user's intent with a function call. Make it as clear and explicit as possible, and keep it concise.
Functions with parameters
Some functions require additional parameters. For instance, if the user is asking to cancel their subscription, the function may need to know about the end date:
In this example, you will notice that the cancellationDate
field is marked as required. Thus, if a user asks the question:
I want to cancel my renewal and get a refund
the AI will ask a follow-up question, inquiring about the desired cancellation date:
Sorry to see you go! When would you like your subscription to end?
Triggering a function call
Now that the function's intent has been specified, it is time to bind it to a function, which will be invoked when the intent is detected.
Using the SDK
The Markprompt React SDK provides helpers to easily setup callback functions that get triggered when a function call intent is detected. Here is an example using the ChatProvider
component:
Alternatively, function calls can be set up in the Markprompt dashboard via assistants.
Showing a confirmation UI
In some situations, it may not be desirable to automatically call the function without an explicit user confirmation. The SDK allows you to define a confirmation UI to show before the function is actually called. This is done via the ToolCallsConfirmation
prop. Here is an example:
Using the API
The Markprompt API also supports function calling. Instead of calling code, it will return a fully-specified JSON object with the required information to take adequate action:
If a function call intent is detected, the response will include a toolCalls
entry:
Biasing behavior towards function calling
Markprompt can be instructed to favor function calling over responding in text. For instance, if the user has an urgent billing issue and you would like this to trigger a case creation without the user explicitly asking for it, you can provide additional system prompt instructions stating this behavior. For instance:
- You must always prioritize creating a function call over returning a text response if the user enters a request that a function can handle.
- If the user has an urgent billing issue, immediately trigger a call to the
createCase
function.
Examples
Below are some examples making use of function calling: