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

Method Create

pkg/core/pool.go:43–66  ·  view source on GitHub ↗

Create 创建新 Agent 并加入池

(ctx context.Context, config *types.AgentConfig)

Source from the content-addressed store, hash-verified

41
42// Create 创建新 Agent 并加入池
43func (p *Pool) Create(ctx context.Context, config *types.AgentConfig) (*agent.Agent, error) {
44 p.mu.Lock()
45 defer p.mu.Unlock()
46
47 // 检查是否已存在
48 if _, exists := p.agents[config.AgentID]; exists {
49 return nil, fmt.Errorf("agent already exists: %s", config.AgentID)
50 }
51
52 // 检查池容量
53 if len(p.agents) >= p.maxAgents {
54 return nil, fmt.Errorf("pool is full (max %d agents)", p.maxAgents)
55 }
56
57 // 创建 Agent
58 ag, err := agent.Create(ctx, config, p.deps)
59 if err != nil {
60 return nil, fmt.Errorf("create agent: %w", err)
61 }
62
63 // 加入池
64 p.agents[config.AgentID] = ag
65 return ag, nil
66}
67
68// Get 获取指定 Agent
69func (p *Pool) Get(agentID string) (*agent.Agent, bool) {

Callers 15

TestRoom_JoinAndLeaveFunction · 0.95
TestRoom_JoinDuplicateFunction · 0.95
TestRoom_GetMembersFunction · 0.95
TestRoom_SayFunction · 0.95
TestRoom_BroadcastFunction · 0.95
TestRoom_SendToFunction · 0.95
TestRoom_ClearHistoryFunction · 0.95
TestPool_CreateFunction · 0.95
TestPool_CreateDuplicateFunction · 0.95
TestPool_MaxCapacityFunction · 0.95
TestPool_ListFunction · 0.95
TestPool_RemoveFunction · 0.95

Calls 1

CreateFunction · 0.92

Tested by 15

TestRoom_JoinAndLeaveFunction · 0.76
TestRoom_JoinDuplicateFunction · 0.76
TestRoom_GetMembersFunction · 0.76
TestRoom_SayFunction · 0.76
TestRoom_BroadcastFunction · 0.76
TestRoom_SendToFunction · 0.76
TestRoom_ClearHistoryFunction · 0.76
TestPool_CreateFunction · 0.76
TestPool_CreateDuplicateFunction · 0.76
TestPool_MaxCapacityFunction · 0.76
TestPool_ListFunction · 0.76
TestPool_RemoveFunction · 0.76