-
Notifications
You must be signed in to change notification settings - Fork 71
feat(adk): add HITL with Desk page #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
029768c
feat(adk): add HITL with Desk page and update HITL page cross-reference
jacksonyzj b91511e
fix(adk): suppress model message after escalation tool call
jacksonyzj ab86ca7
fix(adk): clarify tool name, file path, and nav path in desk-hitl page
jacksonyzj 6b45e93
fix(adk): address review comments — backtick heading, add dark mode s…
jacksonyzj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| --- | ||
| title: HITL with Desk | ||
| description: Escalate conversations to support agents in Botpress Desk. | ||
| --- | ||
|
|
||
| The `desk-hitl` plugin connects your agent to Botpress Desk for human handoff. When escalated, your agent calls `startHitl` to create a Desk ticket and a support agent takes over from there. | ||
|
|
||
| <Frame> | ||
| <img alt="Botpress Desk main inbox view" className="block dark:hidden" src="./assets/desk-ui.png" /> | ||
| <img alt="Botpress Desk main inbox view" className="hidden dark:block" src="./assets/desk-ui-dark.png" /> | ||
| </Frame> | ||
|
|
||
| ## Add `desk-hitl` to your agent | ||
|
|
||
| Add the plugin to `agent.config.ts`: | ||
|
|
||
| ```typescript | ||
| import { defineConfig, z } from "@botpress/runtime" | ||
|
|
||
| export default defineConfig({ | ||
| name: "my-agent", | ||
|
|
||
| dependencies: { | ||
| integrations: { | ||
| webchat: "webchat@0.3.0", | ||
| }, | ||
| plugins: { | ||
| "desk-hitl": { | ||
| version: "desk-hitl@latest", | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| ### Customize handoff messages | ||
|
|
||
| Override the default messages the plugin sends when an agent joins or a session ends: | ||
|
|
||
| ```typescript | ||
| plugins: { | ||
| "desk-hitl": { | ||
| version: "desk-hitl@latest", | ||
| config: { | ||
| agentAssignedMessage: "A support agent has joined the conversation.", | ||
| sessionEndedMessage: "The support session has ended. Is there anything else I can help you with?", | ||
| }, | ||
| }, | ||
| }, | ||
| ``` | ||
|
|
||
| ## Connect your bot in Botpress Desk | ||
|
|
||
| To enable escalations, link your bot to Botpress Desk from the Desk UI. This is a one-time step per bot. Your bot must be deployed at least once before it appears in the list. | ||
|
|
||
| <Steps> | ||
| <Step> | ||
| Run `adk deploy` to deploy your bot. | ||
| </Step> | ||
| <Step> | ||
| Open [**Botpress Desk**](/desk/introduction). | ||
| </Step> | ||
| <Step> | ||
| Go to **AI Agents → Deflecting Bots**. | ||
| </Step> | ||
| <Step> | ||
| Add your bot. | ||
| </Step> | ||
| </Steps> | ||
|
|
||
| <Frame> | ||
| <img alt="Deflecting Bots page in Botpress Desk settings" className="block dark:hidden" src="./assets/deflecting.png" /> | ||
| <img alt="Deflecting Bots page in Botpress Desk settings" className="hidden dark:block" src="./assets/deflecting-dark.png" /> | ||
| </Frame> | ||
|
|
||
| <Warning> | ||
| If you skip this step, `startHitl` will fail with: _"This bot is not connected to Botpress Desk. Enable it on the Deflecting Bots page in Botpress Desk, then republish."_ | ||
| </Warning> | ||
|
|
||
|
|
||
| ## Create an escalation tool | ||
|
|
||
| Wrap `startHitl` in an `Autonomous.Tool` so the model can decide when to escalate. Create a file called `handToSupport.ts` under `src/tools/`: | ||
|
|
||
| ```typescript | ||
| import { Autonomous, context, plugins, z } from "@botpress/runtime" | ||
|
|
||
| export default new Autonomous.Tool({ | ||
| name: "handToSupport", | ||
| description: | ||
| "Transfer the conversation to a support agent. Use when the user explicitly asks for a support agent, or when their issue is beyond the bot's capabilities.", | ||
| input: z.object({ | ||
| reason: z.string().describe("Why the conversation needs a support agent"), | ||
| priority: z.enum(["low", "medium", "high", "urgent"]).default("medium"), | ||
| }), | ||
| handler: async ({ reason, priority }) => { | ||
| const conversation = context.get("conversation") | ||
|
|
||
| await plugins["desk-hitl"].actions.startHitl({ | ||
| conversationId: conversation.id, | ||
| title: reason, | ||
| priority, | ||
| }) | ||
| }, | ||
| }) | ||
| ``` | ||
|
|
||
| Fields passed to `startHitl`: | ||
|
|
||
| | Field | Type | Description | | ||
| |-------|------|-------------| | ||
| | `conversationId` | `string` | The conversation to escalate — required | | ||
| | `title` | `string` | Ticket title shown in Desk | | ||
| | `priority` | `'low' \| 'medium' \| 'high' \| 'urgent'` | Ticket priority (default: `'medium'`) | | ||
| | `userName` | `string` | Customer name shown in the Desk ticket | | ||
| | `userEmail` | `string` | Customer email shown in the Desk ticket | | ||
|
|
||
| ## Use the tool in a conversation handler | ||
|
|
||
| Add the tool to `conversations/index.ts` and instruct the model when to use it: | ||
|
|
||
| ```typescript | ||
| import { Conversation } from "@botpress/runtime" | ||
| import handToSupport from "../tools/handToSupport" | ||
|
|
||
| export default new Conversation({ | ||
| channel: "*", | ||
| handler: async ({ execute }) => { | ||
| await execute({ | ||
| instructions: `You are a helpful support assistant. | ||
| If the user needs help beyond your capabilities or explicitly asks for a support agent, use the handToSupport tool. After calling it, do not send any message.`, | ||
| tools: [handToSupport], | ||
| }) | ||
| }, | ||
| }) | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.