handleToolCall 处理工具调用
(ctx *actor.Context, msg *ToolCallMsg)
| 345 | |
| 346 | // handleToolCall 处理工具调用 |
| 347 | func (a *AgentActor) handleToolCall(ctx *actor.Context, msg *ToolCallMsg) { |
| 348 | execCtx, cancel := a.withCancellation(msg.Ctx) |
| 349 | defer cancel() |
| 350 | |
| 351 | go func() { |
| 352 | result := a.agent.executeSingleTool(execCtx, msg.ToolUse) |
| 353 | |
| 354 | var response *ToolResultMsg |
| 355 | |
| 356 | if toolResult, ok := result.(*types.ToolResultBlock); ok { |
| 357 | response = &ToolResultMsg{ |
| 358 | CallID: msg.ToolUse.ID, |
| 359 | Result: toolResult.Content, |
| 360 | IsError: toolResult.IsError, |
| 361 | } |
| 362 | } else { |
| 363 | response = &ToolResultMsg{ |
| 364 | CallID: msg.ToolUse.ID, |
| 365 | Result: result, |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | if ctx.Sender != nil { |
| 370 | ctx.Reply(response) |
| 371 | } |
| 372 | }() |
| 373 | } |
| 374 | |
| 375 | // handleDirectToolCall 处理直接工具调用 |
| 376 | func (a *AgentActor) handleDirectToolCall(ctx *actor.Context, msg *DirectToolCallMsg) { |
no test coverage detected