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

Method Receive

pkg/agent/actor.go:174–240  ·  view source on GitHub ↗

Receive 处理接收到的消息(Actor 核心方法)

(ctx *actor.Context, msg actor.Message)

Source from the content-addressed store, hash-verified

172
173// Receive 处理接收到的消息(Actor 核心方法)
174func (a *AgentActor) Receive(ctx *actor.Context, msg actor.Message) {
175 a.mu.Lock()
176 a.stats.MessagesReceived++
177 a.stats.LastMessageAt = time.Now()
178 a.mu.Unlock()
179
180 startTime := time.Now()
181
182 defer func() {
183 // 更新统计
184 a.mu.Lock()
185 a.stats.MessagesHandled++
186 latency := time.Since(startTime)
187 // 简单的移动平均
188 a.stats.AverageLatency = (a.stats.AverageLatency + latency) / 2
189 a.mu.Unlock()
190 }()
191
192 // 处理系统消息
193 switch m := msg.(type) {
194 case *actor.Started:
195 agentLog.Debug(context.Background(), "agent actor started", map[string]any{"agent_id": a.agent.ID()})
196 return
197
198 case *actor.Stopping:
199 agentLog.Debug(context.Background(), "agent actor stopping", map[string]any{"agent_id": a.agent.ID()})
200 a.handleStop()
201 return
202
203 case *actor.Stopped:
204 agentLog.Debug(context.Background(), "agent actor stopped", map[string]any{"agent_id": a.agent.ID()})
205 return
206
207 case *actor.Restarting:
208 agentLog.Debug(context.Background(), "agent actor restarting", map[string]any{"agent_id": a.agent.ID()})
209 return
210
211 // 处理 Agent 业务消息
212 case *SendMsg:
213 a.handleSend(ctx, m)
214
215 case *ChatMsg:
216 a.handleChat(ctx, m)
217
218 case *StreamMsg:
219 a.handleStream(ctx, m)
220
221 case *ToolCallMsg:
222 a.handleToolCall(ctx, m)
223
224 case *DirectToolCallMsg:
225 a.handleDirectToolCall(ctx, m)
226
227 case *BatchToolCallMsg:
228 a.handleBatchToolCall(ctx, m)
229
230 case *GetStatusMsg:
231 a.handleGetStatus(ctx, m)

Callers

nothing calls this directly

Calls 12

handleStopMethod · 0.95
handleSendMethod · 0.95
handleChatMethod · 0.95
handleStreamMethod · 0.95
handleToolCallMethod · 0.95
handleDirectToolCallMethod · 0.95
handleBatchToolCallMethod · 0.95
handleGetStatusMethod · 0.95
StopSelfMethod · 0.80
DebugMethod · 0.65
IDMethod · 0.65
WarnMethod · 0.65

Tested by

no test coverage detected