Skip to content

Commit 59630a5

Browse files
committed
feat: added support to set variables in tester agent
1 parent e8400f5 commit 59630a5

12 files changed

Lines changed: 110 additions & 8 deletions

File tree

docs/docs/static/conversationsuite.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@
329329
},
330330
"apiKey": {
331331
"type": "string"
332+
},
333+
"variables": {
334+
"type": "object"
332335
}
333336
},
334337
"additionalProperties": false,

docs/docs/static/conversationtest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@
265265
},
266266
"apiKey": {
267267
"type": "string"
268+
},
269+
"variables": {
270+
"type": "object"
268271
}
269272
},
270273
"additionalProperties": false,

docs/docs/static/swagger.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,10 @@
517517
},
518518
"environmentName": {
519519
"type": "string"
520+
},
521+
"variables": {
522+
"type": "object",
523+
"additionalProperties": true
520524
}
521525
}
522526
}

docs/docs/static/swagger.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ definitions:
245245
type: string
246246
environmentName:
247247
type: string
248+
variables:
249+
additionalProperties: true
250+
type: object
248251
type: object
249252
host: localhost:8080
250253
info:

docs/docs/tests/agent-to-agent-tests.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,13 @@ Configures a Voiceflow agent to act as the tester instead of using OpenAI. When
150150

151151
- `environmentName`: The environment name of the tester Voiceflow agent (e.g., "production", "development")
152152
- `apiKey`: The API key for the tester Voiceflow agent (format: `VF.DM.xxxxx.xxxxx`)
153+
- `variables` (Optional): A map of variables to set in the tester agent after the launch event. These variables will be set using the [Voiceflow State Variables API](https://docs.voiceflow.com/reference/updatestatevariables-1) after launching the tester agent.
153154

154155
**Important Notes:**
155156

156157
- When using Voiceflow agent testing, the `persona` and `userInformation` properties are ignored
157158
- The tester agent should be pre-configured with appropriate conversation logic and any required user data
159+
- Variables are set immediately after the launch event, allowing you to initialize the tester agent's state for each test
158160
- OpenAI is still used for goal evaluation even when using Voiceflow agent testing
159161

160162
**Example:**
@@ -181,6 +183,12 @@ agent:
181183
voiceflowAgentTesterConfig:
182184
environmentName: "production"
183185
apiKey: "VF.DM.your-tester-agent-key"
186+
# Optional: Set variables in the tester agent
187+
variables:
188+
user_name: "John Doe"
189+
user_id: "12345"
190+
booking_type: "hotel"
191+
check_in_date: "2026-02-15"
184192
```
185193
186194
## Choosing Between Testing Methods
@@ -288,7 +296,8 @@ tests:
288296
✅ **Best Practices:**
289297

290298
- Design the tester agent with clear conversation flows
291-
- Include appropriate user information within the agent
299+
- Include appropriate user information within the agent or use the `variables` property to set dynamic values
300+
- Use the `variables` property to initialize agent state for different test scenarios
292301
- Test the tester agent independently before using in tests
293302
- Use meaningful environment names and secure API keys
294303

examples/tests/test_3.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ agent:
1111
voiceflowAgentTesterConfig:
1212
environmentName: "production"
1313
apiKey: "VF.DM.my.key"
14+
# Optional: Variables to set in the tester agent after launch
15+
# These variables will be set using the Voiceflow State API after the launch event
16+
variables:
17+
user_name: "John Doe"
18+
user_address: "12345"
19+
subscription_tier: "premium"
1420
# Note: This test type does not use userInformation since the tester is a Voiceflow agent
1521

1622
# yaml-language-server: $schema=https://voiceflow.xavidop.me/static/conversationtest.json

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.24.0
44

55
require (
66
github.com/pkg/errors v0.9.1
7-
github.com/sirupsen/logrus v1.9.3
7+
github.com/sirupsen/logrus v1.9.4
88
github.com/spf13/cobra v1.10.2
99
)
1010

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR
131131
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
132132
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
133133
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
134-
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
135-
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
134+
github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w=
135+
github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g=
136136
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
137137
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
138138
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
@@ -142,7 +142,6 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
142142
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
143143
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
144144
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
145-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
146145
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
147146
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
148147
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
@@ -190,7 +189,6 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
190189
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
191190
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
192191
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
193-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
194192
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
195193
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
196194
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

internal/types/tests/testTypes.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ type AgentTest struct {
1919

2020
// VoiceflowAgentTesterConfig defines configuration for using a Voiceflow agent as the tester
2121
type VoiceflowAgentTesterConfig struct {
22-
EnvironmentName string `yaml:"environmentName" json:"environmentName"`
23-
APIKey string `yaml:"apiKey" json:"apiKey"`
22+
EnvironmentName string `yaml:"environmentName" json:"environmentName"`
23+
APIKey string `yaml:"apiKey" json:"apiKey"`
24+
Variables map[string]interface{} `yaml:"variables,omitempty" json:"variables,omitempty"`
2425
}
2526

2627
// UserInfo represents information that the agent can use when requested

pkg/test/voiceflow-agent-runner.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/xavidop/voiceflow-cli/internal/global"
77
"github.com/xavidop/voiceflow-cli/internal/types/tests"
88
"github.com/xavidop/voiceflow-cli/internal/types/voiceflow/interact"
9+
"github.com/xavidop/voiceflow-cli/pkg/voiceflow"
910
)
1011

1112
// VoiceflowAgentTestRunner handles the execution of agent-to-agent tests using a Voiceflow agent as the tester
@@ -64,6 +65,22 @@ func (vatr *VoiceflowAgentTestRunner) ExecuteAgentTest(agentTest tests.AgentTest
6465
return fmt.Errorf("failed to launch conversation with tester agent: %w", err)
6566
}
6667

68+
// Update tester agent variables if provided
69+
if len(agentTest.VoiceflowAgentTesterConfig.Variables) > 0 {
70+
vatr.addLog(fmt.Sprintf("Setting %d variables in tester agent", len(agentTest.VoiceflowAgentTesterConfig.Variables)))
71+
err = voiceflow.UpdateStateVariables(
72+
vatr.testerEnvironmentName,
73+
vatr.testerUserID,
74+
agentTest.VoiceflowAgentTesterConfig.Variables,
75+
vatr.testerAPIKey,
76+
vatr.subdomainOverride,
77+
)
78+
if err != nil {
79+
return fmt.Errorf("failed to update tester agent variables: %w", err)
80+
}
81+
vatr.addLog("Successfully updated tester agent variables")
82+
}
83+
6784
// Launch the conversation with the target agent if newSessionPerTest is enabled
6885
if newSessionPerTest {
6986
vatr.addLog("Launching conversation with target Voiceflow agent (new session per test enabled)")

0 commit comments

Comments
 (0)