Agent messages keep growing — how to keep context under control
Run an agent for a while and the messages array balloons: token cost explodes, it gets slow, and eventually it overflows the context window. Not a small issue — the #1 engineering problem in production agents. 6 fixes + runnable code.