You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(x_integration): add count_recent_tweets method for tweet counts
Add a new cached method count_recent_tweets to fetch time-bucketed tweet counts matching a query over the last 7 days using the X v2 API. Also add corresponding LangChain tool and Pydantic schema.
"""Expose the X integration as LangChain tools for agent use."""
@@ -931,6 +1089,36 @@ class SearchRecentTweetsSchema(BaseModel):
931
1089
1, description="Maximum number of pages to fetch (None to exhaust)"
932
1090
)
933
1091
1092
+
classCountRecentTweetsSchema(BaseModel):
1093
+
query: str=Field(
1094
+
...,
1095
+
description="X v2 search query (1-4096 chars), e.g. '(drone OR drones OR UAS OR UAV) lang:en -is:retweet'",
1096
+
)
1097
+
start_time: Optional[str] =Field(
1098
+
None,
1099
+
description="Oldest UTC timestamp YYYY-MM-DDTHH:mm:ssZ (inclusive)",
1100
+
)
1101
+
end_time: Optional[str] =Field(
1102
+
None,
1103
+
description="Newest UTC timestamp YYYY-MM-DDTHH:mm:ssZ (exclusive)",
1104
+
)
1105
+
since_id: Optional[str] =Field(
1106
+
None, description="Only count tweets with an ID greater than this"
1107
+
)
1108
+
until_id: Optional[str] =Field(
1109
+
None, description="Only count tweets with an ID less than this"
1110
+
)
1111
+
granularity: str=Field(
1112
+
"hour", description="Bucket size: 'minute', 'hour' or 'day'"
1113
+
)
1114
+
search_count_fields: Optional[List[str]] =Field(
1115
+
None,
1116
+
description="Count bucket fields (subset of ['start', 'end', 'tweet_count'])",
1117
+
)
1118
+
max_pages: Optional[int] =Field(
1119
+
None, description="Maximum number of pages to fetch (None to exhaust)"
1120
+
)
1121
+
934
1122
return [
935
1123
StructuredTool(
936
1124
name="x_get_user_by_id",
@@ -1041,4 +1229,21 @@ class SearchRecentTweetsSchema(BaseModel):
1041
1229
),
1042
1230
args_schema=SearchRecentTweetsSchema,
1043
1231
),
1232
+
StructuredTool(
1233
+
name="x_count_recent_tweets",
1234
+
description="Count tweets posted in the last 7 days matching an X v2 query, bucketed by time — cheap way to size a query without retrieving tweet content.",
0 commit comments