A ready-to-run example is available here!The Stuck Detector automatically identifies when an agent enters unproductive patterns such as repeating the same actions, encountering repeated errors, or engaging in monologues. By analyzing the conversation history after the last user message, it detects five types of stuck patterns:
- 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
How It Works
In the ready-to-run 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
Ready-to-run Example
This example is available on GitHub: examples/01_standalone_sdk/20_stuck_detector.py
examples/01_standalone_sdk/20_stuck_detector.py
The model name should follow the LiteLLM convention:
provider/model_name (e.g., anthropic/claude-sonnet-4-5-20250929, openai/gpt-4o).
The LLM_API_KEY should be the API key for your chosen provider.Next Steps
- Conversation Pause and Resume - Manual execution control
- Hello World - Learn the basics of the SDK

