handleToolIntermediate 处理中间结果事件
(callID, toolName, label string, data any)
| 1524 | |
| 1525 | // handleToolIntermediate 处理中间结果事件 |
| 1526 | func (a *Agent) handleToolIntermediate(callID, toolName, label string, data any) { |
| 1527 | now := time.Now() |
| 1528 | snapshot := types.ToolCallSnapshot{ |
| 1529 | ID: callID, |
| 1530 | Name: toolName, |
| 1531 | State: types.ToolCallStateExecuting, |
| 1532 | Intermediate: make(map[string]any), |
| 1533 | UpdatedAt: now, |
| 1534 | } |
| 1535 | |
| 1536 | a.mu.Lock() |
| 1537 | if rec, ok := a.toolRecords[callID]; ok { |
| 1538 | if rec.Intermediate == nil { |
| 1539 | rec.Intermediate = make(map[string]any) |
| 1540 | } |
| 1541 | if label == "" { |
| 1542 | label = "data" |
| 1543 | } |
| 1544 | rec.Intermediate[label] = data |
| 1545 | rec.State = types.ToolCallStateExecuting |
| 1546 | rec.UpdatedAt = now |
| 1547 | snapshot.Arguments = rec.Input |
| 1548 | snapshot.StartedAt = rec.StartTime |
| 1549 | snapshot.UpdatedAt = rec.UpdatedAt |
| 1550 | snapshot.Intermediate = rec.Intermediate |
| 1551 | } else { |
| 1552 | if label == "" { |
| 1553 | label = "data" |
| 1554 | } |
| 1555 | snapshot.Intermediate[label] = data |
| 1556 | } |
| 1557 | a.mu.Unlock() |
| 1558 | |
| 1559 | a.eventBus.EmitProgress(&types.ProgressToolIntermediateEvent{ |
| 1560 | Call: snapshot, |
| 1561 | Label: label, |
| 1562 | Data: data, |
| 1563 | }) |
| 1564 | } |
| 1565 | |
| 1566 | // toolReporter 将工具回调转换为事件 |
| 1567 | type toolReporter struct { |
no test coverage detected