executeTaskNode 执行任务节点
(execution *WorkflowExecution, node *NodeDef, result *NodeResult)
| 621 | |
| 622 | // executeTaskNode 执行任务节点 |
| 623 | func (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 执行条件节点 |
| 669 | func (e *Engine) executeConditionNode(execution *WorkflowExecution, node *NodeDef, result *NodeResult) error { |
no test coverage detected