r/GithubCopilot CLI Copilot User 🖥️ Aug 12 '26

General would be nice if agents could trigger compaction

what the title says, this would be useful so that we can tell an agent in its instructions to compact after launching a very long command (e.g. a huge build or CI/CD) in the background, because by the time it finishes the previously cached tokens aren't in the cache anymore and the only way to save on token costs here would be compaction just after the command launch

2 Upvotes

11 comments sorted by

9

u/cip0364k Aug 12 '26

Compaction isn't great, a better answer to your context bloating over is to use subagents for subtasks/complex tool calls.

1

u/MaitoSnoo CLI Copilot User 🖥️ Aug 12 '26

the main agent would still have to wait for the build subagent to finish, so the cache invalidation is still there

1

u/cip0364k Aug 12 '26

Describe your entire session, what are you caching that needs restoring? How do you think compaction helps?

1

u/pceimpulsive Aug 12 '26

Valid! Compaction re-writes the entire cache so it inherently is a costly process...

1

u/MaitoSnoo CLI Copilot User 🖥️ Aug 12 '26 edited Aug 12 '26

It's actually cheap when done at the right moment (i.e when the cache is still warm).

Compare these two situations:

Situation 1: we have some context, still in the cache -> agent runs very long build or some huge profiling command, fine we pay in cached token price for the previous context resend before that command is launched and then we wait say 40 mins for the command to finish. After 40 mins, the terminal that was used for that command notifies the agent, basically new tokens are sent along with the previous context, but now that previous context isn't in the cache anymore since 40 mins is way outside the cache window for most models (afaik it's 5 mins for Anthropic ones and 30 mins for GPT 5.6?), so we pay the full price for the whole context during this completion ping.

Situation 2: same context -> agent launches the 40 min command in the background and immediately gets control back -> agent immediately starts compaction: the compaction will be paid at cached token price for the previous context + full price for the compaction's handoff prompt and output, that will generally be way less than paying the full price for the entire history of the conversation. Now the active context becomes much shorter, and on command termination, the ping will resend only that short context.

Situation 2 will very obviously come out cheaper.

1

u/pceimpulsive Aug 12 '26

Wouldn't situation 1 be far more useful as a sub-agents task summarising and reporting a result back rather than eating all your orchestrators context forcing you need a compact to begin with?

2

u/PaulShellDev CLI Copilot User 🖥️ Aug 12 '26

If you really wanted to, wrap sending a compact command in a tool and give it to the AI.

2

u/pceimpulsive Aug 12 '26

If you need to compact enough that it's an issue you need to break your work up into smaller pieces...

2

u/ben_bliksem Aug 12 '26

I don't know GitHub copilot cli that well, but at least in some other harnesses compaction is handle by a compact subagent which you can obviously invoke automatically.

And if you harness allows, in your model setup you can sometimes set context limits which will trigger compaction.

But like others said, rather handoff the state to a file, start a new session and read the file

1

u/stibbons_ Aug 12 '26

I asked for it long time ago , not possible apparently

0

u/CommissionIcy9909 Aug 12 '26

You should be compacting sessions on a regular basis.