A FastMCP-based engagement bot using Python and the X API v2’s search/recent endpoint was failing to reply to tweets effectively. The bot processed and replied to tweets based on configurable filters but encountered a critical limitation in its search functionality.
Issue
The engagement bot repeatedly reported “All 10 tweets filtered” and entered 85-minute sleep cycles, even though unreplied tweets were available on the platform. The search API returned only 10 tweets per cycle, and after applying standard filters—such as excluding the bot’s own tweets, previously replied content, and repeat authors—no actionable tweets remained. This resulted in only 4 replies over extended periods, making the system appear non-functional despite the availability of content.
Culprit
The primary issue was a hardcoded limit of max_results=10 in the search API call. Given the strict filtering applied, the 10-result limit was consistently exhausted before finding actionable content. The X API v2 search/recent endpoint supports up to 100 results per request, but the implementation artificially restricted the working dataset to just 10 tweets.
Solution
To resolve this, the system was updated to use a configurable search result limit via environment variables:
Configuration Changes
- Added a configurable limit in
config.pyto allow flexibility between 1 and 100 results:- Default value increased from 10 → 100 (10x more raw results).
- Validated to stay within X API limits (1–100).
API Call Update
- Modified the search call to use the configurable limit, ensuring backward compatibility with existing filter logic.
Key Benefits
- Expanded search scope: Now processes 100 tweets per cycle, significantly increasing the chances of finding unreplied content.
- Configurable flexibility: Operators can adjust the limit via environment variables without modifying code.
- Maintained quality controls: Existing filtering logic remains unchanged, ensuring only relevant tweets are processed.
- Efficient operation: The bot now only enters sleep cycles when no actionable content is genuinely available, rather than due to artificial result limitations.
Result: The bot now reliably processes sufficient tweets to identify unreplied content, improving engagement rates while preserving strict quality controls.