Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["9423"],{68522(e,s,n){n.r(s),n.d(s,{metadata:()=>t,default:()=>h,frontMatter:()=>a,contentTitle:()=>o,toc:()=>l,assets:()=>d});var t=JSON.parse('{"id":"reference/token-saver","title":"Token Saver Mode","description":"Token Saver Mode is a battery-saver-style optimization layer for LLM calls. When active, Mercury produces shorter, terser responses, runs fewer reasoning steps, and uses a smaller history window \u2014 saving tokens at the cost of some verbosity and exploration depth.","source":"@site/docs/reference/token-saver.mdx","sourceDirName":"reference","slug":"/reference/token-saver","permalink":"/docs/reference/token-saver","draft":false,"unlisted":false,"editUrl":"https://github.com/cosmicstack-labs/mercury-agent/tree/main/website/docs/reference/token-saver.mdx","tags":[],"version":"current","frontMatter":{"id":"token-saver","title":"Token Saver Mode"},"sidebar":"docsSidebar","previous":{"title":"Skills","permalink":"/docs/reference/skills"},"next":{"title":"Releases","permalink":"/docs/releases/"}}'),r=n(74848),i=n(28453);let a={id:"token-saver",title:"Token Saver Mode"},o,d={},l=[{value:"How It Works",id:"how-it-works",level:2},{value:"Three States",id:"three-states",level:2},{value:"Auto-Engagement",id:"auto-engagement",level:2},{value:"Slash Commands",id:"slash-commands",level:2},{value:"Status Display",id:"status-display",level:2},{value:"Tokens Saved \u2014 Estimation",id:"tokens-saved--estimation",level:2},{value:"Configuration",id:"configuration",level:2},{value:"Zero-Impact Guarantee When Off",id:"zero-impact-guarantee-when-off",level:2},{value:"When to Use It",id:"when-to-use-it",level:2}];function c(e){let s={blockquote:"blockquote",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.p,{children:"Token Saver Mode is a battery-saver-style optimization layer for LLM calls. When active, Mercury produces shorter, terser responses, runs fewer reasoning steps, and uses a smaller history window \u2014 saving tokens at the cost of some verbosity and exploration depth."}),"\n",(0,r.jsxs)(s.p,{children:["It is designed to ",(0,r.jsx)(s.strong,{children:"never affect behavior when disabled"}),". With saver ",(0,r.jsx)(s.code,{children:"off"}),", every LLM call uses exactly the same parameters as a Mercury install without saver support."]}),"\n",(0,r.jsx)(s.h2,{id:"how-it-works",children:"How It Works"}),"\n",(0,r.jsx)(s.p,{children:"When Token Saver Mode is active, Mercury changes four things about every LLM call:"}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Lever"}),(0,r.jsx)(s.th,{children:"Default (off)"}),(0,r.jsx)(s.th,{children:"Saver active"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"maxOutputTokens"})," per response"]}),(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"4096"})}),(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"1638"})," (\xd7 0.4)"]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:"Step budget per request"}),(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"25"})," steps"]}),(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"12"})," steps (\xf7 2)"]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:"Recent-history window injected as context"}),(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"10"})," messages"]}),(0,r.jsxs)(s.td,{children:[(0,r.jsx)(s.code,{children:"4"})," messages"]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:"System prompt suffix"}),(0,r.jsx)(s.td,{children:"(none)"}),(0,r.jsx)(s.td,{children:'"Be terse, no preamble, no restatement, \u2026"'})]})]})]}),"\n",(0,r.jsxs)(s.p,{children:["A fifth lever \u2014 ",(0,r.jsx)(s.strong,{children:"cheap-provider routing"})," \u2014 is available as an opt-in (",(0,r.jsx)(s.code,{children:"/saver routing on"}),"). When enabled while saver is active, Mercury reorders the provider fallback list to prefer cheaper providers first (e.g., DeepSeek and Ollama before Claude or GPT-4). It is off by default to avoid surprising provider switches mid-task."]}),"\n",(0,r.jsx)(s.p,{children:"These changes apply to both the main agent and any sub-agents the supervisor spawns."}),"\n",(0,r.jsx)(s.h2,{id:"three-states",children:"Three States"}),"\n",(0,r.jsx)(s.p,{children:"Saver mode has three states:"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:(0,r.jsx)(s.code,{children:"off"})})," \u2014 disabled. Mercury runs with original parameters. Zero-impact."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:(0,r.jsx)(s.code,{children:"on"})})," \u2014 manually enabled. Persists across restarts."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:(0,r.jsx)(s.code,{children:"auto"})})," \u2014 automatically engaged because daily usage crossed the threshold. Resets to ",(0,r.jsx)(s.code,{children:"off"})," automatically when usage drops well below the threshold (5-point hysteresis) or at the next daily-budget reset."]}),"\n"]}),"\n",(0,r.jsxs)(s.p,{children:["You can always force-disable auto with ",(0,r.jsx)(s.code,{children:"/saver off"})," (one-shot) or ",(0,r.jsx)(s.code,{children:"/saver auto off"})," (turns auto-engagement off permanently)."]}),"\n",(0,r.jsx)(s.h2,{id:"auto-engagement",children:"Auto-Engagement"}),"\n",(0,r.jsxs)(s.p,{children:["By default, saver auto-engages at ",(0,r.jsx)(s.strong,{children:"75%"})," of your daily token budget. When that happens, Mercury sends a one-time notice to the active channel so you know response style is about to change:"]}),"\n",(0,r.jsxs)(s.blockquote,{children:["\n",(0,r.jsxs)(s.p,{children:["\u26A1 Token Saver Mode auto-enabled (75% of daily budget reached). Responses may be shorter and step limits lower. Disable with ",(0,r.jsx)(s.code,{children:"/saver off"}),"."]}),"\n"]}),"\n",(0,r.jsx)(s.p,{children:"If usage drops below 70% (the threshold minus 5-point hysteresis), saver auto-disengages and sends a corresponding notification."}),"\n",(0,r.jsx)(s.p,{children:"You can change the threshold or disable auto-engagement entirely:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-text",children:"/saver threshold 80 # auto-engage at 80% instead of 75%\n/saver threshold 0 # disable auto-engagement (equivalent to /saver auto off)\n/saver auto off # disable auto-engagement (preserves threshold value)\n"})}),"\n",(0,r.jsx)(s.h2,{id:"slash-commands",children:"Slash Commands"}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Command"}),(0,r.jsx)(s.th,{children:"Description"})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"/saver"})}),(0,r.jsx)(s.td,{children:"Show saver status, today's savings, and lifetime savings"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"/saver on"})}),(0,r.jsx)(s.td,{children:"Manually enable saver (persisted)"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"/saver off"})}),(0,r.jsx)(s.td,{children:"Disable saver (also clears any auto-engagement state)"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"/saver toggle"})}),(0,r.jsx)(s.td,{children:"Flip saver on/off"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"/saver threshold <0-100>"})}),(0,r.jsx)(s.td,{children:"Set auto-engage threshold as a percentage of daily budget"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"/saver auto on|off"})}),(0,r.jsx)(s.td,{children:"Master switch for automatic engagement at threshold"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"/saver routing on|off"})}),(0,r.jsx)(s.td,{children:"Opt-in: prefer cheap providers while saver is active"})]})]})]}),"\n",(0,r.jsx)(s.p,{children:"All commands work on both CLI and Telegram."}),"\n",(0,r.jsx)(s.h2,{id:"status-display",children:"Status Display"}),"\n",(0,r.jsxs)(s.p,{children:["When saver is active, the CLI status bar shows a colored ",(0,r.jsx)(s.code,{children:"\u26A1SAVER"})," badge next to the agent name:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:"Green"})," ",(0,r.jsx)(s.code,{children:"\u26A1SAVER"})," \u2014 manually enabled (",(0,r.jsx)(s.code,{children:"/saver on"}),")"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:"Yellow"})," ",(0,r.jsx)(s.code,{children:"\u26A1SAVER (auto)"})," \u2014 auto-engaged at threshold"]}),"\n"]}),"\n",(0,r.jsxs)(s.p,{children:["The token usage bar gains a ",(0,r.jsx)(s.code,{children:"\xb7 saved ~N"})," suffix showing today's estimated savings. The ",(0,r.jsx)(s.code,{children:"/status"})," command also includes a saver line."]}),"\n",(0,r.jsx)(s.h2,{id:"tokens-saved--estimation",children:"Tokens Saved \u2014 Estimation"}),"\n",(0,r.jsx)(s.p,{children:"Mercury keeps two counters:"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:"Saved today"})," \u2014 estimated tokens saved since midnight (resets at daily-budget rollover)"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:"Saved lifetime"})," \u2014 cumulative estimate across all time, persisted to ",(0,r.jsx)(s.code,{children:"~/.mercury/mercury.yaml"})]}),"\n"]}),"\n",(0,r.jsx)(s.p,{children:"Estimation per request is rough but transparent:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{children:"saved = output_headroom + history_trim_estimate\n\noutput_headroom = min(MAX_RESPONSE_TOKENS - effective_cap,\n MAX_RESPONSE_TOKENS - actual_output_tokens)\nhistory_trim = (normal_window - saver_window) \xd7 120 tokens/message\n"})}),"\n",(0,r.jsxs)(s.p,{children:["Treat these numbers as guidance \u2014 they are not exact, since the actual savings depend on how short the model chooses to be. Mercury does not preflight-tokenize requests, because most supported providers (Anthropic, DeepSeek, Grok, Ollama, etc.) use different tokenizers than OpenAI's ",(0,r.jsx)(s.code,{children:"tiktoken"}),"."]}),"\n",(0,r.jsx)(s.h2,{id:"configuration",children:"Configuration"}),"\n",(0,r.jsxs)(s.p,{children:["Saver state is persisted in ",(0,r.jsx)(s.code,{children:"~/.mercury/mercury.yaml"})," under the ",(0,r.jsx)(s.code,{children:"tokens"})," section:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-yaml",children:"tokens:\n dailyBudget: 1000000\n saverMode: false # true when user runs /saver on\n saverAutoEnabled: true # master switch for auto-engagement\n saverAutoThreshold: 75 # percentage at which auto-engage triggers\n saverTokensSavedLifetime: 0 # lifetime savings counter\n cachedWeight: 1 # how much a prompt-cache hit counts toward dailyBudget (0\u20131)\n"})}),"\n",(0,r.jsxs)(s.p,{children:["Every model call in a turn counts toward ",(0,r.jsx)(s.code,{children:"dailyBudget"}),", including the tool steps and any extra rounds. Prompt-cache hits cost far less than fresh input at most providers. Set ",(0,r.jsx)(s.code,{children:"cachedWeight"})," to ",(0,r.jsx)(s.code,{children:"0.1"})," to count them at roughly their price instead of in full. ",(0,r.jsx)(s.code,{children:"/budget"})," shows today's split: cached, uncached and output tokens."]}),"\n",(0,r.jsx)(s.p,{children:"All fields are optional. Existing installs without saver fields work unchanged \u2014 defaults are applied silently on read, and no file is rewritten until you first toggle saver on or it auto-engages."}),"\n",(0,r.jsx)(s.h2,{id:"zero-impact-guarantee-when-off",children:"Zero-Impact Guarantee When Off"}),"\n",(0,r.jsxs)(s.p,{children:["When ",(0,r.jsx)(s.code,{children:"saverMode: false"})," (the default) and saver has never auto-engaged:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"maxOutputTokens"})," and ",(0,r.jsx)(s.code,{children:"stopWhen"})," use their original constants byte-for-byte"]}),"\n",(0,r.jsxs)(s.li,{children:["The recent-history window is ",(0,r.jsx)(s.code,{children:"10"})," exactly"]}),"\n",(0,r.jsxs)(s.li,{children:["The system prompt is identical to a pre-saver install, including the existing ",(0,r.jsx)(s.code,{children:">70%"}),' "Be concise" nudge']}),"\n",(0,r.jsxs)(s.li,{children:["The CLI status bar omits the ",(0,r.jsx)(s.code,{children:"\u26A1SAVER"})," badge entirely (no layout change)"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"mercury.yaml"})," and ",(0,r.jsx)(s.code,{children:"token-usage.json"})," are not rewritten"]}),"\n",(0,r.jsx)(s.li,{children:"The provider fallback order is untouched"}),"\n"]}),"\n",(0,r.jsxs)(s.p,{children:["The only observable difference from a pre-saver install is the addition of ",(0,r.jsx)(s.code,{children:"/saver"})," to the slash-command autocomplete list and the Telegram BotFather command menu."]}),"\n",(0,r.jsx)(s.h2,{id:"when-to-use-it",children:"When to Use It"}),"\n",(0,r.jsx)(s.p,{children:"Useful situations:"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:"You're close to your daily budget"})," \u2014 auto-engagement handles this automatically at 75%"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:"You're doing quick lookups or status checks"})," \u2014 manual ",(0,r.jsx)(s.code,{children:"/saver on"})," keeps responses tight"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:"You're running an unattended batch of agent tasks"})," \u2014 saver caps response size to avoid runaway output"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:"You're on a metered/limited plan"})," \u2014 combine ",(0,r.jsx)(s.code,{children:"/saver on"})," with ",(0,r.jsx)(s.code,{children:"/saver routing on"})," to prefer cheap providers"]}),"\n"]}),"\n",(0,r.jsx)(s.p,{children:"Less useful situations:"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:"Deep debugging or code exploration"})," \u2014 the smaller history window and shorter responses can hurt continuity"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:"Long-form writing"}),' \u2014 the "be terse" suffix actively fights against generating long content']}),"\n"]})]})}function h(e={}){let{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},28453(e,s,n){n.d(s,{R:()=>a,x:()=>o});var t=n(96540);let r={},i=t.createContext(r);function a(e){let s=t.useContext(i);return t.useMemo(function(){return"function"==typeof e?e(s):{...s,...e}},[s,e])}function o(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),t.createElement(i.Provider,{value:s},e.children)}}}]);