Stop Hook
Define an explicit programmatic predicate that decides when the agent's loop should terminate.
Intent & Description
🎯 Intent
Define an explicit programmatic predicate that decides when the agent’s loop should terminate.
📋 Context
A team is operating an agent loop where the agent repeatedly thinks, acts, observes, and decides whether to keep going. The loop needs an explicit stop condition that does not rely on the model itself declaring ‘done’, because in practice the model’s own sense of completion is unreliable — it either stops too early on hard tasks or refuses to stop on easy ones.
💡 Solution
Implement a stop hook function that runs after each step. It returns one of: continue, stop-success, stop-failure. Conditions include: target reached, step budget hit, error encountered, stagnation detected (no progress in last N steps).
Real-world Use Case
- Agent loops need an explicit termination predicate beyond model self-declaration.
- Conditions like budget hit, error, or stagnation can be detected programmatically.
- Costs of an unbounded loop are unacceptable.
Source
Advantages
- Explicit, testable termination logic.
- Independent from the model’s self-assessment.
Disadvantages
- More code to maintain than ‘while not done’.
- Predicate bugs cause hangs or premature stops.