{"uid":"cap_TAEAw87HZe5vVX_bkpGVF","slug":"halowerk-memory-compact-554ffd24","name":"Halowerk Memory Compact","description":"Takes a message history and a character budget and returns a shortened history together with a full account of what it cost. Four stages run in fixed order: pin protects messages that must survive (roles listed in keep_roles, the last keep_last_n messages, and anything you marked pin), dedupe removes later near-duplicates of an earlier message of the same role using word-overlap similarity, trim shortens unprotected survivors to max_message_chars at the last sentence boundary, and drop removes…","url":"https://agent.halowerk.com/v1/memory-compact?utm_source=zero.xyz","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"messages":{"type":"array","items":{"type":"object","required":["role","content"],"properties":{"id":{"type":"string","maxLength":128,"description":"Optional caller-side identifier, echoed unchanged."},"pin":{"type":"boolean","default":false,"description":"If true this message is protected: never trimmed, never dropped."},"role":{"enum":["system","user","assistant","tool"],"type":"string","description":"Speaker role."},"content":{"type":"string","maxLength":8000,"minLength":1,"description":"Message text."}},"additionalProperties":false},"maxItems":200,"minItems":2,"description":"The conversation in order, oldest first."},"keep_roles":{"type":"array","items":{"enum":["system","user","assistant","tool"],"type":"string"},"default":["system"],"maxItems":4,"description":"Roles whose messages are protected."},"keep_last_n":{"type":"integer","default":5,"maximum":50,"minimum":0,"description":"How many of the most recent messages are protected."},"budget_chars":{"type":"integer","maximum":400000,"minimum":100,"description":"Character budget for the sum of all returned message contents."},"max_message_chars":{"type":"integer","default":400,"maximum":4000,"minimum":80,"description":"Length to which unprotected survivors are trimmed in the trim stage."},"duplicate_threshold":{"type":"number","default":0.9,"maximum":1,"minimum":0.5,"description":"Word-overlap ratio from which a later message of the same role counts as a near-duplicate of an earlier one."}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.005","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.005/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.005","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.005","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_ztWC_uh2puC6tLksZdIZe","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.005","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Compresses a conversation history to fit within a character budget by pinning, deduplicating, trimming, and dropping messages in fixed stages.","exampleAgentPrompt":"Compact this conversation history to fit within a 12000 character budget — keep all system messages and the last 5 turns protected, trim unprotected messages to 400 characters each, and flag anything with over 90% word-overlap similarity as a duplicate so it gets dropped.","exampleUseCases":[{"title":"Fitting long chat into LLM context","prompt":"I have a 200-message conversation that's too long to send to the model — can you compact it to fit within 8000 characters, keeping the system message and the last 5 messages safe from removal, and trimming everything else to 300 characters max?"},{"title":"Removing repetitive user messages","prompt":"This support chat has a lot of near-duplicate user messages — compact the history to a 20000 character budget and set the duplicate threshold to 0.85 so repetitive messages from the same role get dropped automatically."},{"title":"Protecting pinned instructions mid-conversation","prompt":"Compact this agent's memory down to 15000 characters, but make sure any message I've marked as pinned survives no matter what, keep all system and tool messages, and preserve the last 3 exchanges."}],"resultDescription":"Returns the compacted message array with the same structure as the input (including echoed ids and pin flags), plus a detailed cost object showing total characters used, how many messages were pinned, deduped, trimmed, and dropped, and the character savings from each stage.","failureModes":["Budget too small to fit even protected messages — returns error indicating budget_chars is insufficient","Input messages array has fewer than 2 items — validation error","A single message content exceeds 8000 characters — validation error","max_message_chars set below 80 or above 4000 — schema validation error","duplicate_threshold outside 0.5–1.0 range — validation error","All messages are protected and already exceed budget — no reduction possible, error or full pass-through"],"whenToPreferThis":"Choose this endpoint when you need deterministic, rule-based conversation history compression with explicit control over which messages survive (by role, recency, or pin flag), rather than summarization-based approaches that use an LLM and introduce non-determinism. Ideal for agent frameworks that must stay within a character or token budget while guaranteeing certain messages (e.g. system prompts, tool outputs) are never lost. Preferable over manual truncation because it runs four structured stages with cost accounting, making the compression auditable.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-11T00:33:15.928Z","isFirstParty":false,"canonicalSlug":"halowerk-memory-compact-554ffd24"}