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

Method handleChat

pkg/agent/actor.go:282–312  ·  view source on GitHub ↗

handleChat 处理同步对话

(ctx *actor.Context, msg *ChatMsg)

Source from the content-addressed store, hash-verified

280
281// handleChat 处理同步对话
282func (a *AgentActor) handleChat(ctx *actor.Context, msg *ChatMsg) {
283 execCtx, cancel := a.withCancellation(msg.Ctx)
284 defer cancel()
285
286 go func() {
287 result, err := a.agent.Chat(execCtx, msg.Text)
288
289 response := &ChatResultMsg{
290 Result: result,
291 Error: err,
292 }
293
294 if err != nil && !errors.Is(err, context.Canceled) {
295 a.recordError(err)
296 }
297
298 // 通过 channel 返回结果
299 if msg.ReplyTo != nil {
300 select {
301 case msg.ReplyTo <- response:
302 default:
303 agentLog.Warn(context.Background(), "chat reply channel full or closed", map[string]any{"agent_id": a.agent.ID()})
304 }
305 }
306
307 // 也通过 Actor 消息回复
308 if ctx.Sender != nil {
309 ctx.Reply(response)
310 }
311 }()
312}
313
314// handleStream 处理流式对话
315func (a *AgentActor) handleStream(_ *actor.Context, msg *StreamMsg) {

Callers 1

ReceiveMethod · 0.95

Calls 7

withCancellationMethod · 0.95
recordErrorMethod · 0.95
cancelFunction · 0.85
ReplyMethod · 0.80
WarnMethod · 0.65
IDMethod · 0.65
ChatMethod · 0.45

Tested by

no test coverage detected