refactor: how to add a node type in workflow (#558)
This commit is contained in:
@@ -31,7 +31,9 @@ import (
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/entity/vo"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/execute"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes/exit"
|
||||
"github.com/coze-dev/coze-studio/backend/domain/workflow/internal/nodes/llm"
|
||||
schema2 "github.com/coze-dev/coze-studio/backend/domain/workflow/internal/schema"
|
||||
"github.com/coze-dev/coze-studio/backend/pkg/lang/ptr"
|
||||
)
|
||||
|
||||
@@ -53,7 +55,7 @@ func (r *WorkflowRunner) designateOptions(ctx context.Context) (context.Context,
|
||||
rootHandler := execute.NewRootWorkflowHandler(
|
||||
wb,
|
||||
executeID,
|
||||
workflowSC.requireCheckPoint,
|
||||
workflowSC.RequireCheckpoint(),
|
||||
eventChan,
|
||||
resumedEvent,
|
||||
exeCfg,
|
||||
@@ -67,7 +69,7 @@ func (r *WorkflowRunner) designateOptions(ctx context.Context) (context.Context,
|
||||
var nodeOpt einoCompose.Option
|
||||
if ns.Type == entity.NodeTypeExit {
|
||||
nodeOpt = nodeCallbackOption(key, ns.Name, eventChan, resumedEvent,
|
||||
ptr.Of(mustGetKey[vo.TerminatePlan]("TerminalPlan", ns.Configs)))
|
||||
ptr.Of(ns.Configs.(*exit.Config).TerminatePlan))
|
||||
} else if ns.Type != entity.NodeTypeLambda {
|
||||
nodeOpt = nodeCallbackOption(key, ns.Name, eventChan, resumedEvent, nil)
|
||||
}
|
||||
@@ -117,7 +119,7 @@ func (r *WorkflowRunner) designateOptions(ctx context.Context) (context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
if workflowSC.requireCheckPoint {
|
||||
if workflowSC.RequireCheckpoint() {
|
||||
opts = append(opts, einoCompose.WithCheckPointID(strconv.FormatInt(executeID, 10)))
|
||||
}
|
||||
|
||||
@@ -139,7 +141,7 @@ func WrapOptWithIndex(opt einoCompose.Option, parentNodeKey vo.NodeKey, index in
|
||||
|
||||
func (r *WorkflowRunner) designateOptionsForSubWorkflow(ctx context.Context,
|
||||
parentHandler *execute.WorkflowHandler,
|
||||
ns *NodeSchema,
|
||||
ns *schema2.NodeSchema,
|
||||
pathPrefix ...string) (opts []einoCompose.Option, err error) {
|
||||
var (
|
||||
resumeEvent = r.interruptEvent
|
||||
@@ -163,7 +165,7 @@ func (r *WorkflowRunner) designateOptionsForSubWorkflow(ctx context.Context,
|
||||
var nodeOpt einoCompose.Option
|
||||
if subNS.Type == entity.NodeTypeExit {
|
||||
nodeOpt = nodeCallbackOption(key, subNS.Name, eventChan, resumeEvent,
|
||||
ptr.Of(mustGetKey[vo.TerminatePlan]("TerminalPlan", subNS.Configs)))
|
||||
ptr.Of(subNS.Configs.(*exit.Config).TerminatePlan))
|
||||
} else {
|
||||
nodeOpt = nodeCallbackOption(key, subNS.Name, eventChan, resumeEvent, nil)
|
||||
}
|
||||
@@ -219,7 +221,7 @@ func (r *WorkflowRunner) designateOptionsForSubWorkflow(ctx context.Context,
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
func llmToolCallbackOptions(ctx context.Context, ns *NodeSchema, eventChan chan *execute.Event,
|
||||
func llmToolCallbackOptions(ctx context.Context, ns *schema2.NodeSchema, eventChan chan *execute.Event,
|
||||
sw *schema.StreamWriter[*entity.Message]) (
|
||||
opts []einoCompose.Option, err error) {
|
||||
// this is a LLM node.
|
||||
@@ -229,7 +231,8 @@ func llmToolCallbackOptions(ctx context.Context, ns *NodeSchema, eventChan chan
|
||||
panic("impossible: llmToolCallbackOptions is called on a non-LLM node")
|
||||
}
|
||||
|
||||
fcParams := getKeyOrZero[*vo.FCParam]("FCParam", ns.Configs)
|
||||
cfg := ns.Configs.(*llm.Config)
|
||||
fcParams := cfg.FCParam
|
||||
if fcParams != nil {
|
||||
if fcParams.WorkflowFCParam != nil {
|
||||
// TODO: try to avoid getting the workflow tool all over again
|
||||
@@ -272,7 +275,7 @@ func llmToolCallbackOptions(ctx context.Context, ns *NodeSchema, eventChan chan
|
||||
|
||||
toolHandler := execute.NewToolHandler(eventChan, funcInfo)
|
||||
opt := einoCompose.WithCallbacks(toolHandler)
|
||||
opt = einoCompose.WithLambdaOption(llm.WithNestedWorkflowOptions(nodes.WithOptsForNested(opt))).DesignateNode(string(ns.Key))
|
||||
opt = einoCompose.WithLambdaOption(nodes.WithOptsForNested(opt)).DesignateNode(string(ns.Key))
|
||||
opts = append(opts, opt)
|
||||
}
|
||||
}
|
||||
@@ -310,7 +313,7 @@ func llmToolCallbackOptions(ctx context.Context, ns *NodeSchema, eventChan chan
|
||||
|
||||
toolHandler := execute.NewToolHandler(eventChan, funcInfo)
|
||||
opt := einoCompose.WithCallbacks(toolHandler)
|
||||
opt = einoCompose.WithLambdaOption(llm.WithNestedWorkflowOptions(nodes.WithOptsForNested(opt))).DesignateNode(string(ns.Key))
|
||||
opt = einoCompose.WithLambdaOption(nodes.WithOptsForNested(opt)).DesignateNode(string(ns.Key))
|
||||
opts = append(opts, opt)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user