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

Method executeTaskNodeWithActor

pkg/workflow/actor_engine.go:381–436  ·  view source on GitHub ↗

executeTaskNodeWithActor 使用 Actor 执行任务节点

(execution *WorkflowExecution, state *workflowState, node *NodeDef)

Source from the content-addressed store, hash-verified

379
380// executeTaskNodeWithActor 使用 Actor 执行任务节点
381func (c *CoordinatorActor) executeTaskNodeWithActor(execution *WorkflowExecution, state *workflowState, node *NodeDef) error {
382 if node.Agent == nil {
383 return errors.New("task node requires agent configuration")
384 }
385
386 // 获取或创建 Agent PID
387 pid, ok := c.engine.GetAgentPID(node.ID)
388 if !ok {
389 // 需要创建 Agent - 这里简化处理,实际应该从 AgentFactory 创建
390 return fmt.Errorf("agent not found for node: %s", node.ID)
391 }
392
393 // 准备输入
394 inputMessage, err := c.prepareInputMessage(execution, node)
395 if err != nil {
396 return err
397 }
398
399 // 通过 Actor 消息执行
400 replyCh := make(chan *pkgagent.ChatResultMsg, 1)
401 pid.Tell(&pkgagent.ChatMsg{
402 Text: inputMessage,
403 Ctx: execution.Context.Context,
404 ReplyTo: replyCh,
405 })
406
407 // 等待结果
408 timeout := node.Timeout
409 if timeout == 0 {
410 timeout = c.engine.actorConfig.DefaultTimeout
411 }
412
413 select {
414 case result := <-replyCh:
415 if result.Error != nil {
416 return result.Error
417 }
418 // 保存结果
419 execution.NodeResults[node.ID] = &NodeResult{
420 NodeID: node.ID,
421 NodeName: node.Name,
422 NodeType: node.Type,
423 Status: StatusCompleted,
424 Outputs: map[string]any{
425 "content": result.Result.Text,
426 },
427 }
428 return nil
429
430 case <-time.After(timeout):
431 return fmt.Errorf("task node %s timed out", node.ID)
432
433 case <-execution.Context.Context.Done():
434 return execution.Context.Context.Err()
435 }
436}
437
438// executeParallelNodeWithActors 使用 Actor 执行并行节点

Callers 1

executeNodesMethod · 0.95

Calls 3

prepareInputMessageMethod · 0.95
GetAgentPIDMethod · 0.80
TellMethod · 0.80

Tested by

no test coverage detected