fix(agent): harden truncation recovery and LLM config