AgentActorChat 向 Agent Actor 发送对话请求并等待响应
(pid *actor.PID, text string, timeout time.Duration)
| 535 | |
| 536 | // AgentActorChat 向 Agent Actor 发送对话请求并等待响应 |
| 537 | func AgentActorChat(pid *actor.PID, text string, timeout time.Duration) (*ChatResultMsg, error) { |
| 538 | replyCh := make(chan *ChatResultMsg, 1) |
| 539 | |
| 540 | pid.Tell(&ChatMsg{ |
| 541 | Text: text, |
| 542 | Ctx: context.Background(), |
| 543 | ReplyTo: replyCh, |
| 544 | }) |
| 545 | |
| 546 | select { |
| 547 | case result := <-replyCh: |
| 548 | return result, nil |
| 549 | case <-time.After(timeout): |
| 550 | return nil, fmt.Errorf("chat request timed out after %v", timeout) |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | // AgentActorCallTool 向 Agent Actor 发送工具调用请求并等待响应 |
| 555 | func AgentActorCallTool(pid *actor.PID, toolName string, input map[string]any, timeout time.Duration) (*DirectToolResultMsg, error) { |