agentbay_memory_compact
Run memory compaction to purge expired, stale, and duplicate entries. Use dry-run mode to preview changes before applying.
Instructions
Run memory compaction: TTL expiration, stale archival, duplicate merge. Supports dry-run mode.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | Project ID | |
| dryRun | No | Preview without making changes (default: false) | |
| staleDays | No | Days without verification to consider stale (default: 60) |
Implementation Reference
- src/index.ts:753-775 (handler)The handler function for the 'agentbay_memory_compact' tool. It accepts projectId, dryRun, and staleDays parameters, POSTs to /api/v1/projects/{projectId}/memory/compact, and returns compaction results including TTL expired, stale archived, duplicates merged, and tokens saved.
// Tool 24: Memory Compact server.tool( 'agentbay_memory_compact', 'Run memory compaction: TTL expiration, stale archival, duplicate merge. Supports dry-run mode.', { projectId: z.string().describe('Project ID'), dryRun: z.boolean().optional().describe('Preview without making changes (default: false)'), staleDays: z.number().optional().describe('Days without verification to consider stale (default: 60)'), }, async ({ projectId, dryRun, staleDays }) => { const data = await apiPost(`/api/v1/projects/${projectId}/memory/compact`, { dryRun, staleDays }); if (data.error) return { content: [{ type: 'text' as const, text: `Error: ${data.error}` }] }; const lines = [ data.dryRun ? 'Dry run — no changes made:' : 'Compaction complete:', `TTL expired: ${data.ttlExpired || 0}`, `Stale archived: ${data.archived || 0}`, `Duplicates merged: ${data.merged || 0}`, `Tokens saved: ${data.tokensSaved?.toLocaleString() || 0}`, ]; return { content: [{ type: 'text' as const, text: lines.join('\n') }] }; } ); - src/index.ts:753-762 (schema)The schema/input validation for agentbay_memory_compact, defined with zod: projectId (string), dryRun (optional boolean), staleDays (optional number).
// Tool 24: Memory Compact server.tool( 'agentbay_memory_compact', 'Run memory compaction: TTL expiration, stale archival, duplicate merge. Supports dry-run mode.', { projectId: z.string().describe('Project ID'), dryRun: z.boolean().optional().describe('Preview without making changes (default: false)'), staleDays: z.number().optional().describe('Days without verification to consider stale (default: 60)'), }, async ({ projectId, dryRun, staleDays }) => { - src/index.ts:753-755 (registration)Registration of the 'agentbay_memory_compact' tool via server.tool() call.
// Tool 24: Memory Compact server.tool( 'agentbay_memory_compact',