Skip to content

Commit e8400f5

Browse files
committed
fix: force new session for new conversations
1 parent e0c8e9b commit e8400f5

4 files changed

Lines changed: 31 additions & 20 deletions

File tree

pkg/test/agent-runner.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewAgentTestRunner(environmentName, userID, apiKeyOverride, subdomainOverri
3535
}
3636

3737
// ExecuteAgentTest runs an agent-to-agent test
38-
func (atr *AgentTestRunner) ExecuteAgentTest(agentTest tests.AgentTest) error {
38+
func (atr *AgentTestRunner) ExecuteAgentTest(agentTest tests.AgentTest, newSessionPerTest bool) error {
3939
// Set up user information for easy lookup
4040
for _, info := range agentTest.UserInformation {
4141
atr.userInformation[info.Name] = info.Value
@@ -57,11 +57,16 @@ func (atr *AgentTestRunner) ExecuteAgentTest(agentTest tests.AgentTest) error {
5757
currentStep := 0
5858
goalAchieved := false
5959

60-
// Launch the conversation
61-
atr.addLog("Launching conversation with Voiceflow agent")
62-
voiceflowResponse, err := atr.interactWithVoiceflow("launch", "")
63-
if err != nil {
64-
return fmt.Errorf("failed to launch conversation: %w", err)
60+
var voiceflowResponse []interact.InteractionResponse
61+
var err error
62+
63+
// Launch the conversation if newSessionPerTest is enabled
64+
if newSessionPerTest {
65+
atr.addLog("Launching conversation with Voiceflow agent (new session per test enabled)")
66+
voiceflowResponse, err = atr.interactWithVoiceflow("launch", "")
67+
if err != nil {
68+
return fmt.Errorf("failed to launch conversation: %w", err)
69+
}
6570
}
6671

6772
// Process the initial response

pkg/test/execute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func executeHTTPSuite(suiteReq HTTPSuiteRequest, logCollector *LogCollector) err
9393
logCollector.AddLog("User ID for test " + testReq.ID + ": " + userID)
9494
}
9595
logCollector.AddLog("Running Test ID: " + testReq.ID)
96-
err := runTest(suiteReq.EnvironmentName, userID, testReq.Test, suiteReq.ApiKey, suiteReq.VoiceflowSubdomain, logCollector, suiteReq.OpenAIConfig)
96+
err := runTest(suiteReq.EnvironmentName, userID, testReq.Test, suiteReq.ApiKey, suiteReq.VoiceflowSubdomain, logCollector, suiteReq.OpenAIConfig, suiteReq.NewSessionPerTest)
9797
if err != nil {
9898
errorMsg := "Error running test " + testReq.ID + ": " + err.Error()
9999
logCollector.AddLog(errorMsg)
@@ -138,7 +138,7 @@ func ExecuteSuite(suitesPath string) error {
138138
}
139139
// Create a dummy log collector for the existing file-based execution
140140
logCollector := &LogCollector{Logs: []string{}}
141-
err = runTest(suite.EnvironmentName, userID, test, "", "", logCollector, suite.OpenAIConfig) // Pass suite-level OpenAI config
141+
err = runTest(suite.EnvironmentName, userID, test, "", "", logCollector, suite.OpenAIConfig, suite.NewSessionPerTest) // Pass suite-level OpenAI config
142142
if err != nil {
143143
global.Log.Errorf("Error running test: %v", err)
144144
return err

pkg/test/runner.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515
)
1616

1717
// Function to simulate running a test
18-
func runTest(environmentName, userID string, test tests.Test, apiKeyOverride, subdomainOverride string, logCollector *LogCollector, suiteOpenAIConfig *tests.OpenAIConfig) error {
18+
func runTest(environmentName, userID string, test tests.Test, apiKeyOverride, subdomainOverride string, logCollector *LogCollector, suiteOpenAIConfig *tests.OpenAIConfig, newSessionPerTest bool) error {
1919
logCollector.AddLog("Running Test ID: " + test.Name)
2020

2121
// Check if this is an agent test
2222
if test.Agent != nil {
23-
return runAgentTest(environmentName, userID, test, apiKeyOverride, subdomainOverride, logCollector, suiteOpenAIConfig)
23+
return runAgentTest(environmentName, userID, test, apiKeyOverride, subdomainOverride, logCollector, suiteOpenAIConfig, newSessionPerTest)
2424
}
2525

2626
// Original interaction-based test logic
@@ -86,7 +86,7 @@ func runTest(environmentName, userID string, test tests.Test, apiKeyOverride, su
8686
}
8787

8888
// runAgentTest executes an agent-to-agent test
89-
func runAgentTest(environmentName, userID string, test tests.Test, apiKeyOverride, subdomainOverride string, logCollector *LogCollector, suiteOpenAIConfig *tests.OpenAIConfig) error {
89+
func runAgentTest(environmentName, userID string, test tests.Test, apiKeyOverride, subdomainOverride string, logCollector *LogCollector, suiteOpenAIConfig *tests.OpenAIConfig, newSessionPerTest bool) error {
9090
logCollector.AddLog("Executing agent-to-agent test: " + test.Name)
9191

9292
agentTest := *test.Agent
@@ -104,7 +104,7 @@ func runAgentTest(environmentName, userID string, test tests.Test, apiKeyOverrid
104104
runner := NewVoiceflowAgentTestRunner(environmentName, userID, apiKeyOverride, subdomainOverride, logCollector)
105105

106106
// Execute the Voiceflow agent test
107-
return runner.ExecuteAgentTest(agentTest)
107+
return runner.ExecuteAgentTest(agentTest, newSessionPerTest)
108108
}
109109

110110
// Default to OpenAI-based agent testing
@@ -114,7 +114,7 @@ func runAgentTest(environmentName, userID string, test tests.Test, apiKeyOverrid
114114
runner := NewAgentTestRunner(environmentName, userID, apiKeyOverride, subdomainOverride, logCollector)
115115

116116
// Execute the agent test
117-
return runner.ExecuteAgentTest(agentTest)
117+
return runner.ExecuteAgentTest(agentTest, newSessionPerTest)
118118
}
119119

120120
func autoGenerateValidationsIDs(validations []tests.Validation) []tests.Validation {

pkg/test/voiceflow-agent-runner.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (vatr *VoiceflowAgentTestRunner) addLog(message string) {
3131
}
3232

3333
// ExecuteAgentTest runs an agent-to-agent test using a Voiceflow agent as the tester
34-
func (vatr *VoiceflowAgentTestRunner) ExecuteAgentTest(agentTest tests.AgentTest) error {
34+
func (vatr *VoiceflowAgentTestRunner) ExecuteAgentTest(agentTest tests.AgentTest, newSessionPerTest bool) error {
3535
// Validate that we have the required Voiceflow agent tester configuration
3636
if agentTest.VoiceflowAgentTesterConfig == nil {
3737
return fmt.Errorf("voiceflowAgentTesterConfig is required for Voiceflow agent testing")
@@ -54,12 +54,8 @@ func (vatr *VoiceflowAgentTestRunner) ExecuteAgentTest(agentTest tests.AgentTest
5454
currentStep := 0
5555
goalAchieved := false
5656

57-
// Launch the conversation with the target agent
58-
vatr.addLog("Launching conversation with target Voiceflow agent")
59-
targetAgentResponse, err := vatr.interactWithTargetAgent("launch", "")
60-
if err != nil {
61-
return fmt.Errorf("failed to launch conversation with target agent: %w", err)
62-
}
57+
var targetAgentResponse []interact.InteractionResponse
58+
var err error
6359

6460
// Launch the conversation with the tester agent and provide the goal
6561
vatr.addLog("Launching conversation with tester Voiceflow agent")
@@ -68,6 +64,16 @@ func (vatr *VoiceflowAgentTestRunner) ExecuteAgentTest(agentTest tests.AgentTest
6864
return fmt.Errorf("failed to launch conversation with tester agent: %w", err)
6965
}
7066

67+
// Launch the conversation with the target agent if newSessionPerTest is enabled
68+
if newSessionPerTest {
69+
vatr.addLog("Launching conversation with target Voiceflow agent (new session per test enabled)")
70+
targetAgentResponse, err = vatr.interactWithTargetAgent("launch", "")
71+
if err != nil {
72+
return fmt.Errorf("failed to launch conversation with target agent: %w", err)
73+
}
74+
75+
}
76+
7177
// Send the target agent's initial response to the tester agent
7278
vatr.addLog("Sending target agent's initial response to tester agent")
7379
// Use the initial response from the target agent as the first message to the tester agent

0 commit comments

Comments
 (0)