eca icon indicating copy to clipboard operation
eca copied to clipboard

compaction prompt improvement ideas (including md analysis)

Open brdloush opened this issue 2 months ago • 4 comments

Motivation

Having started to use autonomous agentic flow in last couple of days, I have a feeling that eca is curently not exactly strong when it comes to context compaction.

I know that I can rewrite the prompt myself (am about to try that soon)  but perhaps the "out of the box experience" (usable for most people) can be improved.

What

I had some basic (AI-driven) research done about how different opensource harnesses approach this compaction problem, what's their interesting ideas as well as limitations.

Slack conversation for context: https://clojurians.slack.com/archives/C093426FPUG/p1789151504300249

How & why

I believe some ideas might be good adopt "in the default". I've read the whole document and a lot of things clicked for me which might be good ideas, such as

  • structure of the compaction output that must be filled (IMO this is very important to keep to keep at least some minimal quality of the compaction handout output)
  • concrete fidelity rules, nudging agent to mention specific things, not generic prose
  • distinguishing whether we are doing 1st compaction or Nth already (2nd and n-th compaction may be tailored more to avoid further degradation). I guess this might need some additional coding effort, so should be considered first. But the example mentioned in Merge Rules seems very usable (~ "be aware that there is already a heavily summarized content on the very beginning of this session, don't rely on it THAT MUCH, newer turns win over the summary, ..". So perhaps distinguishing between "first" and "nth" might be worth implementing.

I also believe that it might be beneficial to sacrifice a bunch of session-leading tokens (few tens of them) to better introduce what the purpose of the received compacted content really was:

;; current
"The conversation was compacted/summarized, consider this summary:\n"

;; suggested
(str "A previous agent worked on this task and ran out of context. "
     "Below is its handoff summary. Use it to avoid repeating work already done.\n\n"
     "Treat the working tree and command output as authoritative. The summary "
     "locates the relevant work; it is not proof that the work is correct or "
     "complete. Verify before you rely on it.\n\n"
     summary)

The actual analysis (ai comparison; some strong/weak/adopt ideas of other opensource harnesses)

Here's that mentioned full document for hammock-thinking on the compaction topic :-)

compaction-prompts-v2.md

brdloush avatar Sep 11 '26 19:09 brdloush

Btw with all those ideas in context, I asked my llm to derive me a "custom compaction prompt that we can already use today" (without any changes in ECA). And it managed to invent interesting prompting. Will try this prompt in upcoming days.

This one caught my eyes

First compaction, or a later one?

Look at the start of the conversation above. If it already contains an earlier handoff summary, this is a later compaction — apply the Merge rules below. If it does not, this is the first — skip them.

Basically it managed to fold quite a lot of ideas that "miss some proposed features" into prose-based instructions. Perhaps this might be useful strategy as well.

compact.md

brdloush avatar Sep 11 '26 20:09 brdloush

Quick update. After a week of mostly agent-autonomous work (which I only observe and steer occasionally), I am very satisfied with that compaction prompt I suggested in last comment. I've seen my agent both writing down reasonably well-written compaction summaries, as well as saw the agent successfully working on tasks which spawned multiple (3-5) 262k context compactions. I have a feeling that the more constrained and structured compaction prompt helped a lot.

brdloush avatar Sep 20 '26 14:09 brdloush

That makes a lot of sense to me, thanks for the time you spent on this, from what I saw, it looks like a real good improvement of compaction tool @zikajk I will go with that improvement, but feel free to do minor adjustments since you better than me on spotting those things. Usually less is better from my tests so we may want to reduce that compaction, but compared with right now, it looks better

ericdallo avatar Oct 05 '26 19:10 ericdallo

About the nth mention of the compaction, I do think we can track that and add a number to tell LLM about that, but only that, we can do that as a separated issue after this one is done

ericdallo avatar Oct 05 '26 19:10 ericdallo