CreateAndSpawn 创建并在 Actor 系统中启动 Agent
( ctx context.Context, system *actor.System, config *types.AgentConfig, name string, )
| 505 | |
| 506 | // CreateAndSpawn 创建并在 Actor 系统中启动 Agent |
| 507 | func (f *AgentActorFactory) CreateAndSpawn( |
| 508 | ctx context.Context, |
| 509 | system *actor.System, |
| 510 | config *types.AgentConfig, |
| 511 | name string, |
| 512 | ) (*actor.PID, error) { |
| 513 | agentActor, err := f.Create(ctx, config) |
| 514 | if err != nil { |
| 515 | return nil, err |
| 516 | } |
| 517 | |
| 518 | // 设置监督策略(Agent 应该在失败时重启) |
| 519 | props := &actor.Props{ |
| 520 | Name: name, |
| 521 | MailboxSize: 100, |
| 522 | SupervisorStrategy: actor.NewOneForOneStrategy(3, time.Minute, actor.DefaultDecider), |
| 523 | } |
| 524 | |
| 525 | pid := system.SpawnWithProps(agentActor, props) |
| 526 | return pid, nil |
| 527 | } |
| 528 | |
| 529 | // ============== 辅助函数 ============== |
| 530 |
nothing calls this directly
no test coverage detected