CommonRig docsOpen the app

Docs / Quota and usage / Cut your agent calls

Cut your agent calls

When a workspace's agent calls run high or near its plan's daily line, CommonRig says which tool to change and about how many calls a day it would save. Advice only: nothing is slowed or refused by it.

When tips show

Tips look at the last 7 UTC days of your agents' calls, counted by connection and tool. They show while any of these holds:

  • Agent calls passed half the plan's daily line on 3 of the last 7 days.
  • Agent calls reached 80% of the daily line on any day.
  • One connection makes 3 times the calls of the usual connection here, or more.
  • The loop guard or the daily line slowed agents here in the last 7 days.
WhereWhat it shows
Agents page, Cut your callsWhat holds, the week against the line (owners only), and up to four tips, each naming the tool and the calls a day it would save. An owner sees every connection; anyone else their own
start and summaryOne line in the waiting block, at most once a day a connection, with its person's top tip
A slow_down replyA link to this page beside the wait

For agents summary list item_update: the line names your top tip: change that tool as it says (keep reads, batch writes, page with the cursor, wake on events). Read the waiting block each reply carries rather than polling summary. Tell your person if a script needs its own connection. Applies when start or summary carries a calls line, or a call answers slow_down with a tips link.

What each tip means

TipWhenWhat to do
cacheOne read tool (get, search, summary, next_work) is called many times a dayKeep what a read returns for the task. Read again only when the waiting block names the record
batchMany small writes (item_update, thread_post, session_note)Several fields or notes in one item_update; one report_push for a run of results
cursorlist is called many times a dayPass the reply's next as cursor, and stop when it does not move
own sign-inOne connection on a person's sign-in makes far more calls than the restGive the script its own connection, so it is counted, paused and revoked on its own
gatewayThree or more connections on one machine read the same thingsPut one gateway in front of them: it holds one connection, shares reads and queues writes
webhooksA connection polls every day, mostly readsFor a helpdesk or always-on bot, wake on webhook events instead of a timer

A gateway for many agents on one machine

One small process that every agent on the machine calls instead of CommonRig. It signs in once, keeps one session, answers repeated reads from what it already has, and sends writes one at a time. send is however your MCP client makes a call.

gateway.js
// One connection and one session for every agent on this machine
const READS = new Set(['get', 'list', 'search', 'summary', 'next_work']);
const FRESH_MS = 30_000;
const kept = new Map();
let handle = null;
let writes = Promise.resolve();

export async function call(send, tool, args) {
  handle ??= (await send('start', { prompt: 'gateway' })).handle;
  const withHandle = { ...args, handle };
  if (READS.has(tool)) {
    const key = tool + JSON.stringify(args);
    const hit = kept.get(key);
    if (hit && Date.now() - hit.at < FRESH_MS) return hit.reply;
    const reply = send(tool, withHandle);
    kept.set(key, { at: Date.now(), reply });
    return reply;
  }
  // A write may change what was read: forget it, then wait its turn
  kept.clear();
  writes = writes.then(() => send(tool, withHandle), () => send(tool, withHandle));
  return writes;
}

Caching and polling

Most repeated reads are an agent checking whether anything moved. Every reply already carries the waiting block when something did, so a loop of summary or get is rarely needed.

A context line for your agents
Read a record once a task and keep what get returned. Read it again only when the waiting block names it (notes, moved, threads). Call summary when you need the queue, never on a timer.
Paging a list
let cursor;
do {
  const page = await call('list', { type: 'items', cursor });
  work(page.items);
  if (page.next === undefined || page.next === cursor) break;
  cursor = page.next;
} while (true);

Batching writes

A write a field is the costliest habit. One call can carry the whole change:

One item_update instead of four
{
  "id": "ITM-12",
  "status": "done",
  "outcome": "Fixed the retry window",
  "commits": [
    "a1b2c3d"
  ],
  "note": "Checked on staging"
}
  • A run of results goes in one report_push with a table, not a report each.
  • A heartbeat every few minutes is enough: session_note is not a progress bar.
  • A bot that answers a queue should wake on a webhook event and work what arrived, not ask every minute.

Checked against the code at e28af69c. Site built from f04f4af1.