10 November 2026 · 6 min read

Code mode: fewer steps, smaller bills, better answers

Memtro's agent can now do the legwork of an investigation in a short script instead of a long chain of tool calls. Here is what that changes for the answers you get, how quickly you get them, and what they cost.

Ask an AI agent "who owns the accounts with an overdue invoice over £5,000?" and watch what it does. It lists the overdue invoices. It reads every one of them. It picks out the large ones. Then it looks up the first customer in the CRM, reads the result, looks up the second, reads that, and carries on, one customer at a time, until it can answer.

Nothing in that question is hard. It is just long. Twelve customers is thirteen tool calls, and each of those is a full round trip through the model, which re-reads everything gathered so far before it decides what to do next. By the end it has re-read the whole invoice list a dozen times to produce an answer six lines long.

Code mode changes how that legwork gets done. Instead of making the calls one at a time, the agent writes a short script that makes them all, does the filtering and matching itself, and hands back only the answer. It is live in Memtro's agent mode now, it switches itself on, and there is nothing to set up.

What actually happens

For the question above, the agent writes something like this:

async () => {
  const { invoices } = await tools.xero_invoices({ type: "ACCREC", overdue_only: true });
  const large = invoices.filter((i) => i.amount_due > 5000);
  const owners = await Promise.all(
    large.map((i) => tools.hubspot_search({ object: "companies", query: i.contact, limit: 1 })),
  );
  return large.map((i, n) => ({
    invoice: i.number,
    customer: i.contact,
    due: i.amount_due,
    owner: owners[n].results[0]?.hubspot_owner_id,
  }));
}

Memtro runs it, the script makes the calls, and the agent gets back a short table: invoice, customer, amount, owner. The forty invoices and twelve CRM records it read along the way never enter the conversation. Then it writes the answer.

Two steps instead of fourteen. Everything good about code mode follows from that.

Faster answers

Each step of an agent loop is a model turn, and a model turn takes seconds. Fourteen of them back to back is the difference between an answer that arrives while you are still looking at the screen and one you come back for.

A script collapses the lookups into one step, and runs them side by side rather than in a queue: up to six calls at once, so twelve CRM lookups take about as long as two. What remains is the time the systems themselves take to respond, which was always the floor.

Smaller bills

Most of what you pay for in an agent run is not the answer. It is the model re-reading. Every step re-reads the instructions, the tool definitions and every result so far, so a long chain of lookups pays for the early results again and again.

A rough picture of the invoice question, with illustrative numbers:

One call at a timeCode mode
Model steps142
Invoice list re-read13 timesNever: it stays in the script
CRM results re-readEach one, on every later stepNever
Input tokens, roughly~280,000~25,000

Those figures assume a 10,000-token starting context, an invoice list of about 6,000 tokens and 800 tokens per CRM record. Your numbers will differ. The shape will not: the saving grows with the square of the number of lookups, because every extra step re-reads every earlier one. Ten lookups is a nice saving. Fifty is the difference between a question that is worth asking and one that is not.

There is a second saving on top. A company with twenty-odd connected systems has around 150 tools, and the model normally has to read their full definitions before it does anything. For scripts, Memtro gives it just the tool names, under a thousand tokens, and the model asks for the details of the one or two it actually needs.

Better answers

This is the benefit that is easiest to overlook, and arguably the most important.

Exact filtering instead of eyeballing. Ask a model to read forty invoices and pick out the ones over £5,000 and it will usually get it right. "Usually" is the problem. Models skim, miscount and lose rows halfway down a long list. A script's amount_due > 5000 does not. Counting, totalling, sorting, matching a customer in one system to the same customer in another: these are things code does exactly, and now they are done by code.

A clear head for the reasoning. A model working through a conversation stuffed with forty invoices and a dozen CRM records is reasoning around a great deal of noise. With code mode it reasons over the six lines that matter. Less to wade through means less chance of fixing on the wrong detail.

Room for the bigger question. Agent mode works within a step budget, thirty by default. When every lookup is a step, a question that needs fifty lookups runs out of budget before it finishes. When the lookups happen inside a script, the budget goes on thinking: following a lead, checking a second source, deciding what the evidence means. Questions like "which of our top fifty customers has nobody spoken to since August?" stop being too big to ask.

Safe by design

A script can only read. It can list, search, fetch, filter and combine, and nothing else. It cannot send an email, update a record, post a message or save anything to memory.

That does not mean Memtro's agent cannot act. It still can, when somebody asks for it and an administrator has granted that action. It just does so as a separate, visible step, under the same checks as before, and never from inside a script. The script works out what is true. Deciding to change something stays in the open, where you can see it.

The rest of the safety model is unchanged too:

  • Every call inside a script is checked exactly as if the agent had made it directly: the same team permissions, the same connections, the same protections against prompt injection. A script can never reach more than the conversation could.
  • The script runs in a sealed sandbox, a JavaScript engine with no access to files, the network or the machine it runs on. All it can touch is the read tools it was given.
  • You can see what it did. The activity trail lists every call the script made, whether it worked and how long it took.

Nothing to switch on

Code mode is offered automatically in agent mode (the default on the Chat page, and available from the API) whenever a conversation has at least eight read tools from connected systems. Below that there is too little to join for a script to be worth writing. The agent decides when a script is the right shape for the job, and makes ordinary calls when it is not.

What we will measure

Code mode shipped this week. The benefits above follow from how agent loops work: fewer steps, less re-reading, exact arithmetic. How much they add up to on real questions is something we are now measuring on live traffic and on our benchmarks. We will publish those numbers when we have them, whatever they say.

The details, including the limits and exactly what a script can and cannot call, are in the code mode documentation.

Where agents remember your company

Sign in, add a provider key, create an API key and point your tools at Memtro. It takes about five minutes.

7-day free trial · card on file, nothing charged until it ends · cancel any time