This example is available on GitHub: examples/01_standalone_sdk/20_stuck_detector.py
- Repeating Action-Observation Cycles: The same action produces the same observation repeatedly (4+ times)
- Repeating Action-Error Cycles: The same action repeatedly results in errors (3+ times)
- Agent Monologue: The agent sends multiple consecutive messages without user input or meaningful progress (3+ messages)
- Alternating Patterns: Two different action-observation pairs alternate in a ping-pong pattern (6+ cycles)
- Context Window Errors: Repeated context window errors that indicate memory management issues
examples/01_standalone_sdk/20_stuck_detector.py
Running the Example
How It Works
In this example, the agent is deliberately given a task designed to trigger stuck detection - executing the samels command 5 times in a row. The stuck detector analyzes the event history and identifies the repetitive pattern:
- The conversation proceeds normally until the agent starts repeating actions
- After detecting the pattern (4 identical action-observation pairs), the stuck detector flags the conversation as stuck
- The conversation can then handle this gracefully, either by stopping execution or taking corrective action
stuck_detection=True), and you can check the stuck status at any point using conversation.stuck_detector.is_stuck().
Pattern Detection
The stuck detector compares events based on their semantic content rather than object identity. For example:- Actions are compared by their tool name, action content, and thought (ignoring IDs and metrics)
- Observations are compared by their observation content and tool name
- Errors are compared by their error messages
- Messages are compared by their content and source
Next Steps
- Conversation Pause and Resume - Manual execution control
- Hello World - Learn the basics of the SDK

