ExecuteWithActors 使用 Actor 模型执行工作流
(ctx context.Context, workflowID string, inputs map[string]any)
| 98 | |
| 99 | // ExecuteWithActors 使用 Actor 模型执行工作流 |
| 100 | func (e *ActorEngine) ExecuteWithActors(ctx context.Context, workflowID string, inputs map[string]any) (*WorkflowResult, error) { |
| 101 | // 加载工作流定义 |
| 102 | def, err := e.loadWorkflowDefinition(workflowID) |
| 103 | if err != nil { |
| 104 | return nil, fmt.Errorf("failed to load workflow definition: %w", err) |
| 105 | } |
| 106 | |
| 107 | // 验证输入 |
| 108 | if err := e.validateInputs(def, inputs); err != nil { |
| 109 | return nil, fmt.Errorf("invalid inputs: %w", err) |
| 110 | } |
| 111 | |
| 112 | // 创建执行实例 |
| 113 | execution, err := e.createExecution(def, inputs) |
| 114 | if err != nil { |
| 115 | return nil, fmt.Errorf("failed to create execution: %w", err) |
| 116 | } |
| 117 | |
| 118 | // 使用协调器执行 |
| 119 | resultCh := make(chan *WorkflowResult, 1) |
| 120 | errCh := make(chan error, 1) |
| 121 | |
| 122 | e.coordinatorPID.Tell(&ExecuteWorkflowMsg{ |
| 123 | Execution: execution, |
| 124 | ResultCh: resultCh, |
| 125 | ErrorCh: errCh, |
| 126 | }) |
| 127 | |
| 128 | // 等待完成 |
| 129 | select { |
| 130 | case result := <-resultCh: |
| 131 | return result, nil |
| 132 | case err := <-errCh: |
| 133 | return nil, err |
| 134 | case <-ctx.Done(): |
| 135 | _ = e.CancelExecution(execution.ID) |
| 136 | return nil, ctx.Err() |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // SpawnAgent 在 Actor 系统中创建 Agent |
| 141 | func (e *ActorEngine) SpawnAgent(ctx context.Context, nodeID string, agentConfig *types.AgentConfig, deps *pkgagent.Dependencies) (*actor.PID, error) { |
nothing calls this directly
no test coverage detected