21 / 108 · 03 Agentic Testing Architectures · Practical ReAct Implementation← prev⊞ allnext →☰ Read as one page
3.4History Management Strategies
The history buffer directly affects agent performance. Too little history causes loops; too much wastes tokens.
Strategy 1: Fixed Window
# Keep the last N steps
self.history = self.history[-5:]
Simple and predictable. Works well for tests under 15 steps.
Strategy 2: Summarized History
def summarize_history(self) -> str:
"""Compress history into a summary to save tokens."""
if len(self.history) <= 3:
return json.dumps(self.history)
# Keep first step, summary of middle, and last 2 steps
summary = f"Started at {self.history[0]['state_url']}. "
summary += f"Took {len(self.history) - 3} intermediate steps. "
if any(h.get('result') == 'error' for h in self.history[1:-2]):
summary += "Encountered errors along the way. "
summary += f"Recent actions: {json.dumps(self.history[-2:])}"
return summary
Saves tokens while preserving context for long-running agents.
Strategy 3: Milestone-Based History
def milestone_history(self) -> list[dict]:
"""Keep only steps that represent significant state changes."""
milestones = []
last_url = None
for step in self.history:
# URL changed = navigation milestone
if step.get("state_url") != last_url:
milestones.append(step)
last_url = step.get("state_url")
# Error occurred = error milestone
elif step.get("result") == "error":
milestones.append(step)
# Assertion made = assertion milestone
elif "ASSERT" in step.get("action", ""):
milestones.append(step)
return milestones[-5:] # Keep last 5 milestones
Best for long multi-page workflows where only navigation and assertions matter.