sweep_agent
Transfer funds from an agent's Lightning wallet back to the operator's balance using the agent ID and amount in satoshis.
Instructions
Sweep funds from agent back to operator balance. REQUIRES OPERATOR KEY.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agent_id | Yes | Agent ID to sweep funds from | |
| amount_sats | Yes | Amount in sats (use large number for full balance) |
Implementation Reference
- src/index.ts:1467-1485 (handler)The handler implementation for the "sweep_agent" tool, which calls the client's sweepAgent method.
case 'sweep_agent': { const parsed = SweepAgentSchema.parse(args); const amount = typeof parsed.amount_sats === 'string' ? 999999999 : parsed.amount_sats; const result = await session.requireClient().sweepAgent(parsed.agent_id, amount); return { content: [ { type: 'text', text: JSON.stringify({ success: true, message: `Swept ${result.amountTransferred} sats from agent`, amount_transferred: result.amountTransferred, new_operator_balance: result.newOperatorBalance, new_agent_balance: result.newAgentBalance, }, null, 2), }, ], }; } - src/lightning-faucet.ts:1046-1071 (handler)The underlying API client method that performs the sweep operation.
/** * Sweep funds from agent back to operator */ async sweepAgent(agentId: number, amountSats: number): Promise<{ amountTransferred: number; newOperatorBalance: number; newAgentBalance: number; rawResponse: ApiResponse; }> { const result = await this.request<ApiResponse & { amount_transferred?: number; new_operator_balance?: number; new_agent_balance?: number; }>('withdraw_from_agent', { agent_id: agentId, amount_sats: amountSats, sweep: true, }); return { amountTransferred: result.amount_transferred || amountSats, newOperatorBalance: result.new_operator_balance || 0, newAgentBalance: result.new_agent_balance || 0, rawResponse: result, }; } - src/index.ts:221-224 (schema)The input validation schema for the sweep_agent tool.
const SweepAgentSchema = z.object({ agent_id: z.number().int().positive().describe('Agent ID to sweep funds from'), amount_sats: z.union([z.number().int().positive(), z.literal('all')]).describe('Amount in sats or "all" for full balance'), });