| 1659 | // This tests a scenario where we execute two separate batch tool calls |
| 1660 | // The second batch should not re-add the tool messages from the first batch |
| 1661 | class TwoBatchAgent implements Agent { |
| 1662 | private batchCount = 0; |
| 1663 | |
| 1664 | tools = { |
| 1665 | tool_a: vi.fn().mockResolvedValue({ result: 'a' }), |
| 1666 | tool_b: vi.fn().mockResolvedValue({ result: 'b' }), |
| 1667 | }; |
| 1668 | |
| 1669 | async runner(context: AgentRuntimeContext, _state: AgentState) { |
| 1670 | if (context.phase === 'user_input' || context.phase === 'tools_batch_result') { |
| 1671 | this.batchCount++; |
| 1672 | if (this.batchCount === 1) { |
| 1673 | // First batch |
| 1674 | return { |
| 1675 | type: 'call_tools_batch' as const, |
| 1676 | payload: { |
| 1677 | parentMessageId: 'msg', |
| 1678 | toolsCalling: [ |
| 1679 | { |
| 1680 | id: 'batch1_call_a', |
| 1681 | type: 'default' as const, |
| 1682 | apiName: 'tool_a', |
| 1683 | identifier: 'tool_a', |
| 1684 | arguments: '{}', |
| 1685 | }, |
| 1686 | ], |
| 1687 | }, |
| 1688 | }; |
| 1689 | } else if (this.batchCount === 2) { |
| 1690 | // Second batch - should not duplicate first batch's tool messages |
| 1691 | return { |
| 1692 | type: 'call_tools_batch' as const, |
| 1693 | payload: { |
| 1694 | parentMessageId: 'msg', |
| 1695 | toolsCalling: [ |
| 1696 | { |
| 1697 | id: 'batch2_call_a', |
| 1698 | type: 'default' as const, |
| 1699 | apiName: 'tool_a', |
| 1700 | identifier: 'tool_a', |
| 1701 | arguments: '{}', |
| 1702 | }, |
| 1703 | { |
| 1704 | id: 'batch2_call_b', |
| 1705 | type: 'default' as const, |
| 1706 | apiName: 'tool_b', |
| 1707 | identifier: 'tool_b', |
| 1708 | arguments: '{}', |
| 1709 | }, |
| 1710 | ], |
| 1711 | }, |
| 1712 | }; |
| 1713 | } |
| 1714 | } |
| 1715 | return { type: 'finish' as const, reason: 'completed' as const }; |
| 1716 | } |
| 1717 | } |
| 1718 |
nothing calls this directly
no outgoing calls
no test coverage detected