Escalating to Human Support
Often times, you will want to build a way for users to escalate to a human support agent. One way to do this would be to present the user with button options after high-confidence answers.
In this example, we are answering user questions in a Slack channel. After every high-confidence answer, we present two buttons to them. If the user clicks "Resolved", we will tag the thread as resolved and terminate the agent. If they click "I want Human Support", we will open a Zendesk ticket on their behalf (and keep the two sides in sync). If they continue asking questions in the thread, the bot will continue responding.
Currently only available for Slack
from runllm import Agent, AnswerCategory, Event, SlackListener, SlackChannel
from runllm.decorators import entrypoint
@entrypoint(
listeners=[SlackListener(
team_id="T123456",
channels=[SlackChannel(channel_id="C123456")]
)],
)
def escalation_workflow(agent: Agent, event: Event):
convo = event.conversation
slack_thread = convo.surface
answer = agent.answer(convo)
if answer.category is AnswerCategory.ANSWERED:
# Present the buttons after the answer is given.
blocks = [{
"type": "buttons",
"buttons": [
{"id": "resolved", "style": "primary", "text": "Resolved"},
{"id": "escalate", "style": "danger", "text": "I Need Human Support"}
]
}]
button_clicked = agent.send_to_slack_thread(
answer,
slack_thread,
blocks=blocks,
block_until_button_clicked=True,
)
# Apply the tag and terminate.
if button_clicked.id == "resolved":
agent.apply_tag("Resolved", convo)
agent.terminate()
else:
# Summarize the ticket in the zendesk body.
summary = agent.summarize()
ticket = agent.create_zendesk_ticket(
convo,
tags=convo.tags,
description=(
f"Slack thread discussion: {slack_thread.link()}\n\n"
f"Summary:\n {summary}"
)
)
# Notify the Slack thread that a human agent will follow up soon.
agent.send_to_slack_thread(
"We've filed a ticket with our support team. They will reach out on this thread within 1 business day.",
slack_thread,
)
agent.terminate(keep_in_sync=[ticket, slack_thread])
else:
# Otherwise, answer normally.
agent.send_to_slack_thread(answer, to=slack_thread)