r/opencodeCLI • • 18d ago

A subagent saves your context, not your tokens

A subagent reads the files, runs the search, and reports back one summary, so the main thread never sees the twenty files it looked at. That is the point: the win is that its context dies with it, not that the work is cheaper, and it usually costs more tokens than doing the same thing inline. If you paste the full transcript back into the main thread afterwards, you paid for the subagent and kept the cost anyway.

5 Upvotes

13 comments sorted by

14

u/xRebellion_ 18d ago

Subagents is mainly about parallelism and context management to begin with, not cost saving. Especially with the fact that the gap between cache read and input is widening.

2

u/funbike 17d ago edited 17d ago

It's about all of the above.

Even with really cheap caching, it still makes senses to use a mix of LLM models in multiple agents.

I mix it up with overlapping subagent responsibilities to leverage cache. A cheap "PO" agent drafts user specs and suggests a coding plan and files to inspect. An expensive "planner" uses those file recommendations to create the real plan. A cheap "coder" agent implement it, then reviews its own work; an expensive "reviewer" evaluates and improves that review.

In other words, I have the prior cheap agent do some follow-up work and pass that off to the next smarter agent so it has less overall work to do, usually less file searching and probing.

1

u/toadi 17d ago

Am tracking the cache hit of my subagents. While they are a little bit lower vs my orchestrator. Not too bad i think. But I can not say it is cheaper to run vs doing everything in the orchestrator. Think maybe that difference is negligent.

But why I do it is to keep context clean in orchestrator. Large context lose "attention" which is bad.

6

u/bokerkebo 18d ago

it's cheaper if you use cheaper models for the subagent. otherwise, just use the main agent and maybe one reviewer subagent

1

u/xmsxms 17d ago

The issue with this is that the main context gets filled with noise of the investigation that might have lots of wrong initial thought etc. All of that noise is now inserted into every turn the agent makes. Costs you in cache read tokens, context window limits and noise.

2

u/Piyh 17d ago

The agent writes your reddit posts, not your brain

1

u/sagiroth 18d ago

You not reinventing the wheel here friend. It's common sense by now to use strong model for plan/orchestration and offload to cheap models.

1

u/Early_Aardvark_4026 17d ago

I had to process tens of millions of JSON records. I tried two methods.

  1. One agent. The agent reached its context limit overnight. Context compaction made the results worse.
  2. An orchestrator with multiple subagents. This setup handled the workload well. It took longer and used more tokens.

I agree that subagents reduce the context each agent needs. In my case, total token use went up. Cost also depends on the model. If each task has a clear scope and needs little context, a faster model with a lower price per token can cost less overall, even if the run uses more tokens.

1

u/xapep 17d ago

Tens of millions of records is where the per-record model choice beats everything else in the bill. If each record needs one extraction pass, the orchestrator's job is throughput and failure isolation, so a cheap model with a strict schema wins over a better model with a loose prompt.

What usually costs more than tokens at that volume isn't the model, it's retries on malformed output. Pin the output to a schema, checkpoint by record id so a dead batch resumes instead of restarting, and log cost per 10k records. Then a model swap is a one-line change you can measure.

1

u/ward2k 17d ago

Depends, high context can cost you more tokens

I'm not someone that uses sub agents for literally everything but sometimes it's nice to help keep context free

You don't need your expensive model don't searches all over your codebase. You can pass that to a smaller model sub agent

A reviewer really benefits from a subagent with a clean context

Sometimes even a separate subagent for writing tests too. Main agents have a bit of a notorious habit of writing tests that pass no matter what and not just accepting that the code might be flawed

1

u/ConspicuousPineapple 18d ago

What do you think context is made of?

3

u/torrso 18d ago

Fairy dust

1

u/SureEnd9430 18d ago

Sugar, spice and everything nice.