Skip to content

Commit dfa66d5

Browse files
authored
[docs sprint] phrase trigger documentation (#16)
1 parent 7401140 commit dfa66d5

File tree

2 files changed

+96
-3
lines changed

2 files changed

+96
-3
lines changed

docs/mint.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@
4949
"navigation": [
5050
{
5151
"group": "Getting Started",
52-
"pages": ["welcome", "hosted-quickstart", "open-source-quickstart"]
52+
"pages": [
53+
"welcome",
54+
"hosted-quickstart",
55+
"open-source-quickstart"
56+
]
5357
},
5458
{
5559
"group": "Vocode 101",
@@ -67,6 +71,7 @@
6771
"open-source/create-your-own-agent",
6872
"open-source/langchain-agent",
6973
"open-source/action-agents",
74+
"open-source/action-phrase-triggers",
7075
"open-source/local-conversation",
7176
"open-source/events-manager",
7277
"open-source/using-synthesizers",
@@ -109,7 +114,9 @@
109114
},
110115
{
111116
"group": "Usage",
112-
"pages": ["api-reference/usage/get-usage"]
117+
"pages": [
118+
"api-reference/usage/get-usage"
119+
]
113120
},
114121
{
115122
"group": "Actions",
@@ -223,4 +230,4 @@
223230
"twitter": "https://twitter.com/vocodehq",
224231
"website": "https://www.vocode.dev/"
225232
}
226-
}
233+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
title: 'Action Triggers'
3+
description: 'Activate actions with function calls or specific phrases'
4+
---
5+
## What are function calls?
6+
[Function calls](https://platform.openai.com/docs/guides/function-calling) allow modern Large Language Models (LLMs) like ChatGPT to perform tasks outside of text generation.
7+
For example, if I create a math assistant with ChatGPT, I might make a "multiply" function that ChatGPT can call to multiply two numbers together.
8+
9+
If you add an action to a vocode agent, its corresponding function calling schema is added to each ChatGPT query. If the function call is outputted by ChatGPT, the corresponding action is triggered automatically.
10+
11+
***Note:*** *In vocode agents, ChatGPT can return a text response alongside a function call. In this scenario, the text is synthesized and played first, then the action is run.*
12+
13+
## What are phrase triggers?
14+
15+
Phrase triggers are text phrases that activate an action when produced by an agent. Phrase triggers are useful in production use-cases where consistency and reliability are important, since text outputs are easier to control in comparison to function calls.
16+
17+
## Configuring action triggers
18+
Each vocode action config contains an `action_trigger` field to specify how the action is triggered. The default trigger is function calling. The examples below demonstrate how to set action triggers for an `EndConversation` action config:
19+
20+
**Function calls:**
21+
```python
22+
from vocode.streaming.action.end_conversation import EndConversationVocodeActionConfig
23+
from vocode.streaming.models.actions import FunctionCallActionTrigger
24+
25+
EndConversationVocodeActionConfig(
26+
type="action_end_conversation",
27+
action_trigger=FunctionCallActionTrigger(
28+
type="action_trigger_function_call"
29+
)
30+
)
31+
```
32+
***Note:*** *You can also leave `action_trigger` field empty and vocode will default to function calls.*
33+
34+
**Phrase triggers:**
35+
36+
```python
37+
from vocode.streaming.action.end_conversation import EndConversationVocodeActionConfig
38+
from vocode.streaming.models.actions import PhraseBasedActionTrigger, PhraseBasedActionTriggerConfig, PhraseTrigger
39+
40+
EndConversationVocodeActionConfig(
41+
type="action_end_conversation",
42+
action_trigger=PhraseBasedActionTrigger(
43+
type = "action_trigger_phrase_based",
44+
config: PhraseBasedActionTriggerConfig(
45+
phrase_triggers = [
46+
PhraseTrigger(
47+
phrase="Ending conversation now",
48+
condition="phrase_condition_type_contains"
49+
),
50+
# Additional phrase triggers can be listed here
51+
]
52+
)
53+
)
54+
)
55+
```
56+
For the code above, if the agent says 'Ending conversation now', the end conversation action will automatically be taken.
57+
You can add multiple phrase triggers for an action by passing a list of `PhraseTrigger` instances.
58+
59+
The `phrase_condition_type_contains` condition configures the agent to run the action if its output *contains* the phrase. So, the action will also be run if the agent
60+
says 'I am ending conversation now'.
61+
62+
## Example Scenario
63+
64+
Let's assume we have an action called `TurnOnLight` that turns on your bedroom light when activated. Take the following conversation:
65+
```plaintext
66+
Human: Hello
67+
AI: How can I assist you today?
68+
Human: Please turn on the lights.
69+
```
70+
71+
If the action is triggered via a function call, the bot may respond with:
72+
```plaintext
73+
AI: Sure!
74+
BOT_ACTION_START: Running `action_turn_on_light`
75+
```
76+
or it may run the action without saying anything.
77+
78+
If we use a phrase trigger instead, we may do the following:
79+
1. In our prompt, write "If the human asks to turn on the lights, say 'I will turn on the lights now' verbatim"
80+
2. Configure `TurnOnLight` with "I will turn on the lights now" as its phrase trigger
81+
82+
Then, the bot will respond with:
83+
```
84+
AI: I will turn on the lights now.
85+
BOT_ACTION_START: Running `action_turn_on_light`
86+
```

0 commit comments

Comments
 (0)