You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/tests/interaction-tests.md
+99Lines changed: 99 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,20 @@ description: These are some tests
20
20
interactions:
21
21
# The ID of the interactions
22
22
- id: test_1
23
+
user:
24
+
# the input type
25
+
# it could be text, audio or prompt
26
+
type: launch
27
+
# Optional: Variables to set in the agent state after this interaction
28
+
variables:
29
+
user_name: "John Doe"
30
+
account_type: "premium"
31
+
agent:
32
+
validate:
33
+
- type: traceType
34
+
value: speak
35
+
36
+
- id: test_2
23
37
user:
24
38
# the input type
25
39
# it could be text, audio or prompt
@@ -247,7 +261,92 @@ interactions:
247
261
value: "You selected yes"
248
262
```
249
263
264
+
## Setting Variables
265
+
266
+
You can set variables in the agent's state during a test using the `variables` property on any interaction. Variables are set using the [Voiceflow State Variables API](https://docs.voiceflow.com/reference/updatestatevariables-1) **after** the interaction completes. This is especially important for `launch` interactions, where the session must exist before variables can be set.
267
+
268
+
### When to Use Variables
269
+
270
+
- **Initialize agent state**: Set variables after launching a session to configure the agent's behavior
271
+
- **Simulate pre-existing data**: Set user data or context variables that your agent expects
272
+
- **Test different scenarios**: Use different variable values to test how your agent responds under various conditions
273
+
274
+
### How It Works
275
+
276
+
1. **For `launch` interactions**: The launch is executed first to create the session, then variables are set afterwards (the session must exist before variables can be set)
277
+
2. **For all other interactions**: Variables are set **before** the interaction executes, so the agent has access to them during the interaction
278
+
3. Subsequent interactions will have access to the updated variables
279
+
280
+
### Example
281
+
282
+
```yaml
283
+
name: Variable Setting Example
284
+
description: Test demonstrating variable setting in interaction tests
285
+
286
+
interactions:
287
+
- id: launch_conversation
288
+
user:
289
+
type: launch
290
+
# Variables are set AFTER the launch interaction creates the session
291
+
variables:
292
+
user_name: "John Doe"
293
+
account_type: "premium"
294
+
service_list: "basic, premium, enterprise"
295
+
agent:
296
+
validate:
297
+
- type: traceType
298
+
value: speak
299
+
300
+
- id: ask_about_account
301
+
user:
302
+
type: text
303
+
text: "What is my account type?"
304
+
agent:
305
+
validate:
306
+
- type: contains
307
+
value: "premium"
308
+
309
+
- id: update_preferences
310
+
user:
311
+
type: text
312
+
text: "Update my preferences"
313
+
# For non-launch interactions, variables are set BEFORE the interaction
314
+
variables:
315
+
preferred_language: "Spanish"
316
+
agent:
317
+
validate:
318
+
- type: contains
319
+
value: "preferences updated"
320
+
```
321
+
322
+
### Variable Types
323
+
324
+
Variables support any value type including strings, numbers, booleans, arrays, and objects:
325
+
326
+
```yaml
327
+
variables:
328
+
# String
329
+
user_name: "Jane Smith"
330
+
# Number
331
+
retry_count: 3
332
+
# Boolean
333
+
is_vip: true
334
+
# Object
335
+
user_profile:
336
+
name: "Jane Smith"
337
+
email: "jane@example.com"
338
+
# Array/List
339
+
selected_items:
340
+
- "item1"
341
+
- "item2"
342
+
```
343
+
344
+
### Important Notes
250
345
346
+
- For `launch` interactions, variables are set **after** the interaction (the session must exist first)
347
+
- For all other interactions, variables are set **before** the interaction executes
348
+
- The `variables` property uses the same underlying API as the [Agent-to-Agent testing variables](/tests/agent-to-agent-tests/#voiceflowagenttargetconfig-voiceflow-agent-to-agent-testing-only)
349
+
- Variables are merged with existing state variables (PATCH operation), not replacing them entirely
0 commit comments