MCPcopy Create free account
hub / github.com/astercloud/aster / executeTaskNode

Method executeTaskNode

pkg/workflow/engine.go:623–666  ·  view source on GitHub ↗

executeTaskNode 执行任务节点

(execution *WorkflowExecution, node *NodeDef, result *NodeResult)

Source from the content-addressed store, hash-verified

621
622// executeTaskNode 执行任务节点
623func (e *Engine) executeTaskNode(execution *WorkflowExecution, node *NodeDef, result *NodeResult) error {
624 if node.Agent == nil {
625 return errors.New("task node requires agent configuration")
626 }
627
628 // 创建Agent
629 agent, err := e.agentFactory.CreateAgent(execution.Context.Context, node.Agent, node.Config)
630 if err != nil {
631 return fmt.Errorf("failed to create agent: %w", err)
632 }
633
634 // 准备输入消息
635 inputMessage, err := e.prepareInputMessage(execution, node)
636 if err != nil {
637 return fmt.Errorf("failed to prepare input: %w", err)
638 }
639
640 // 设置超时
641 ctx := execution.Context.Context
642 if node.Timeout > 0 {
643 var cancel context.CancelFunc
644 ctx, cancel = context.WithTimeout(ctx, node.Timeout)
645 defer cancel()
646 }
647
648 // 执行Agent
649 reader := agent.Execute(ctx, inputMessage)
650 for {
651 event, err := reader.Recv()
652 if err != nil {
653 if errors.Is(err, io.EOF) {
654 break
655 }
656 return fmt.Errorf("agent execution failed: %w", err)
657 }
658
659 if event != nil {
660 // 处理事件
661 result.Outputs = e.processAgentEvent(event, result.Outputs)
662 }
663 }
664
665 return nil
666}
667
668// executeConditionNode 执行条件节点
669func (e *Engine) executeConditionNode(execution *WorkflowExecution, node *NodeDef, result *NodeResult) error {

Callers 1

executeNodeMethod · 0.95

Calls 7

prepareInputMessageMethod · 0.95
processAgentEventMethod · 0.95
cancelFunction · 0.85
RecvMethod · 0.80
CreateAgentMethod · 0.65
ExecuteMethod · 0.65
WithTimeoutMethod · 0.45

Tested by

no test coverage detected