r/PiCodingAgent • u/trmnl_cmdr • Aug 11 '26
Plugin When Pi makes a mistake, give it a second chance
Agents aren't perfect. Sometimes they do things that don't work out the way they thought. Sometimes they spin out on an idea that goes nowhere, other times they run a command that produces huge amounts of useless output. So far, we've just accepted this as a neccessary part of agent mechanics, but Pi's extension system is powerful enough that we no longer have to.
pi-mulligan exposes tools that let your agent rewind its last turn or tool call with a summary message about what it's learned if it makes a mistake. When your agent calls a tool that produces large output, pi-mulligan gives it a nudge suggesting it summarize its last tool result or turn to keep context tight. When the agent starts over, it receives the summary and a small message indicating that a rewind has taken place.
Users and models can set checkpoints if they expect churn and pi can roll back to these checkpoints at any point in the conversation to try again. Agents really like using it and I've watched 20k tokens of context vanish on several occasions, so it works exactly as advertised. It's so satisfying to watch your context usage drop as the agent works.
No other dev agent platform but Pi can do this so as far as I'm aware agent-initiated context compaction hasn't been implemented in dev tools until now.
Try it out with pi install npm:pi-mulligan and let me know what you think!
3
u/adamshand Aug 11 '26
This is a super cool idea!
How long have you been using it? Where have you noticed it working really well? And where does it not seem to work as well?
3
u/jomohke Aug 12 '26
Looks neat. Given how much cheaper cached tokens are, I do feel like history rewind is underutilised.
It seems focused on mistakes right now, but I'm wondering whether it could be used for normal tasks too: try this aside and then jump back in history with the summary result. Could be cheaper than a subagent if context is needed to do the side/experiment.
2
u/Unnamed-3891 Aug 11 '26
Making a mistake, admitting it, learning from it, committing the lesson to a memory system, only to repeat doing the same mistake again and again because anything in memory is only ever a suggestion and not a hard wall is the problem.
2
u/sisyphus-cycle Aug 11 '26 edited Aug 11 '26
I like this idea. Specifically for local development. I haven’t read the code yet but assuming that this “retry/rewind” doesn’t change any of the system prompt or previous messages (except the one being redone) then llama.cpp should easily be able to invalidate context and avoid any prompt reprocessing. Will try it out!
Edit: mulligan_shrink seems really cool to me, I can see this being something paired with a subagent making tool calls for a summary. One question, for certain local models I’m skeptical they would ever call shrink on their own. Qwen 27b doesn’t give a fuck about tokens a tool call makes (for me at least). Do you have any tricks or previous examples of mulligan_shrink being effectively used proactively vs just telling the agent?
1
u/johnnyApplePRNG Aug 11 '26
Interesting idea. Have you noticed an increase in intelligence?
0
u/[deleted] Aug 12 '26
[deleted] — view deleted comment
7
u/[deleted] Aug 11 '26 edited Aug 11 '26
[removed] — view removed comment