Skip to content

Add XSearchTool built-in tool for X/Twitter search via Grok provider #3896

Description

@colesmcintosh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature request, or PR implementing a feature (enhancement)toolsxai

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions