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

Method Resume

pkg/core/pool.go:105–137  ·  view source on GitHub ↗

Resume 从存储中恢复 Agent

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

Source from the content-addressed store, hash-verified

103
104// Resume 从存储中恢复 Agent
105func (p *Pool) Resume(ctx context.Context, agentID string, config *types.AgentConfig) (*agent.Agent, error) {
106 p.mu.Lock()
107 defer p.mu.Unlock()
108
109 // 1. 检查是否已在池中
110 if ag, exists := p.agents[agentID]; exists {
111 return ag, nil
112 }
113
114 // 2. 检查池容量
115 if len(p.agents) >= p.maxAgents {
116 return nil, fmt.Errorf("pool is full (max %d agents)", p.maxAgents)
117 }
118
119 // 3. 检查存储中是否存在
120 _, err := p.deps.Store.LoadMessages(ctx, agentID)
121 if err != nil {
122 return nil, fmt.Errorf("agent not found in store: %s", agentID)
123 }
124
125 // 4. 设置 AgentID
126 config.AgentID = agentID
127
128 // 5. 创建 Agent (会自动加载状态)
129 ag, err := agent.Create(ctx, config, p.deps)
130 if err != nil {
131 return nil, fmt.Errorf("resume agent: %w", err)
132 }
133
134 // 6. 加入池
135 p.agents[agentID] = ag
136 return ag, nil
137}
138
139// Remove 从池中移除 Agent (不删除存储)
140func (p *Pool) Remove(agentID string) error {

Callers 1

TestPool_ResumeFunction · 0.95

Calls 2

CreateFunction · 0.92
LoadMessagesMethod · 0.65

Tested by 1

TestPool_ResumeFunction · 0.76