Triggered Utterances
Triggered Utterances
The term “utterance” is a familiar term in Conversational AI. It's a single agent output or response used as an example to guide your agent’s behavior and output within a dialogue. It serves as a guide for shaping the agent’s responses to similar user inputs, ensuring its consistency and relevance in its interaction. For instance, if a user asks, “What time do you open tomorrow?” an utterance like, “We open at 8:00 AM tomorrow. Is there anything else I can assist you with?” demonstrates how the agent should respond clearly, politely, and proactively.
In Parlant we have a different process to utterances. In fact, consider utterances in Parlant a feature in itself rather than just a concept or a technique. Utterances allows you to guide your LLM into keeping the communication with the customer active while waiting for other actions to complete, making your agent interactive.
We've all had the experience where we asked an employee a question and they said "let me check that out for you" or "let me double check" before returning with a final answer. Or perhaps, while browsing a store without making a purchase, an employee asks "is there anything I can help you with?" or "do you have everything you need?". Utterances allow your AI agents to replicate those human-like interactions.
Utterances Modes
There are two types of utterances to work with at the moment. The first handles delegation while an action is being processed, and the second creates a follow-up action or interaction based on a specific condition. Let’s break them down further and explore some practical examples to help you implement each effectively.
Delegation During Action Processing
This delegation method is particularly useful when your agent is handling a mid-to-heavy task, like fetching data or performing complex calculations or verifications that typically take more than just a few seconds to complete. It allows the agent to reassure the customer that their request is actively being processed, in a more human-like manner such as “Let me check that out for you”. This type of utterance serves as a placeholder, helping manage the user's expectations while the task is still in progress.
You implement this utterance in your tool service whenever a tool is being used that would typically take relatively more time than usual considering you’re communicating with a customer. Triggering it involves creating a message event inside the session in the form of a post request within your tool. Here’s a simple example of its use:
#/modules/tech_store.py
@tool
async def checking_inventory(context: ToolContext, user_query: str) -> ToolResult:
"""
This is an example for using the utterances feature
"""
# your code goes here and while you wait for an response use the following
# code to notify your customer that you're currently checking for an answer
async with httpx.AsyncClient(follow_redirects=True, timeout=30) as client:
(
await client.post(
f"http://localhost:8800/sessions/{context.session_id}/events",
json={
"kind": "message",
"source": "ai_agent",
"actions": [
{
"action": "Tell the user to hold still while you check the inventory",
"reason": "buy_time",
}
],
},
)
).raise_for_status().json()
return ToolResult(data="Product is in stock")
While you create a message event to the client while this tool is being processed, you pass the following actions parameters to create your utterance:
action
: What to notify the user while this tool is being processed
reason
: "buy_time"
is the term used when you don’t want the customer to think that the agent is not responding and therefore need to send an utterance notifying that the tool is being processed.
Conditional Follow-Up Actions
We use conditional follow up utterances when we want the agent to send a follow up message or a “ping” whenever the condition is met; such as creating a condition where if the customer hasn’t responded in 25 seconds to “ping” the customer asking if they need anymore guidance or creating a condition for when a user verified a step in your application without interacting with the agent.
This is mainly done through the client side of your application.
#yam - for thjis example im not well suited. i need a code case example