From 240cddbcaf0be27e78dbad38d406c0f9055948ee Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 13 Nov 2025 12:20:27 +0800 Subject: [PATCH] Implement Execute method call in Create function for improved assistant creation handling --- agent/assistant/hook/create.go | 6 ++++++ agent/assistant/hook/create_test.go | 13 +++++++++++++ agent/testutils/testutils.go | 25 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 agent/assistant/hook/create_test.go create mode 100644 agent/testutils/testutils.go diff --git a/agent/assistant/hook/create.go b/agent/assistant/hook/create.go index 1d5fec4f..aba8ebcd 100644 --- a/agent/assistant/hook/create.go +++ b/agent/assistant/hook/create.go @@ -4,5 +4,11 @@ import "github.com/yaoapp/yao/agent/context" // Create create a new assistant func (s *Script) Create(ctx *context.Context, messages []context.Message) (*context.ResponseHookCreate, error) { + res, err := s.Execute(ctx, "Create", messages) + if err != nil { + return nil, err + } + + _ = res return &context.ResponseHookCreate{}, nil } diff --git a/agent/assistant/hook/create_test.go b/agent/assistant/hook/create_test.go new file mode 100644 index 00000000..20a33957 --- /dev/null +++ b/agent/assistant/hook/create_test.go @@ -0,0 +1,13 @@ +package hook_test + +import ( + "testing" + + "github.com/yaoapp/yao/agent/testutils" +) + +// TestCreate test the create hook +func TestCreate(t *testing.T) { + testutils.Prepare(t) + defer testutils.Clean(t) +} diff --git a/agent/testutils/testutils.go b/agent/testutils/testutils.go new file mode 100644 index 00000000..5ea25003 --- /dev/null +++ b/agent/testutils/testutils.go @@ -0,0 +1,25 @@ +package testutils + +import ( + "testing" + + "github.com/yaoapp/yao/agent" + "github.com/yaoapp/yao/config" + "github.com/yaoapp/yao/test" +) + +// Prepare prepare the test environment +func Prepare(t *testing.T) { + test.Prepare(t, config.Conf) + + // Load agent + err := agent.Load(config.Conf) + if err != nil { + t.Fatal(err) + } +} + +// Clean clean the test environment +func Clean(t *testing.T) { + test.Clean() +}