Standardize action results
This commit is contained in:
13
core/action/action_suite_test.go
Normal file
13
core/action/action_suite_test.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package action_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestAction(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Agent Action test suite")
|
||||
}
|
||||
@@ -75,15 +75,16 @@ func (a *CustomAction) initializeInterpreter() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *CustomAction) Run(ctx context.Context, params ActionParams) (string, error) {
|
||||
func (a *CustomAction) Run(ctx context.Context, params ActionParams) (ActionResult, error) {
|
||||
v, err := a.i.Eval(fmt.Sprintf("%s.Run", a.config["name"]))
|
||||
if err != nil {
|
||||
return "", err
|
||||
return ActionResult{}, err
|
||||
}
|
||||
|
||||
run := v.Interface().(func(map[string]interface{}) (string, error))
|
||||
run := v.Interface().(func(map[string]interface{}) (string, map[string]interface{}, error))
|
||||
|
||||
return run(params)
|
||||
res, meta, err := run(params)
|
||||
return ActionResult{Result: res, Metadata: meta}, err
|
||||
}
|
||||
|
||||
func (a *CustomAction) Definition() ActionDefinition {
|
||||
|
||||
@@ -23,18 +23,18 @@ type Params struct {
|
||||
Foo string
|
||||
}
|
||||
|
||||
func Run(config map[string]interface{}) (string, error) {
|
||||
func Run(config map[string]interface{}) (string, map[string]interface{}, error) {
|
||||
|
||||
p := Params{}
|
||||
b, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "",map[string]interface{}{}, err
|
||||
}
|
||||
if err := json.Unmarshal(b, &p); err != nil {
|
||||
return "", err
|
||||
return "",map[string]interface{}{}, err
|
||||
}
|
||||
|
||||
return p.Foo, nil
|
||||
return p.Foo,map[string]interface{}{}, nil
|
||||
}
|
||||
|
||||
func Definition() map[string][]string {
|
||||
@@ -79,7 +79,7 @@ return []string{"foo"}
|
||||
"Foo": "bar",
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(runResult).To(Equal("bar"))
|
||||
Expect(runResult.Result).To(Equal("bar"))
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
@@ -28,6 +28,11 @@ func NewContext(ctx context.Context, cancel context.CancelFunc) *ActionContext {
|
||||
|
||||
type ActionParams map[string]interface{}
|
||||
|
||||
type ActionResult struct {
|
||||
Result string
|
||||
Metadata map[string]interface{}
|
||||
}
|
||||
|
||||
func (ap ActionParams) Read(s string) error {
|
||||
err := json.Unmarshal([]byte(s), &ap)
|
||||
return err
|
||||
|
||||
@@ -21,8 +21,8 @@ type IntentResponse struct {
|
||||
Reasoning string `json:"reasoning"`
|
||||
}
|
||||
|
||||
func (a *IntentAction) Run(context.Context, ActionParams) (string, error) {
|
||||
return "no-op", nil
|
||||
func (a *IntentAction) Run(context.Context, ActionParams) (ActionResult, error) {
|
||||
return ActionResult{}, nil
|
||||
}
|
||||
|
||||
func (a *IntentAction) Definition() ActionDefinition {
|
||||
|
||||
@@ -18,8 +18,8 @@ type ConversationActionResponse struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (a *ConversationAction) Run(context.Context, ActionParams) (string, error) {
|
||||
return "no-op", nil
|
||||
func (a *ConversationAction) Run(context.Context, ActionParams) (ActionResult, error) {
|
||||
return ActionResult{}, nil
|
||||
}
|
||||
|
||||
func (a *ConversationAction) Definition() ActionDefinition {
|
||||
|
||||
@@ -12,8 +12,8 @@ func NewStop() *StopAction {
|
||||
|
||||
type StopAction struct{}
|
||||
|
||||
func (a *StopAction) Run(context.Context, ActionParams) (string, error) {
|
||||
return "no-op", nil
|
||||
func (a *StopAction) Run(context.Context, ActionParams) (ActionResult, error) {
|
||||
return ActionResult{}, nil
|
||||
}
|
||||
|
||||
func (a *StopAction) Definition() ActionDefinition {
|
||||
|
||||
@@ -19,8 +19,8 @@ type ReasoningResponse struct {
|
||||
Reasoning string `json:"reasoning"`
|
||||
}
|
||||
|
||||
func (a *ReasoningAction) Run(context.Context, ActionParams) (string, error) {
|
||||
return "no-op", nil
|
||||
func (a *ReasoningAction) Run(context.Context, ActionParams) (ActionResult, error) {
|
||||
return ActionResult{}, nil
|
||||
}
|
||||
|
||||
func (a *ReasoningAction) Definition() ActionDefinition {
|
||||
|
||||
@@ -33,8 +33,8 @@ type StateResult struct {
|
||||
Goal string `json:"goal"`
|
||||
}
|
||||
|
||||
func (a *StateAction) Run(context.Context, ActionParams) (string, error) {
|
||||
return "internal state has been updated", nil
|
||||
func (a *StateAction) Run(context.Context, ActionParams) (ActionResult, error) {
|
||||
return ActionResult{Result: "internal state has been updated"}, nil
|
||||
}
|
||||
|
||||
func (a *StateAction) Definition() ActionDefinition {
|
||||
|
||||
Reference in New Issue
Block a user