-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathworkflow_test.go
More file actions
53 lines (41 loc) · 1.77 KB
/
Copy pathworkflow_test.go
File metadata and controls
53 lines (41 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package adk_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.temporal.io/sdk/activity"
"go.temporal.io/sdk/testsuite"
"google.golang.org/adk/v2/model"
"go.temporal.io/sdk/contrib/googleadk"
adk "github.com/temporalio/samples-go/googleadk"
)
// TestAgentWorkflow drives AgentWorkflow through a scripted FakeModel — no live
// LLM. The model first calls the get_weather tool, then answers with text; the
// test asserts the tool ran (as a real activity) and its result reached the
// answer.
func TestAgentWorkflow(t *testing.T) {
var s testsuite.WorkflowTestSuite
env := s.NewTestWorkflowEnvironment()
env.RegisterWorkflow(adk.AgentWorkflow)
env.RegisterActivityWithOptions(adk.GetWeather, activity.RegisterOptions{Name: adk.WeatherToolName})
// Scripted model: turn 1 requests get_weather, turn 2 produces the final text.
fm := googleadk.NewFakeModel(
googleadk.FunctionCallResponse("call-1", adk.WeatherToolName, map[string]any{"city": "San Francisco"}),
googleadk.TextResponse("It's sunny, 72°F in San Francisco."),
)
acts, err := googleadk.NewActivities(googleadk.Config{
Models: map[string]googleadk.ModelFactory{
adk.ModelName: func(context.Context, string) (model.LLM, error) { return fm, nil },
},
})
require.NoError(t, err)
// Register the integration's InvokeModel activity by its stable name.
env.RegisterActivityWithOptions(acts.InvokeModel, activity.RegisterOptions{Name: googleadk.InvokeModelActivityName})
env.ExecuteWorkflow(adk.AgentWorkflow, "What's the weather in San Francisco?")
require.True(t, env.IsWorkflowCompleted())
require.NoError(t, env.GetWorkflowError())
var answer string
require.NoError(t, env.GetWorkflowResult(&answer))
assert.Contains(t, answer, "sunny")
}