Description
Add XSearchTool as a new built-in tool that enables Grok-powered agents to search X/Twitter posts, user profiles, and threads natively. This is a unique capability only available through X AI's Grok models.
Motivation
X AI's Grok models offer the only LLM provider with native access to real-time X/Twitter data. This enables use cases not possible with any other provider:
- Real-time social media search - Search posts, threads, and user content on X
- Date-range filtering - Query posts within specific time windows
- Handle-based filtering - Include or exclude specific X accounts
- Multimedia understanding - Analyze images and videos embedded in posts
Proposed code
from pydantic_ai import Agent, XSearchTool
agent = Agent(
'grok:grok-4-1-fast',
builtin_tools=[
XSearchTool(
allowed_x_handles=['pydantic'], # Max 10 handles
from_date='2025-01-01',
to_date='2025-06-01',
enable_image_understanding=True,
enable_video_understanding=True,
)
]
)
result = agent.run_sync('What are the latest Pydantic AI updates on X?')
print(result.output)
Provider Support
Only XAI/Grok
References
Description
Add
XSearchToolas a new built-in tool that enables Grok-powered agents to search X/Twitter posts, user profiles, and threads natively. This is a unique capability only available through X AI's Grok models.Motivation
X AI's Grok models offer the only LLM provider with native access to real-time X/Twitter data. This enables use cases not possible with any other provider:
Proposed code
Provider Support
Only XAI/Grok
References